MSBuild在缺少的项目文件上强制编译失败 [英] MSBuild force compile failure on missing project files

查看:66
本文介绍了MSBuild在缺少的项目文件上强制编译失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为一名开发人员,我希望我的编译器(在这种情况下为Visual Studio中的MSBuild)在任何磁盘上缺少的csproj项目中包含文件时都会严重失败.在目睹从网站意外删除web.config之后,这个主意突然出现.没有它,MSBuild会很高兴地进行编译(并且也将以连续集成的方式进行,因为它也可以运行MSBuild).

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).

是否有一种方法可以强制MSBuild在成功完成构建之前检查解决方案的所有项目中引用的所有文件是否存在?启用警告为错误似乎并没有做到这一点.实际上,在查看输出时,我没有发现文件丢失的任何通知.我知道它会为标记为编译"的项目文件标记丢失的文件,但是仅内容文件呢?

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?

推荐答案

实际上,如果将Content项目设置为请勿复制",则它不会在MSBuild中引起错误甚至警告.但是,如果将其设置为如果更新则复制"或将类型更改为资源"(仍将其保留在请勿复制"上),则将触发错误.我能够将一个随机的.bak文件作为资源",并且不会对我的构建产生不利影响.

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.

这篇关于MSBuild在缺少的项目文件上强制编译失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆