How to stop MSBuild execution without raising error?

With MSBuild, as soon as an error occurs, project execution stops if ContinueOnError=true .

Is there a way to stop a project without raising an error?

I would like to have this opportunity because I have an existing msbuild project file set, and in some cases I will need to stop processing projects without raising an error, because this is a normal exit point for the process, and I don’t want the person using a script, I thought something was wrong.

I know that I can just set some property and set all other tasks on it, but I would like to avoid it.

+6
msbuild
source share
3 answers

As you explain, you want to stop your assembly in special circumstances without raising an error because this is a normal exit point. Why not create a goal without doing anything that will serve as your exit point. In your special circumstances, you will call this goal.

 <target Name="BuildProcess"> <Message Text="Build starts"/> ... <CallTarget Targets="Exit" Condition="Special Condition"/> <CallTarget Targets="Continue" Condition="!(Special Condition)"/> ... </target> <target Name="Continue"> <Message Text="Build continue"/> </target> <target Name="Exit"> <!-- This target could be removed --> <!-- Only used for logging here --> <Message Text="Build ended because special condition occured"/> </target> 
+7
source share

The way to do this is to create another goal to wrap the goal you are interested in conditioning.

So, if you have a script with this type:

 <Target Name="MainTarget"> command - run under a certain condition command - run under a certain condition command - run under a certain condition command - run under a certain condition command - run under a certain condition </Target> 

The thing is, you want to keep the need to use the condition statement a whole bunch of times, right?

To solve this problem you can do this:

 <Target Name="MainWrapper" DependsOnTargets="EstablishCondition;MainTarget" /> <Target Name="EstablishCondition"> <SomeCustomTask Input="blah"> <Output PropertyName="TestProperty" TaskParameter="value" /> </SomeCustomTask> </Target> <Target Name="MainTarget" Condition="$(TestProperty)='true'"> command command command command command </Target> 
+2
source share

In the end, he found an elegant solution to a similar problem. I just needed to rephrase my concern about “doing MSBuild interrupt / interrupt” to “Skip the following targets.”

 <PropertyGroup> <LastInfoFileName>LastInfo.xml</LastInfoFileName> <NewInfoFileName>NewInfo.xml</NewInfoFileName> </PropertyGroup> <Target Name="CheckSomethingFirst" BeforeTargets="DoSomething"> <Message Condition="ConditionForContinue" Text="Let carry on with next target" /> <WriteLinesToFile Condition="ConditionForContinue" File="$(NewInfoFileName)" Lines="@(SomeText)" Overwrite="true" /> <Message Condition="!ConditionForContinue" Text="Let discard next target" /> <Copy Condition="!ConditionForContinue" SourceFiles="$(LastInfoFileName)" DestinationFiles="$(NewInfoFileName)" /> </Target> <Target Name="DoSomething" Inputs="$(NewInfoFileName)" Outputs="$(LastInfoFileName)"> <Message Text="DoSomethingMore" /> <Copy SourceFiles="$(NewInfoFileName)" DestinationFiles="$(LastInfoFileName)" /> </Target> 

This works fine with the command:

 msbuild.exe Do.targets /t:DoSomething 

where the target DoSomething I / Os are correctly verified after CheckSomethingFirst is executed.

0
source share

All Articles