Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fail an MSBuild when content files are missing

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?

like image 383
ilivewithian Avatar asked Jun 22 '09 15:06

ilivewithian


2 Answers

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

like image 166
Sayed Ibrahim Hashimi Avatar answered Oct 20 '22 11:10

Sayed Ibrahim Hashimi


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.

like image 24
Jay Sharma Avatar answered Oct 20 '22 13:10

Jay Sharma