How to add powershell script as custom action in visual studio setup project - visual-studio-setup-proje

I have written one powershell(IPConfiguration.ps1) script to change the static IP address , subnet address and for disabling the IPV6 option in the ethernet network Interface. PowerShell script working well without any issue. When launching in my machine on PowerShell command prompt.
Now I am creating setup file using visual studio 2022 setup project. and wanted to launch this IPConfiguration.ps1 PowerShell script after installation, so all IP address and others option get set automatically. I believe this can be done by providing the custom action but I am not aware how to use powershell script as custom action in visual studio setup project. Because Visual studio only allow to create custom action for exe,dll,js etc not for powershell script files. so can any one please guide me , how can I use IPConfiguration.ps1 script as custom action in Visual studio 2022 setup project?
Many thanks in advance for any lead or solution.
I tried below solutions.
Execute an script/application after installing (using VS Setup Project)
https://stackoverflow.com/questions/2414956/how-to-run-a-bat-file-during-installation#:~:text=Here%27s%20what%20you%20do%3A%201%20Create%20a%20setup,want%20to%20execute%20and%20cmd.exe%20%28C%3A%5CWindows%5CSystem32%5Ccmd.exe%29%20More%20items
Tried above solution by replacing powershell.ps1 script in-place of batch script and replacing cmd.exe with powershell.exe along with proper parameter.

Related

Can Visual Studio (NOT VS Code) do remote ssh development? The docs says yes, but

This seems like it ought to be solved with a google search, but I've been looking really hard for the past hour and can't find it. There are many links saying Visual Studio (not VS Code) supports remote ssh development (for instance https://learn.microsoft.com/en-us/cpp/linux/connect-to-your-remote-linux-computer?view=vs-2019 ) but none actually show the final step. Can Visual Studio remote develop on linux without installing the code locally?
On VS Code, the feature to remote develop over SSH lets you specify the remote address and then you don't even need the code locally cause all editing and debugging is remote. Does Visual Studio have that feature too? The above link shows how to setup a connection to a machine, but then I can't find any way to actually connect to that machine to browse for the project. How does remote development work in Visual Studio? It seems like I can copy the code locally on my windows box and it will copy the code and build it on linux? But is there not an option like VS Code has where the code lives remotely on the linux box and VS just uses ssh to read it?
The only way I have found is with remote debugging. First you have to copy the binaries to the Linux machine. Then you can debug the program with remote debugging. But actually a bit cumbersome in contrast to VS Code remote.
Here a link from the Microsoft documentation with detailed instructions:
https://learn.microsoft.com/en-us/visualstudio/debugger/remote-debugging-dotnet-core-linux-with-ssh?view=vs-2019
Hopefully there will be a better solution in the future.I don't like VS Code either.
I have a VS-Code on Windows and a Cent-Os (linux) like you, and with extensions installed and set up here and thereā€¦ things work out.
But since my company is paying us the Visual Studio 2019_pro edition, I have been trying to make things work. And also, we have our uses and customs with Visual Studio 2019.
So, as previously said on the question:
Can Visual Studio remote develop on linux without installing the code locally?"
No ! I agree, it does not work as in VSCode.
But to help others that might come around this question, and IF it is possible for them to clone their repos on Windows, then, I have manage to write my code on Visual Studio 2019, launch the compile (here it does rsync to the linux and launch g++), and then debug.
In order to do that, we have to create a new 'Configuration'. This is the things that I think is not properly documented for now. Because, when starting Visual Studio, it creates a default configuration "x64-Debug".
When adding a 'Linux-Debug' configuration (default one proposed by VisualStudio 2019), once setup using the 'connection to a machine', as it has already been stated, in the "Remote machine name" field, then save, and in my case (a CMake file type project), the rsync process is started by VisualStudio and the first 'Configuration' stage of CMake is performed.
Then each time I compile or run, VisualStudio2019 'rsync' the files that I have locally changed from the windows to the linux and compiles/runs.
HTH
You can use SSHFS to mount remote filesystems over SSH, and then open the relevant folder using Visual Studio.

How to write and debug a PowerShell module using VIsual Studio Powershell Tools?

I'd like to take advantage of Visual Studio's debugging capabilities when writing PowerShell scripts, especially PowerShell modules. Thus, I have installed the PowerShell tools for Visual Studio. I created a new PowerShell module project - but I can't figure out how to properly run and debug?
When running such a project I'd expect that the module is loaded and all functions are available in the debug window - and that any code execution would stop at break points.
However, I can't manage to run a module that way. In Solution Properties => Advanced => Entry point I can only select ps1 files. I've RTFM at https://docs.poshtools.com/ but didn't find anything about modules. Just to avoid any confusion, I am not developing anything with C# or VB in this project, just pure PS. I have been developing PS before using Visual Studio Code, but as I am more comfortable with Visual Studio 2019 I might be able to use it for PS development as well.
Any suggestions?

are visual studio macros available in the Command Tool window?

Macros for Build Commands and Properties like $(SolutionDir) and $(ProjectDir) are available as Arguments for External Tools.
Are the same macros available to the Shell Command of the Command Tool Window?
Right now I can resort to using an environment variable, and if I forget to set it before Visual Studio starts, I can remotely inject it. Dynamically Add/Edit Environment Variables of Remote Process
Tools.Shell /c tfpt.exe review %SOLUTIONDIR%
Is there a syntax for the Command Tool Window that will allow me to access the Build Macros?!
Did this syntax somehow escape the design considerations of the Visual Studio team?
Tools.Shell /c tfpt.exe review $(SolutionDir)
Please send any syntax that is known to work, including version of Visual Studio.
If there's already a ticket open on Microsoft Connect for this, I'd accept that as an answer too.
Please no answers that suggest the many optional plugins for Visual Studio that host Powershell, Python or others.
We took a look at the code and it doesn't seem that those macros are available today. I'll file a feature request.

can i use a console application that execute powershell script as a custom action

In my solution, I have a windows service and WPF application to mange this service
and a console application that executes Powershell script files and also, an installer project.
In my installer project, I want to add a custom action (the console app) that execute the Powershell functions.
When I try to install, I get an error.
My Question is: can I use a console application that executes powershell script as a custom action?
I'm using visual studio 2010.
Thanks.
You are aware that PowerShell is not installed by default on Windows XP and Windows Vista? If that is OK, the next hurdle is the default execution policy does not allow script execution. You can get around that by using the powershell.exe parameter -ExecutionPolicy Unrestricted. However that parameter is not available in PowerShell 1.0 IIRC.
Personally, I'd be a bit wary about relying on PowerShell for a custom action but if you know the environment this is installing into (corp/IT app) then go for it. :-)

Why does ExecutionPolicy behavior vary across projects in Visual Studio?

I have been using NuGet for quite some time on a particular PC. Now, I created a new project in VS2010 (it's an MVC 4 Beta project using the Single Page App template if that matters). When I select
Tools / Library Package Manager / Package Manager Console
The console window opens but displays the error:
File C:\Program Files (x86)\Microsoft Visual Studio
10.0\Common7\IDE\Extensions\Microsoft Corporation\NuGet Package Manager\1.7.30402.9028\Modules\NuGet\profile.ps1 cannot be loaded
because the execution of scripts is disabled on this system. Please
see "get-help about_signing" for more details.
However, other projects can still open and use Package Manager Console.
In each case, VS2010 is running as the same user.
If I open a command prompt (using the same account under which VS2010 is running), start PowerShell, and enter the command
Get-ExecutionPolicy
PowerShell returns
Restricted
My understanding based on a Scott Hanselman blog is that scripts should not run at all if the ExecutionPolicy is restricted.
Why are existing projects able to use the Package Manager Console while a new one is not?
Update: Changing the ExecutionPolicy to AllSigned and restarting VS2010 solves the immediate problem, but my main question is why the other projects were able to bypass the established ExecutionPolicy. VS2010 is not running as an administrator.
I experienced the same problem and solved it by:
Opening Powershell as an Administrator
Entering the following command "Set-ExecutionPolicy RemoteSigned"
Restart Visual Studio and the Package Manager Console worked as expected
It is important to note however that Powershell will give you a warning
"The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose you to the security risks described in the about_Execution_Policies help topic. Do you want to change the execution policy?"
And should be careful of enabling this feature and should read more information in the help topics about the security risks.
In addition to Murries' answer, I found jellonek's post (on another thread) helpful. You might have to change the permissions on a different version of PowerShell (32-bit and 64-bit versions require separate permissions).
From How to Tell if PowerShell is 32-bit or 64-bit:
64-bit PowerShell Path: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
32-bit PowerShell Path: C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe
Also, BOTH of these should work:
Set-ExecutionPolicy RemoteSigned
Set-ExecutionPolicy Unrestricted
Another way to fix this is by merging a Regedit file with the following content:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell]
"ExecutionPolicy"="Unrestricted"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell]
"ExecutionPolicy"="Unrestricted"
(Create a text file called NuGetPowerShellFix.txt, copy paste the above into it, rename to NuGetPowerShellFix.reg, then run.)
After merging the above file, restart Visual Studio.
If you're using NuGet in Visual Studio 2013 and get this annoying error, go to Tools | NuGet Package Manager | Package Manager Settings and click "Clear Package Cache." Restart Visual Studio. I know there are multiple solutions to this, so this is yet another to try.
I have had this problem intermittently as well. I just came across it again and ran across this thread. In my latest case, I realized I had VS 2013 open twice (which normally is not an issue, I do it all the time). Since the only common theme of others that seemed to fix it was circumstantially related to requiring administrator privileges I gave it a shot and closed both instances of VS and reopened my solution in a new instance. Ran the nuget install and it worked without a hitch.
Based on this, I am thinking that it is a file permission issue causing this spurious error. Sort of like when windows has a lock on a file in the bin directory after a debug session and will not let you compile the solution.
You may be able to resolve this by not running Visual Studio as Administrator.
Different cause, same error message; might be helpful for someone who runs into this one.
Since we needed to create a project on a share on a remote server in our network and ran into similar problems here's what worked:
map the share as a network drive, say R: (but I guess it would also work without this mapping)
open Internet options > Security > Local intranet > Sites > Advanced (via IE or control panel)
add either "R:" or "file://server.domain.xy" (the former will automatically turn into the latter once you reopen the dialog)
run the x86 PowerShell executable and do "Set-ExecutionPolicy RemoteSigned"
Once I did all that Visual Studio didn't complain that the project was in an untrusted location upon opening the solution again, and it successfully ran all the PowerShell scripts for the packages that get auto-installed when creating a new MVC application.
I'm having this issue now, i think what worked for me easy was that i just had to restart visual studio 2013 and run it as administrator...worked fast for me.

Resources