How to fail an MSBuild when content files are missing

依然范特西╮ 提交于 2019-11-27 05:45:16

问题


I've noticed that our cruise control server does not fail the build when content files are missing.

I'd like to fail the build when javascript / graphics files etc are missing. How can I go about validating the project file with the files pulled from svn?


回答1:


You can create a target to check to make sure that all Content files are physically located on disk and raise an error if this is not the case. Here is such a target

<Target Name="ValidateContentFiles">
  <Error Condition="!Exists(%(Content.FullPath))" 
         Text="Missing Content file [%(Content.FullPath)]"/>
</Target>

You can make sure that this target is executed everytime by adding it to the InitialTargets attribute on the Project element. For example

<Project InitialTargets="ValidateContentFiles"
         ToolsVersion="3.5" DefaultTargets="Build" 
         xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

Sayed Ibrahim Hashimi

My Book: Inside the Microsoft Build Engine : Using MSBuild and Team Foundation Build




回答2:


You can also add the error condition in BeforeBuild Target available in .csproj like this:

<Target Name="BeforeBuild">
<Error Condition="!Exists(%(Content.FullPath))"
Text="Missing Content file [%(Content.FullPath)]"/>
</Target>

BeforeBuild will always execute when building a project and so you do not require adding the target to InitialTargets attribute of the Project property.



来源:https://stackoverflow.com/questions/1027861/how-to-fail-an-msbuild-when-content-files-are-missing

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