I used to open a solution file in Visual Studio, right click a project, select "Debug" -> "Start a new instance" to start a debug session.
Can I write a powershell script to automate this? To make things easier, the automation does not have to rebuild and Project, the script only needs to start a debug session in Visual Studio executing myApplication.debug.exe
Visual Studio has a 'DebugExe' command-line parameter you can use to accomplish this.
param
(
[Parameter(Mandatory = $false)]
[String]
$TargetFileName
)
& "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe" /command "Debug.Start" /debugexe "$TargetFileName"
Related
I would like to modify the standard PowerShell profile in Windows if the Powershell opens inside VS Code integrated terminal (when you are editing e.g. python scripts in VS Code, rather than PS scripts, which opens the ISE profile in any case).
Is there some environmental variable that gets set by the integrated PowerShell? Or is there some way of opening Powershell with a particular profile, instead of the default?
Thanks
VS Code creates an environment variable named TERM_PROGRAM. You can check it for a value of vscode, something like this:
if($env:TERM_PROGRAM -eq 'vscode') {
# do some stuff...
}
If you want to check if you're running within PowerShell Integrated Console (ships with PowerShell extension) under vscode and not just any powershell console running under vscode, you can:
if ($Host.Name -eq 'Visual Studio Code Host') {
Write-Output 'PowerShell Integrated Console'
}
This is meaningful to detect because it is the only powershell console host that provided full debugger support (eg. break on exception experience) and debugger integration with vscode.
You said you're into modifying profile when running within vscode, then you should check (again with PowerShell integrated console which ships with PoweShell extension):
PS> $PROFILE.CurrentUserCurrentHost
C:\Users\username\Documents\PowerShell\Microsoft.VSCode_profile.ps1
PS> $PROFILE.AllUsersCurrentHost
C:\Program Files\PowerShell\7\Microsoft.VSCode_profile.ps1
If people are working on PowerShell code within Visual Studio Code, then why they would NOT install PowerShell extension which ships with a specific console that fully integrates with Visual Studio code and on the top of that, provides you a profile file specifically geared towards Visual Studio code?
I have a .PS1 file as part of Visual Studio 2017 project. Let me know, how to execute this script file in debug mode (VS debug mode)? also let me know, how to pass input variables to this script file?
Check out PowerShell Tools for Visual Studio and the PowerShell Class.
I am trying to rum my test cases through Visual Studio test in PowerShell but it's giving me an error. It's working fine with CMD - why?
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" C:\DLL\Automation_2.dll /Tests:AccessToWire
You have to prefix your invoke with an ampersand. Also use quotes for your parameters:
& "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" "C:\DLL\Automation_2.dll" "/Tests:AccessToWire"
This question already has answers here:
How can I use PowerShell with the Visual Studio Command Prompt?
(15 answers)
Closed 1 year ago.
I have Visual Studio 9.0 installed but I want to use it manually from PowerShell. It comes with two setup scripts: vcvars32.bat for the 32-bit compiler and vcvars64.bat for the 64-bit compiler. When I open cmd.exe and run one of the scripts, it sets up everything just fine and I can run cl.exe without any problems. When I run one of those setup scripts from PowerShell, though, it doesn't work. The scripts run through fine but trying to run cl.exe afterwards yields a "cl.exe could not be found" error! And looking at the contents of the PATH environment variable after running one of the setup scripts I can see that PATH hasn't actually been modified at all.
So it seems as if the batch files ran from PowerShell maintain their own environment variables state which goes away as soon as the batch file terminates. So is there a way to run batch files from PowerShell and have those batch files affect the actual environment variables of the current PowerShell session? Because that is what I need. All that is done by vcvars32.bit and vcvars64.bit is setting up environment variables after all but it only seems to work from cmd.exe, not from PowerShell.
You should use InvokeEnvironment script to do that. Check its man page:
Invoke-Environment <path_to_>vsvars32.bat
You can furhter generalize this by determining OS bits and crafting the vsvars<OsBits>.bat.
Example:
PS C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools> $env:INCLUDE -eq $null
PS C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools> $true
PS C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools> Invoke-Environment .\vsvars32.bat
PS C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools> $env:INCLUDE
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE;C:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\ucrt;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\shared;C:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\winrt;
I don't have Visual Studio at hand, but the batch scripts most likely just set variables for the current session. Running them from PowerShell won't do you any good, because they'll be launched in a child CMD process and change the process environment of that process, but not of the parent (PowerShell) process.
I suspect you need to translate the variable definitions to PowerShell, e.g.
set PATH=%PATH%;C:\some\where
set FOO=bar
becomes
$env:Path += ';C:\some\where'
$env:FOO = 'bar'
Write the translated definitions to a .ps1 file and dot-source that file in your PowerShell session:
. C:\path\to\vcvars.ps1
How could i install any ".exe" without having any user action, means wherever the user interaction needed it should continue with the default selection (eg: license agreement) using powershell
any reference or links will help
[Discussed Below: Mostly wanted to install visual studio and visual studio related update]
If you are talking about Visual studio, and Microsoft product in general, you should look for unattended installation for example : How to: Create and Run an Unattended Installation of Visual Studio.
For Visual Studio below command works:
Start-Process -FilePath "C:\Installs\VS2013\vspremium.exe" -ArgumentList "/adminfile C:\Installs\VS2013\AdminDeployment.xml /passive /norestart" -Wait -NoNewWindow -PassThru
Also in the AdminDeployment.xml file you can make NoWeb="yes", it works otherwise as well.
<BundleCustomizations TargetDir="default" NoWeb="yes"/>