是否可以在launchSettings.json中引用环境变量



我想用NuGet包中的可执行文件运行我的代码。因此,exe在我的用户配置文件目录中。所以,文件看起来像这样:

{
"profiles": {
"UITests": {
"commandName": "Executable",
"executablePath": "C:\Users\MarkKharitonov\.nuget\packages\nunit.consolerunner\3.9.0\tools\nunit3-console.exe",
"commandLineArgs": "@params.txt --where:"method == LoginSuccessWithCorrectPassword" ..\..\UITests\bin\Debug\net472\UITests.dll",
"workingDirectory": "C:\DFDeploymentSmokeTests\LocalTestProfiles\qa56"
}
}
}

是否可以引用环境变量UserProfile并使用它来代替C:\Users\MarkKharitonov

编辑1

我根本不想让我的名字出现在文件中。这样,它可以被其他人重用,前提是他们的源代码位于同一个文件夹中,这不是问题。但是,只要我必须使用我的名字引用NuGet包的路径,这个文件就不能提交到源代码管理。

经过大量实验,它似乎在某种程度上取决于正在运行的命令。更准确地说,命令在哪个shell中运行。

如果它在cmd.exe中,%VARIABLE%应该可以工作。

如果它在powershell下运行,那么在双引号可扩展字符串中,它将是$env:VARIABLE${env:VARIABLE}

我建议如下。

{
"profiles": {
"UITests": {
"commandName": "Executable",
"executablePath": "${env:UserProfile}\.nuget\packages\nunit.consolerunner\3.9.0\tools\nunit3-console.exe",
"commandLineArgs": "@params.txt --where:"method == LoginSuccessWithCorrectPassword" ..\..\UITests\bin\Debug\net472\UITests.dll",
"workingDirectory": "C:\DFDeploymentSmokeTests\LocalTestProfiles\qa56"
}
}
}

假设UserProfile为C:\Users\MarkKharitonov

最新更新