如何在 Visual Studio 命令提示符下使用 PowerShell?

编程入门 行业动态 更新时间:2024-10-26 08:26:34
本文介绍了如何在 Visual Studio 命令提示符下使用 PowerShell?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用 Beta 2 已经有一段时间了,当我运行 Visual Studio 2010 命令提示符时不得不转向 cmd.exe,这让我很抓狂.我曾经有一个很好的 vsvars2008.ps1 脚本用于 Visual Studio 2008.是否有 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 Visual Studio 2010 Command Prompt. I used to have a nice vsvars2008.ps1 script for Visual Studio 2008. Is there a vsvars2010.ps1 script or something similar?

推荐答案

大量窃取博文 用 PowerShell 替换 Visual Studio 命令提示符,我能够让它工作.我将以下内容添加到我的 profile.ps1 文件中,一切都很好.

Stealing liberally from blog post Replace Visual Studio Command Prompt with PowerShell, I was able to get this to work. I added the following to my profile.ps1 file and all is well with the world.

pushd 'c:Program Files (x86)Microsoft Visual Studio 10.0VC' 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 Studio 2015.vcvarsall.bat 不再存在.相反,您可以使用 vsvars32.bat 文件,该文件位于 Common7Tools 文件夹.

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 Common7Tools folder.

pushd 'C:Program Files (x86)Microsoft Visual Studio 14.0Common7Tools' 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 Studio2017EnterpriseCommon7Tools" 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

您也可以让拆分只创建两个项目以避免破坏包括等号在内的值,它也是环境变量名称和值的分隔符:

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[0])" -value

Visual Studio 2022 的小改动,现在它是 64 位.

Minor Changes for Visual Studio 2022, now that it's 64-bit.

pushd "C:Program FilesMicrosoft Visual Studio2022EnterpriseCommon7Tools" cmd /c "VsDevCmd.bat&set" | foreach { if ($_ -match "=") { $v = $_.split("=", 2); set-item -force -path "ENV:$($v[0])" -value } } popd Write-Host "`nVisual Studio 2022 Command Prompt variables set." -ForegroundColor Yellow

更多推荐

如何在 Visual Studio 命令提示符下使用 PowerShell?

本文发布于:2023-11-06 17:20:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1564309.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:命令提示符   如何在   Studio   Visual   PowerShell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!