我的 csproj 中有一个 postbuild 事件。我想忽略此命令的输出,但是每当我执行 command >nul 2>&1 时,这个 csproj 都会损坏,可能是因为“>”。我注意到当我从 postbuild 窗口写 ">"而不是直接编辑 csproj 时,如果被编码了..是否有解决方法(除了从 bat 文件运行它)

最佳答案

这可以使用来自自定义目标的 MSBuild 的 <Exec> 任务来完成,而不是依赖于默认的前/后构建脚本属性。

您可以将其添加到您的 csproj 文件中,而不是使用默认的前/后构建脚本:

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
  <Exec Command="some command" IgnoreExitCode="true" />
</Target>

请注意,对于“基于 sdk”的项目(ASP.NET Core、.NET Core、.NET Standard),上述格式是在 Visual Studio UI 中指定构建后事件时添加的格式,但 IgnoreExitCode 属性除外。

关于c# - 如何忽略构建后事件的警告和错误?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47203952/

10-17 02:05