windows 将 PowerShell 用于 Visual Studio 命令提示符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4398136/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 15:46:15  来源:igfitidea点击:

Use PowerShell for Visual Studio Command Prompt

windowsvisual-studiowindows-7powershell

提问by ProfK

In a serious intiative to migrate all my command line operations to PowerShell, I would like to avoid using the old fashioned command console for anything. However, the Visual Studio Command prompt has various environment variables and path settings not found in the default command prompt. How could I create a 'Visual Studio PowerShell' with those same settings?

为了将我所有的命令行操作迁移到 PowerShell,我想避免使用老式的命令控制台进行任何操作。但是,Visual Studio 命令提示符具有默认命令提示符中没有的各种环境变量和路径设置。如何使用相同的设置创建“Visual Studio PowerShell”?

采纳答案by Roman Kuzmin

You can use for example this scriptto import Visual Studio command prompt environment, see the examples in the script documentation comments, e.g. for Visual Studio 2010:

例如,您可以使用此脚本导入 Visual Studio 命令提示符环境,请参阅脚本文档注释中的示例,例如 Visual Studio 2010:

Invoke-Environment '"%VS100COMNTOOLS%\vsvars32.bat"' 

Having done that in the beginning of a PowerShell session (from your profile or manually), you get what you ask for in this PowerShell session.

在 PowerShell 会话开始时(从您的配置文件或手动)完成此操作后,您将在此 PowerShell 会话中获得所需的内容。

Or you can use the solution provided by Keith Hill in this answer.

或者您可以使用 Keith Hill 在此答案中提供的解决方案。

回答by Yoni H

have a look at PowerConsole

看看PowerConsole

回答by Doug Finke

PowerConsole has been incorporated into NuGet http://nuget.codeplex.com/. You get PowerShell inside Visual Studio and a package management system.

PowerConsole 已合并到 NuGet http://nuget.codeplex.com/ 中。你可以在 Visual Studio 中获得 PowerShell 和一个包管理系统。

回答by zdan

What I do is create a simple cmd batch command script that looks like this:

我所做的是创建一个简单的 cmd 批处理命令脚本,如下所示:

call "%VS80COMNTOOLS%vsvars32.bat"
powershell

Then I create a shortcut that invokes this through cmd. The shortcut target looks like:

然后我创建了一个通过 cmd 调用它的快捷方式。快捷方式目标如下所示:

%windir%\System32\cmd.exe /k "SetupPSBuildEnvironment.cmd"

If you want the console to look like the powershell console, just modify the Layout to your liking in the shortcut properties.

如果您希望控制台看起来像 powershell 控制台,只需在快捷方式属性中根据您的喜好修改布局即可。

回答by mjsr

I use this script that I call Initialize-VisualStudio.ps1, i call it in my profile with dot source, to set the environment variables need it, in my actual session:

我使用这个我称之为 Initialize-VisualStudio.ps1 的脚本,我在我的配置文件中用点源调用它,在我的实际会话中设置需要它的环境变量:

param([switch]$ArquitectureX86)
if($ArquitectureX86)
{ $arq= "x86"}
else
{ $arq="x64"}
pushd 'c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC'
cmd /c "vcvarsall.bat $arq&set" |
foreach {
  if ($_ -match "=") {
  $v = $_.split("="); set-item -force -path "ENV:$($v[0])" -value "$($v[1])"; 
}
}
popd