And*_*y S 116 powershell visual-studio-2010 visual-studio
我现在已经使用Beta 2了一段时间,这让我疯狂,我必须在运行VS2010命令提示符时向cmd.exe发挥作用.我曾经为Visual Studio 2008提供了一个很好的vsvars2008.ps1脚本.任何人都有vsvars2010.ps1或类似的东西吗?
And*_*y S 214
从这里偷偷地偷窃:http://allen-mack.blogspot.com/2008/03/replace-visual-studio-command-prompt.html,我能够让它发挥作用.我将以下内容添加到我的profile.ps1中,并且一切都与世界相符.
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
Run Code Online (Sandbox Code Playgroud)
这已经运行了好几年 - 直到Visual Studio 2015.vcvarsall.bat不再存在.相反,您可以使用vsvars32.bat文件,该文件位于Common7\Tools文件夹中.
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
Run Code Online (Sandbox Code Playgroud)
对于Visual Studio 2017,情况再次发生了变化.vsvars32.bat似乎已被弃用了VsDevCmd.bat.确切的路径可能会有所不同,具体取决于您使用的Visual Studio 2017版本.
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
Run Code Online (Sandbox Code Playgroud)
Kei*_*ill 25
最简单的选项是运行VS 2010命令提示符,然后启动PowerShell.exe.如果你真的想从你的"home"PowerShell提示符中做到这一点,那么你展示的方法就是你要走的路.我使用了Lee Holmes写的一段脚本:
<#
.SYNOPSIS
Invokes the specified batch file and retains any environment variable changes
it makes.
.DESCRIPTION
Invoke the specified batch file (and parameters), but also propagate any
environment variable changes back to the PowerShell environment that
called it.
.PARAMETER Path
Path to a .bat or .cmd file.
.PARAMETER Parameters
Parameters to pass to the batch file.
.EXAMPLE
C:\PS> Invoke-BatchFile "$env:VS90COMNTOOLS\..\..\vc\vcvarsall.bat"
Invokes the vcvarsall.bat file to set up a 32-bit dev environment. All
environment variable changes it makes will be propagated to the current
PowerShell session.
.EXAMPLE
C:\PS> Invoke-BatchFile "$env:VS90COMNTOOLS\..\..\vc\vcvarsall.bat" amd64
Invokes the vcvarsall.bat file to set up a 64-bit dev environment. All
environment variable changes it makes will be propagated to the current
PowerShell session.
.NOTES
Author: Lee Holmes
#>
function Invoke-BatchFile
{
param([string]$Path, [string]$Parameters)
$tempFile = [IO.Path]::GetTempFileName()
## Store the output of cmd.exe. We also ask cmd.exe to output
## the environment table after the batch file completes
cmd.exe /c " `"$Path`" $Parameters && set > `"$tempFile`" "
## Go through the environment variables in the temp file.
## For each of them, set the variable in our local environment.
Get-Content $tempFile | Foreach-Object {
if ($_ -match "^(.*?)=(.*)$")
{
Set-Content "env:\$($matches[1])" $matches[2]
}
}
Remove-Item $tempFile
}
Run Code Online (Sandbox Code Playgroud)
注意:此功能将在即将发布的PowerShell Community Extensions 2.0模块版本中提供.
use*_*702 18
我在这里找到了一个简单的方法:修改快捷方式.
原始快捷方式是这样的:
%comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\VsDevCmd.bat""
Run Code Online (Sandbox Code Playgroud)
& powershell在最后一个引用之前添加,如下所示:
%comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\VsDevCmd.bat" & powershell"
Run Code Online (Sandbox Code Playgroud)
如果要使其看起来更像PS,请转到快捷方式属性的" 颜色"选项卡,并将红色,绿色和蓝色值分别设置为1,36和86.
Mic*_*ens 16
一个老问题,但值得另一个答案(a)提供VS2013支持; (b)结合前两个答案中的最佳答案; (c)提供功能包装.
这是建立在@ Andy的技术基础之上的(基于Allen Mack的技术,正如Andy指出的那样(反过来建立在Robert Anderson的技术上,正如Allen指出的那样(所有这些都有一个轻微的故障,如本页所示,用户只知道为"我 - - "所以我也考虑到了这一点))).
这是我的最终代码 - 请注意在正则表达式中使用非贪婪量词来处理值中任何可能的嵌入等于.这也恰好简化了代码:单个匹配而不是匹配,然后在Andy的示例中进行拆分,或者匹配,然后在"我 - "的示例中匹配indexof和substrings).
function Set-VsCmd
{
param(
[parameter(Mandatory, HelpMessage="Enter VS version as 2010, 2012, or 2013")]
[ValidateSet(2010,2012,2013)]
[int]$version
)
$VS_VERSION = @{ 2010 = "10.0"; 2012 = "11.0"; 2013 = "12.0" }
$targetDir = "c:\Program Files (x86)\Microsoft Visual Studio $($VS_VERSION[$version])\VC"
if (!(Test-Path (Join-Path $targetDir "vcvarsall.bat"))) {
"Error: Visual Studio $version not installed"
return
}
pushd $targetDir
cmd /c "vcvarsall.bat&set" |
foreach {
if ($_ -match "(.*?)=(.*)") {
Set-Item -force -path "ENV:\$($matches[1])" -value "$($matches[2])"
}
}
popd
write-host "`nVisual Studio $version Command Prompt variables set." -ForegroundColor Yellow
}
Run Code Online (Sandbox Code Playgroud)
Keith已经提到了PowerShell社区扩展(PSCX)及其Invoke-BatchFile命令:
Invoke-BatchFile "${env:ProgramFiles(x86)}\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"
Run Code Online (Sandbox Code Playgroud)
我也注意到PSCX也有一个Import-VisualStudioVars功能:
Import-VisualStudioVars -VisualStudioVersion 2013
Run Code Online (Sandbox Code Playgroud)
代替
Import-Module "VS-Directory\Community\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
Enter-VsDevShell -VsInstallPath "VS-Directory\Community" -DevCmdArguments
Run Code Online (Sandbox Code Playgroud)
但是,如果您希望 VS 默认使用 64 位 MSVC 和环境,则可以使用 arch=64 的 DevCmdArguments
Enter-VsDevShell -VsInstallPath "VS-Directory\Community" -DevCmdArguments '-arch=x64'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
40456 次 |
| 最近记录: |