visual studio open linea instalar iniciar consola comandos code abrir visual-studio-2010 visual-studio powershell

visual studio 2010 - open - ¿Cómo puedo usar PowerShell con el símbolo del sistema de Visual Studio?



visual studio 2010 command prompt (7)

He estado usando Beta 2 desde hace un tiempo y me ha estado volviendo loco que tengo que punt a cmd.exe cuando ejecuto el símbolo del sistema VS2010. Solía ​​tener un buen script vsvars2008.ps1 para Visual Studio 2008. ¿Alguien tiene un vsvars2010.ps1 o algo similar?


Encontré un método simple here : modifique el acceso directo.

El atajo original es algo como esto:

%comspec% /k ""C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/Tools/VsDevCmd.bat""

Agrega & powershell agrega & powershell antes de la última cita, así:

%comspec% /k ""C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/Tools/VsDevCmd.bat" & powershell"

Si desea que se parezca más a PS, vaya a la pestaña Colores de las propiedades de acceso directo y establezca los valores Rojo, Verde y Azul en 1, 36 y 86, respectivamente.


Felicitaciones a Andy S por su respuesta. He estado usando su solución por un tiempo, pero hoy tuve un problema. Cualquier valor que tenga un signo igual en él se trunca en el signo igual. Por ejemplo, tuve:

JAVA_TOOL_OPTIONS=-Duser.home=C:/Users/Me

Pero mi sesión de PS informó:

PS C:/> $env:JAVA_TOOL_OPTIONS -Duser.home

Lo arreglé modificando mi script de perfil a lo siguiente:

pushd ''c:/Program Files (x86)/Microsoft Visual Studio 11.0/VC'' cmd /c "vcvarsall.bat&set" | foreach { if ($_ -match "=") { $i = $_.indexof("=") $k = $_.substring(0, $i) $v = $_.substring($i + 1) set-item -force -path "ENV:/$k" -value "$v" } } popd


Keith ya mencionó PowerShell Community Extensions (PSCX), con su comando Invoke-BatchFile :

Invoke-BatchFile "${env:ProgramFiles(x86)}/Microsoft Visual Studio 12.0/VC/vcvarsall.bat"

También noté que PSCX también tiene una función Import-VisualStudioVars :

Import-VisualStudioVars -VisualStudioVersion 2013


La opción más simple es ejecutar el símbolo del sistema de VS 2010 y luego iniciar PowerShell.exe. Si realmente desea hacer esto desde su mensaje de "inicio" de PowerShell, el enfoque que muestre es el camino a seguir. Uso un script que Lee Holmes escribió hace un tiempo:

<# .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 }

Nota: esta función estará disponible en la versión de PowerShell Community Extensions 2.0 basada en módulos próximamente.


Me gusta pasar los comandos a un shell hijo así:

cmd /c "`"${env:VS140COMNTOOLS}vsvars32.bat`" && <someCommand>"

O alternativamente

cmd /c "`"${env:VS140COMNTOOLS}../../VC/vcvarsall.bat`" amd64 && <someCommand> && <someOtherCommand>"


Robando liberalmente desde aquí: http://allen-mack.blogspot.com/2008/03/replace-visual-studio-command-prompt.html , pude hacer que esto funcione. Agregué lo siguiente a mi profile.ps1 y todo está bien con el mundo.

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

Esto funcionó bien durante años, hasta Visual Studio 2015. vcvarsall.bat ya no existe. En su lugar, puede usar el archivo vsvars32.bat, que se encuentra en la carpeta 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

Las cosas han cambiado una vez más para Visual Studio 2017. Parece que vsvars32.bat se ha descartado a favor de VsDevCmd.bat . La ruta exacta puede variar según la edición de Visual Studio 2017 que esté utilizando.

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


Una pregunta anterior pero que vale otra respuesta para (a) proporcionar el soporte VS2013; (b) combine lo mejor de las dos respuestas anteriores; y (c) proporcionar una envoltura de función.

Esto se basa en la técnica de Andy (que se basa en la técnica de Allen Mack como lo indicó Andy (que a su vez se basa en la técnica de Robert Anderson tal como lo indicó Allen). Todos ellos tenían un ligero error como el que se indica en esta página por el usuario "me- - ", así que lo tomé en cuenta también))).

Aquí está mi código final: tenga en cuenta el uso del cuantificador no codicioso en la expresión regular para manejar cualquier posible igual incrustado en los valores. Eso también simplifica el código: una coincidencia única en lugar de una coincidencia, luego se divide como en el ejemplo de Andy o una coincidencia, luego un índice y subcadenas como en el ejemplo de "yo".

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 }