My Technical Notes

Friday, 8 May 2015

PowerShell: using the Visual Studio Command Prompt bat file

Install PowerShell Community Extensions and Import the PSCX module:

Import PSCX

You may have to restart the computer after installing it.

You can use either `Invoke-BatchFile` with the full path to the bat file:

Invoke-BatchFile "${env:ProgramFiles(x86)}\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"

or you can use the `Import-VisualStudioVars` command:

Import-VisualStudioVars -VisualStudioVersion 2013

Note that calling it twice will still re-append to the `path` variable. To prevent this from happening, we can use `Get-Command`:

if (-not (Get-Command xsd.exe -ErrorAction SilentlyContinue)) {
    Import-VisualStudioVars -VisualStudioVersion 2013    

No comments: