PowerShell is the more powerful and flexible of the two, while cmd is more straightforward and easier to learn. So, which one should you use? The answer is that it depends on what you need to do. While both are used for executing commands, there are some key differences between the two. \\\"$fileNameWithoutExt.exe\" Write-Host -NoNewLine 'Press any key to continue.When it comes to command-line interfaces, two options come to mind: PowerShell and Command Prompt (cmd). If (!(Test-Path (Join-Path $targetDir "vcvarsall.bat"))) popd cls cl *.cpp. $targetDir = "c:\Program Files (x86)\Microsoft Visual Studio $($VS_VERSION)\VC" That also happens to simplify the code: a single match instead of a match then split as in Andy's example or a match then indexof and substrings as in "me-"'s example). Here is my final code-note the use of the non-greedy quantifier in the regex to handle any possible embedded equals in the values. This builds on Andy's technique (which builds on Allen Mack's technique as Andy indicated (which in turn builds on Robert Anderson's technique as Allen indicated (all of which had a slight glitch as indicated on this page by the user known only as "me-", so I took that into account as well))). To (a) provide Visual Studio 2013 support (b) combine the best of two previous answers and (c) provide a function wrapper: Note: this function will be available in the PowerShell Community Extensions 2.0 module-based release coming soon. # For each of them, set the variable in our local environment. # Go through the environment variables in the temp file. # the environment table after the batch file completesĬmd.exe /c " `"$Path`" $Parameters & set > `"$tempFile`" " Invokes the vcvarsall.bat file to set up a 64-bit dev environment. AllĮnvironment variable changes it makes will be propagated to the currentĬ:\PS> Invoke-BatchFile "$env:VS90COMNTOOLS\.\.\vc\vcvarsall.bat" amd64 Invokes the vcvarsall.bat file to set up a 32-bit dev environment. I use a script that Lee Holmes wrote a while back: Invoke-BatchFile "$env:VS90COMNTOOLS\.\.\vc\vcvarsall.bat" If you really want to do this from your "home" PowerShell prompt, the approach you show is the way to go. The simplest option is to run the VS 2010 command prompt and then start PowerShell.exe. Write-Host "`nVisual Studio 2022 Command Prompt variables set." -ForegroundColor Yellow pushd "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools" Minor Changes for Visual Studio 2022, now that it's 64-bit. You can also make the split create just two items to avoid breaking values including the equal sign, which is also the separator of the environment variable name and the value: $v = $_.split("=", 2) set-item -force -path "ENV:\$($v)" -value Write-Host "`nVisual Studio 2017 Command Prompt variables set." -ForegroundColor Yellow pushd "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools" The exact path may vary depending on which edition of Visual Studio 2017 you're using. vsvars32.bat appears to have been dropped in favor of VsDevCmd.bat. Things have changed yet again for Visual Studio 2017. Write-host "`nVisual Studio 2015 Command Prompt variables set." -ForegroundColor Yellow pushd 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools' Instead, you can use the vsvars32.bat file, which is located in the Common7\Tools folder. This has worked well for years - until Visual Studio 2015. Write-host "`nVisual Studio 2010 Command Prompt variables set." -ForegroundColor Yellow pushd 'c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC' I added the following to my profile.ps1 file and all is well with the world. Stealing liberally from blog post Replace Visual Studio Command Prompt with PowerShell, I was able to get this to work.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |