简体   繁体   English

MS Visual Studio 子项目编译预建事件 IF 条件错误

[英]MS Visual Studio subproject compilation prebuilt events IF condition error

My solution has two projects: c++ dll and c# web.我的解决方案有两个项目:c++ dll 和 c# web。 Dll project has pre-built event like this Dll 项目有这样的预建事件

IF 2 == 1
(
   echo ERROR: Dll building error
)

And, obviously, this condition not interrupts building process and it finishes with success, if I run it for dll project.而且,显然,如果我为 dll 项目运行它,这种情况不会中断构建过程并且它会成功完成。

But.. the Web project depends on the dll and therefore uilds it, in turn, by MSBUILD.exe command in it own pre-build event.但是.. Web 项目依赖于 dll,因此反过来,通过 MSBUILD.exe 命令在它自己的预构建事件中使用它。 That is, as a result, pre-build parent (MSBUILD for web) following by nested pre-build childs (IF for dll).也就是说,作为结果,预构建父级(用于 Web 的 MSBUILD)跟随嵌套的预构建子级(IF 用于 dll)。 . . And if I try to build web project, it interrupts with message Dll building error (from the dll project pre-built event) after child dll project by MSBUILD.exe (in web pre-built event) has built with success!!!如果我尝试构建 Web 项目,它会在 MSBUILD.exe 的子 dll 项目(在 Web 预构建事件中)成功构建后,以消息Dll 构建错误(来自 dll 项目预构建事件)中断!!! - result dll file has appeared in output dir!. - 结果 dll 文件已出现在输出目录中!

What it's means?这是什么意思? Child pre-build event conditions incorrectly interrupts parent build process?子预构建事件条件错误地中断了父构建过程?

The problem appears to be that you're misusing MSBuild.问题似乎是您滥用 MSBuild。 The proper way to handle "subprojects" is to use a Solution.处理“子项目”的正确方法是使用解决方案。 In this solution, you have both projects, and a project dependency from the web project on the DLL.在此解决方案中,您拥有两个项目,以及来自 Web 项目对 DLL 的项目依赖项。 You build the solution, and that's one MSBuild command.您构建解决方案,这是一个 MSBuild 命令。 Therefore, the C# web project does not need to start another MSBuild command.因此,C# web 项目不需要启动另一个 MSBuild 命令。

MSBuild, when using a solution file, sees the real dependencies and handles build failures correctly. MSBuild 在使用解决方案文件时,会看到真正的依赖项并正确处理构建失败。 Note that a "echo ERROR" in a pre-build event is just text on a screen, not a build failure.请注意,预构建事件中的“回显错误”只是屏幕上的文本,而不是构建失败。 You'll need to exit /b 1 the pre-build step to stop the build 您需要exit /b 1预构建步骤以停止构建

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM