【问题标题】:Visual Studio: Pass Arguments to an Executable in the Compiler Post-Build EventsVisual Studio:将参数传递给编译器生成后事件中的可执行文件
【发布时间】:2018-08-25 18:40:40
【问题描述】:

我正在尝试运行一个可执行文件以在 Visual Studio 的构建后事件中更改我的应用程序配置。根据配置是调试还是发布,我想将参数传递给我的可执行文件,以便正确执行我的配置更改器。这是我所做的:

if $(ConfigurationName) == Release 
(
"$(ProjectDir)ConfigurationGenerator\ConfigurationGenerator.exe" Release $(OutDir)applicationConfiguration.config 
)

if $(ConfigurationName) == Debug 
(
"$(ProjectDir)ConfigurationGenerator\ConfigurationGenerator.exe" Debug $(OutDir)applicationConfiguration.config
)

因此,在这种情况下,“Debug”和“Release”是参数 #1,“$(OutDir)applicationConfiguration.config”是参数 #2。每次我尝试运行我的应用程序时,它都会使构建崩溃,并在错误列表窗口中返回我,我的应用程序以退出代码 3 停止。有什么想法吗?

【问题讨论】:

  • 你已经描述了你做了什么,但你没有描述它有什么问题。
  • 好的,我来编辑一下
  • 希望该实用程序不仅仅在失败时设置退出代码。在“输出”窗口中查找它吐出的诊断消息。通常,您需要将文件路径参数放在“双引号”中,这样​​路径中的空格就不会造成麻烦。退出代码有时等于 Windows 错误,3 == path not found.

标签: c# visual-studio post-build-event


【解决方案1】:

你甚至需要一个条件?只需传入$Configuration

<PropertyGroup>
  <PostBuildEvent>
    Call "$(ProjectDir)ConfigurationGenerator\ConfigurationGenerator.exe" "$(Configuration)" "$(OutDir)applicationConfiguration.config"
  </PostBuildEvent>
</PropertyGroup>

【讨论】:

  • 我不确定您要在这里解释什么。你能告诉我在哪里有这个配置吗
  • 如果您打开 .csproj 文件,这是存储 PostBuildEvents 的 XML 格式。
  • 好的,我试试
  • @MichaelNormand 查看构建窗口的输出,正如 Hans Passant 指出的那样。它将显示传递给您的 exe 的完整命令。
  • 我明白了!非常感谢大家!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-06
  • 2012-05-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-26
相关资源
最近更新 更多