Bookmark and Share

ContinueOnError for Project Builds

by KodefuGuru 9. October 2008 14:29

I've seen a few questions in the forums where the poster wants the build to fail for certain projects but not others. This can be accomplished through metadata and item batching.

Here is the item group that defines the projects.

<ItemGroup>
    <
Projects Include="$(MSBuildProjectDirectory)\DataAccess\DataAccess.csproj">
        <
Group>Build</Group>
        <
Title>Data Access</Title>
        <
Description>Data Access Layer</Description>
        <
ContinueOnError>False</ContinueOnError>
    </
Projects>
    <
Projects Include="$(MSBuildProjectDirectory)\Business\Business.csproj">
        <
Group>Build</Group>
        <
Title>Business</Title>
        <
Description>Business Layer</Description>
        <
ContinueOnError>False</ContinueOnError>
    </
Projects>
    <
Projects Include="$(MSBuildProjectDirectory)\NonCritical\NonCritical.csproj">
        <
Group>Build</Group>
        <
Title>NonCritical</Title>
        <
Description>A Non Critical Project</Description>
        <
ContinueOnError>True</ContinueOnError>
    </
Projects>
    <
Projects Include="$(MSBuildProjectDirectory)\Presentation\Presentation.csproj">
        <
Group>Build</Group>
        <
Title>Presentation</Title>
        <
Description>Presentation Layer</Description>
        <
ContinueOnError>False</ContinueOnError>
    </
Projects>
</
ItemGroup>

Here is the call to the MSBuild task.

<MSBuild Projects="@(Projects)" ContinueOnError="%(ContinueOnError)" />

Since ContinueOnError is defined as metadata for the Projects items, you can access it in a batching scenario by using the % symbol. When assigned to the ContinueOnError attribute, it evaluates the text contained within the metadata, in this case True or False.  One side effect of this is that all of the ContinueOnError=False projects will be executed before the True projects. 

I don't like this approach, because I consider a compilation failure a failed build. However, this should help you out if you're faced with a scenario where this functionality is required.

Tags:

Kodefu

blog comments powered by Disqus

KodefuGuru.GetInfo()

Chris Eargle
LinkedIn Twitter Technorati Facebook

Chris Eargle
C# MVP, INETA Community Champion


MVP - Visual C#

 

INETA Community Champions
Friend of RedGate
Telerik .NET Ninja
Community blogs & blog posts

I am a #52er

I have joined Anti-IF Campaign


World Map

Tag cloud

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2010