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

mar*_*ark 5 asp.net-core-mvc .net-core

我想使用 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"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

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

编辑1

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

小智 2

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

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

如果它在 powershell 下运行,那么它将是$env:VARIABLEor${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"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

假设 UserProfile 是 C:\Users\MarkKharitonov