SubZeno SubZeno - 1 year ago 229
C# Question

How to permanently set Environment Variables for the Visual Studio command line

For my project I need to use the Visual Studio Development Tools as additional command line features, for instance to create dlls with the tlbimp utility.

According to the Microsoft documentation, I need to properly configure my environment variables for the Visual Studio Command Line, by calling the


file sets the appropriate environment variables to enable command-line builds. (More info:

What looks annoying in my case, it's that these features are temporary available in my PowerShell prompt. Every time I need to re-run that batch file. Is there a clever way to make them persistent?

Answer Source

You can configure or modify (if it already exists) your Powershell profile in order to automatically invoke the vsvars32.bat batch file:

function Invoke-Batchfile ($file) {
    $cmd = "`"$file`" & set"
    cmd /c $cmd | Foreach-Object {
    $p, $v = $_.split('=')
        Set-Item -path env:$p -value $v

Invoke-Batchfile "$env:VSCOMNTOOLS\vsvars32.bat"

Take into account that you first need to define as well an environment variable pointing to your Visual Studio installation path, according to the used version:

  • For Visual Studio 15 Update 3 (v.14.0):

$env:VSCOMNTOOLS = "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools"

  • For Visual Studio 13. (v.12.0):

$env:VSCOMNTOOLS = "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools"

  • Etc...

Now, everytime you open your Poweshell prompt, the Visual Studio development tools' features will be available.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download