如何将PowerShell与Visual Studio命令提示符一起使用? [英] How can I use PowerShell with the Visual Studio Command Prompt?

查看:211
本文介绍了如何将PowerShell与Visual Studio命令提示符一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Beta 2一段时间了,这让我发疯了,在运行VS2010命令提示符时,我不得不将其拖到cmd.exe.我曾经为Visual Studio 2008创建了一个不错的vsvars2008.ps1脚本.有人有vsvars2010.ps1或类似的东西吗?

I've been using Beta 2 for a while now and it's been driving me nuts that I have to punt to cmd.exe when running the VS2010 Command Prompt. I used to have a nice vsvars2008.ps1 script for Visual Studio 2008. Anyone have a vsvars2010.ps1 or something similar?

推荐答案

从此处自由地进行窃取:

Stealing liberally from here: http://allen-mack.blogspot.com/2008/03/replace-visual-studio-command-prompt.html, I was able to get this to work. I added the following to my profile.ps1 and all is well with the world.

pushd 'c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC'
cmd /c "vcvarsall.bat&set" |
foreach {
  if ($_ -match "=") {
    $v = $_.split("="); set-item -force -path "ENV:\$($v[0])"  -value "$($v[1])"
  }
}
popd
write-host "`nVisual Studio 2010 Command Prompt variables set." -ForegroundColor Yellow

多年来一直运行良好-直到Visual Studio2015.vcvarsall.bat不再存在.而是可以使用Common7 \ Tools文件夹中的vsvars32.bat文件.

This has worked well for years - until Visual Studio 2015. vcvarsall.bat no longer exists. Instead, you can use the vsvars32.bat file, which is located in the Common7\Tools folder.

pushd 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools'    
cmd /c "vsvars32.bat&set" |
foreach {
  if ($_ -match "=") {
    $v = $_.split("="); set-item -force -path "ENV:\$($v[0])"  -value "$($v[1])"
  }
}
popd
write-host "`nVisual Studio 2015 Command Prompt variables set." -ForegroundColor Yellow

对于Visual Studio 2017,事情再次发生了变化.vsvars32.bat似乎已被放弃,而对VsDevCmd.bat有利.确切的路径可能会有所不同,具体取决于您所使用的Visual Studio 2017版本.

Things have changed yet again for Visual Studio 2017. vsvars32.bat appears to have been dropped in favor of VsDevCmd.bat. The exact path may vary depending on which edition of Visual Studio 2017 you're using.

pushd "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools"
cmd /c "VsDevCmd.bat&set" |
foreach {
  if ($_ -match "=") {
    $v = $_.split("="); set-item -force -path "ENV:\$($v[0])"  -value "$($v[1])"
  }
}
popd
Write-Host "`nVisual Studio 2017 Command Prompt variables set." -ForegroundColor Yellow

这篇关于如何将PowerShell与Visual Studio命令提示符一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆