2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Windows Terminal に x64 Native Tools Command Prompt for VS 2019 を登録する

Last updated at Posted at 2020-09-10

Windows Terminal から Visual Studio Build Tools を起動するには、settings.json に呼び出し用の命令を登録してしまえばいいんだなあと思いまして、コマンドプロンプトの例を参考にしながら、こんなふうに追加してみました。

            {
                // Make changes here to the cmd.exe profile.
                "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
                "name": "コマンド プロンプト",
                "commandline": "cmd.exe",
                "hidden": false
            },
            {
                // Make changes here to the vs2019-x64 batchfile profile.
                "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6102}",
                "name": "x64 Native Tools Command Prompt for VS 2019",
                "commandline": "cmd.exe /k C:\\Programs86\\MicrosoftVS\\2019\\BuildTools\\VC\\Auxiliary\\Build\\vcvars64.bat",
                "startingDirectory": "C:\\Users\\pcowner\\",
                "hidden": false
            },

commandline に書く内容は、スタートメニューの Visual Studio 2019 , Visual Studio Tools, VC の中にあるショートカットを参考にしました。/k オプションが大事です。忘れると悲しい。

さらにcmdではなくpowershellで使おうとする場合はこうなります。上の例とはVS2019のインストール先が異なるため、エスケープ地獄に陥っています。

            {
                // Make changes here to the powershell.exe profile.(これは見本)
                "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
                "name": "Windows PowerShell",
                "commandline": "powershell.exe",
                "hidden": false
            },
            {
                // Make changes here to the vs2019-x64 powershell.exe profile.
                "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44c0}",
                "name": "Windows PowerShell vs2019",
                "commandline": "powershell.exe -noe -c \" &{ Import-Module \"\"\"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\Common7\\Tools\\Microsoft.VisualStudio.DevShell.dll\"\"\" ; Enter-VsDevShell xxxxxxxx -DevCmdArguments -arch=x64 } \"",
                "startingDirectory": "C:\\Users\\ta\\",
                "hidden": false
            },

commandline に与える文字列の書き方は、スタートメニューの Visual Studio 2019 , Visual Studio Tools の中にある Developer PowerShell for VS 2019 を参考にします。これはショートカットなので、ファイルの場所を開いたりプロパティを見るなどして、リンク先を探します。例えばリンク先が以下のようになっている場合


C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -noe -c "&{Import-Module """C:\Programs86\MicrosoftVS\2019\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"""; Enter-VsDevShell yyyyyyyy}"

"commandline":"(この部分)"


"commandline":"powershell.exe -noe -c \"&{Import-Module \"\"\"C:\\Programs86\\MicrosoftVS\\2019\\BuildTools\\Common7\\Tools\\Microsoft.VisualStudio.DevShell.dll\"\"\"; Enter-VsDevShell yyyyyyyy -DevCmdArguments -arch=x64}\""

となります。Enter-VsDevShell の引数(インスタンスID)はユーザによって異なるようなので、自分の環境のもの書く必要があります。(知らなかった)

guidはpowershellの New-Guid でちゃんと発行したほうがいいかもしれませんね。

参考記事

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?