MSBuild force compile failure on missing project files

与世无争的帅哥 提交于 2019-12-12 12:16:53

问题


As a developer, I want my compiler (MSBuild in Visual Studio in this case) to fail badly whenever it contains a file in any csproj project that is missing on disk. This idea sprung out at me after witnessing an accidental deletion of a web.config from a web site. MSBuild happily compiles without it (and would do so in continuous integration as well, since that just runs MSBuild too).

Is there a way to force MSBuild to check that all files referenced in all of a solution's projects are present before making a build succeed? Enabling Warnings as Errors doesn't seem to do it. In fact, viewing the output, I didn't see any notice that a file was missing. I know it flags missing files for project files marked "Compile", but what about content-only ones?


回答1:


It indeed appears that if a Content item is set as "Do not copy" then it will not cause an error or even a warning in MSBuild. However, if you set it to either "Copy if newer" or change the type to "Resource" (still leaving it on "Do not copy") then it will trigger an error. I was able to make a random .bak file a "Resource" with no adverse effect on my build that I could tell.



来源:https://stackoverflow.com/questions/28160294/msbuild-force-compile-failure-on-missing-project-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!