0

Is it possible to terminate an MSBuild process for a project (*.csproj) as a normal execution flow?

Something like

<Exit Condition="..."></Exit>

This should not raise an error. It is supposed to be a valid flow for skipping building a project under certain conditions.

The project is a Visual Studio project which means the Build target is defined in Microsoft.Common.Target file, not in the csproj.

Thanasis Ioannidis
  • 2,981
  • 1
  • 30
  • 50

2 Answers2

0

The error tag alone will terminate a script without an raising an error: Try this:

<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="Build">
    <Message Text="Before error"/>
    <Error/>
    <Message Text="After error"/>
  </Target>
</Project>
James Woolfenden
  • 6,498
  • 33
  • 53
  • Can I use this in a Visual Studio project? There is already a "Build" Target. I just want to stop building the project under certain circumstances. In your example where should I put the condition? – Thanasis Ioannidis May 07 '14 at 09:38
0

I found a workaround for this. Maybe it is not the most elegant thing to do, but it works.

I had to override the "Build" Target. The original target is defined in Microsoft.Common.Targets file. I inspected the file tho see how the "Build" target is defined and it is like this

<Target
   Name="Build"
   Condition=" '$(_InvalidConfigurationWarning)' != 'true' "
   DependsOnTargets="$(BuildDependsOn)"
   Returns="$(TargetPath)" />

So, in my project file I had to create my own "Build" target which would be identical to that one above, with the only difference that it would have additional conditional logic

In my csproj file I created this:

<Target
   Name="Build"
   Condition=" '$(_InvalidConfigurationWarning)' != 'true' And (.... more conditions here....) "
   DependsOnTargets="$(BuildDependsOn)"
   Returns="$(TargetPath)" />

This seems to work, especially when the project is built as part of a batch build of multiple projects within a solution.

Thanasis Ioannidis
  • 2,981
  • 1
  • 30
  • 50