{"id":3692,"date":"2016-03-11T20:16:22","date_gmt":"2016-03-11T20:16:22","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=3692"},"modified":"2016-05-25T12:48:02","modified_gmt":"2016-05-25T12:48:02","slug":"setup-powershell-to-use-the-visual-studio-paths-etc","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/setup-powershell-to-use-the-visual-studio-paths-etc\/","title":{"rendered":"Setup Powershell to use the Visual Studio paths etc."},"content":{"rendered":"<p>This one&#8217;s straight off of <a href=\"http:\/\/stackoverflow.com\/questions\/2124753\/how-i-can-use-powershell-with-the-visual-studio-command-prompt\" target=\"_blank\">How I can use PowerShell with the Visual Studio Command Prompt?<\/a> and it works a treat.<\/p>\n<p>So I amend the $profile file with the following (updated to include VS 2015)<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nfunction Set-VsCmd\r\n{\r\n    param(\r\n        &#x5B;parameter(Mandatory=$true, HelpMessage=&quot;Enter VS version as 2010, 2012, 2013, 2015&quot;)]\r\n        &#x5B;ValidateSet(2010,2012,2013,2015)]\r\n        &#x5B;int]$version\r\n    )\r\n    $VS_VERSION = @{ 2010 = &quot;10.0&quot;; 2012 = &quot;11.0&quot;; 2013 = &quot;12.0&quot;; 2015 = &quot;14.0&quot; }\r\n    if($version -eq 2015)\r\n    {\r\n        $targetDir = &quot;c:\\Program Files (x86)\\Microsoft Visual Studio $($VS_VERSION&#x5B;$version])\\Common7\\Tools&quot;\r\n        $vcvars = &quot;VsMSBuildCmd.bat&quot;\r\n    }\r\n    else\r\n    {\r\n        $targetDir = &quot;c:\\Program Files (x86)\\Microsoft Visual Studio $($VS_VERSION&#x5B;$version])\\VC&quot;\r\n        $vcvars = &quot;vcvarsall.bat&quot;\r\n    }\r\n \r\n    if (!(Test-Path (Join-Path $targetDir $vcvars))) {\r\n        &quot;Error: Visual Studio $version not installed&quot;\r\n        return\r\n    }\r\n    pushd $targetDir\r\n    cmd \/c $vcvars + &quot;&amp;set&quot; |\r\n    foreach {\r\n      if ($_ -match &quot;(.*?)=(.*)&quot;) {\r\n        Set-Item -force -path &quot;ENV:\\$($matches&#x5B;1])&quot; -value &quot;$($matches&#x5B;2])&quot;\r\n      }\r\n    }\r\n    popd\r\n    write-host &quot;`nVisual Studio $version Command Prompt variables set.&quot; -ForegroundColor Yellow\r\n}\r\n<\/pre>\n<p>The previous version (non-VS 2015) is listed below in case it&#8217;s still needed<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nfunction Set-VsCmd\r\n{\r\n    param(\r\n        &#x5B;parameter(Mandatory=$true, HelpMessage=&quot;Enter VS version as 2010, 2012, or 2013&quot;)]\r\n        &#x5B;ValidateSet(2010,2012,2013)]\r\n        &#x5B;int]$version\r\n    )\r\n    $VS_VERSION = @{ 2010 = &quot;10.0&quot;; 2012 = &quot;11.0&quot;; 2013 = &quot;12.0&quot; }\r\n    $targetDir = &quot;c:\\Program Files (x86)\\Microsoft Visual Studio $($VS_VERSION&#x5B;$version])\\VC&quot;\r\n    if (!(Test-Path (Join-Path $targetDir &quot;vcvarsall.bat&quot;))) {\r\n        &quot;Error: Visual Studio $version not installed&quot;\r\n        return\r\n    }\r\n    pushd $targetDir\r\n    cmd \/c &quot;vcvarsall.bat&amp;set&quot; |\r\n    foreach {\r\n      if ($_ -match &quot;(.*?)=(.*)&quot;) {\r\n        Set-Item -force -path &quot;ENV:\\$($matches&#x5B;1])&quot; -value &quot;$($matches&#x5B;2])&quot;\r\n      }\r\n    }\r\n    popd\r\n    write-host &quot;`nVisual Studio $version Command Prompt variables set.&quot; -ForegroundColor Yellow\r\n}\r\n<\/pre>\n<p>Another user on the same question of stackoverlow also put forward the idea of simply changing the shortcut that Visual Studio supply to add the &#038; powershell, like this<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n%comspec% \/k &quot;&quot;C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\Common7\\Tools\\VsDevCmd.bat&quot; &amp; powershell&quot;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This one&#8217;s straight off of How I can use PowerShell with the Visual Studio Command Prompt? and it works a treat. So I amend the $profile file with the following (updated to include VS 2015) function Set-VsCmd { param( &#x5B;parameter(Mandatory=$true, HelpMessage=&quot;Enter VS version as 2010, 2012, 2013, 2015&quot;)] &#x5B;ValidateSet(2010,2012,2013,2015)] &#x5B;int]$version ) $VS_VERSION = @{ 2010 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[118,50],"tags":[],"class_list":["post-3692","post","type-post","status-publish","format-standard","hentry","category-powershell","category-visual-studio"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/3692","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=3692"}],"version-history":[{"count":5,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/3692\/revisions"}],"predecessor-version":[{"id":4017,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/3692\/revisions\/4017"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=3692"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=3692"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=3692"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}