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"
Related
In my profile settings for powershell I have the following lines:
set-alias vs startVisualStudio
function startVisualStudio {
Start-Process -FilePath "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\devenv.exe" .\\*.sln
}
When I navigate to a directory containing a .sln file and type vs, Visual Studio opens to the default start screen telling me that .\*.sln could not be found. I have tried several ways of including the asterisk, like 'backtick'*.sln, /*.sln among other, but always the same message. If I replace the .\*.sln with a simple . and run vs, it does open the current directory in visual studio, however not as a solution. How can I write this function to open the .sln in the current directory in Visual Studio?
* isn't unwrapped by powershell, it will just pass it on to Visual Studio. Visual Studio won't do it either, so you have to do it yourself. Find all solution files in the folder and get the first one. This will fail if no .sln-files are present.
set-alias vs startVisualStudio
function startVisualStudio
{
$slnfile = (Get-ChildItem -Path .\ -Filter *.sln)[0].Name
Start-Process -FilePath "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\devenv.exe" $slnfile
}
I got this working recursively (Powershell 7.0) in sub directories too by doing the following:
Open powershell, type
echo $profile
Open up the location of your profile, save the below into it:
function vs
{
Get-ChildItem *.sln -Recurse | Invoke-Item
}
Then just type vs into a folder and it will open solution file in any containing folders
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.
This is my first attempt at automating some of my development environment setup. I have the following powershell script:
& "C:\MAMP\MAMP.exe"
& "C:\Program Files\Microsoft VS Code\Code.exe"
I run it and it works fine, but when I close the powershell window it closes my VS Code window as well. MAMP stays open.
I'm sure this is a simple fix. Thanks!
Have you tried with Start-Process?
Start-Process "C:\Program Files\Microsoft VS Code\Code.exe"
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
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"