有没有办法在launchSettings.json中使用构建变量?

时间:2019-10-22 20:54:33

标签: visual-studio-2019

我正在像这样手动调用NUnit控制台运行器:

"MyRunConfig": {
  "commandName": "Executable",
  "executablePath": "nunit3-console.exe",
  "commandLineArgs": "MyProject\\bin\\Debug\\MyProject.dll"
}

问题是,由于输出位置不同,我必须为Release版本进行单独的运行配置。我怎么做?我可以以某种方式使用TargetPath构建属性吗?

1 个答案:

答案 0 :(得分:0)

我使用的是 VS 2019 16.10.4,我在 launchSettings.json 中使用了 $(OutDir)$(ConfigurationName) 宏。所以你的配置可能看起来像:

"MyRunConfig": {
  "commandName": "Executable",
  "executablePath": "nunit3-console.exe",
  "commandLineArgs": "MyProject\\$(OutDir)MyProject.dll"
}

或者使用 $(TargetPath) 将是:

"MyRunConfig": {
  "commandName": "Executable",
  "executablePath": "nunit3-console.exe",
  "commandLineArgs": "$(TargetPath)"
}

您可以使用任何 Pre/Post-Build Macros。我通常会进入“编辑预构建...”对话框(在项目属性“构建事件”页面上)并使用其宏按钮,以便我可以看到它们各自解析的内容。

我在 Microsoft 的任何地方都找不到此宏支持的文档,但它在 .NET 5.0 项目中对我有用。

相关问题