views:

58

answers:

1

Let me start by example... I have an all.proj that looks similar to this:

<ItemGroup>
  <ProjectsToBuild Include="..\Sites\*\*.csproj" />
</ItemGroup>

<Target Name="DeployWebsites" DependsOnTargets="BuildMergedSolutions">
  <AspNetCompiler 
    PhysicalPath="%(ProjectsToBuild.RootDir)%(ProjectsToBuild.Directory)"
    TargetPath="%(ProjectsToBuild.RootDir)%(ProjectsToBuild.Directory)..\..\..\deploy\%(ProjectsToBuild.Filename)"
    VirtualPath="/%(ProjectsToBuild.Filename)%(ProjectsToBuild.Extension)"
    Debug="true"
    Updateable="true"
    Force="true" />
</Target>

If one of the tasks fails it will exit the target. Is there any way to just print the error and continue exceuting the remaining tasks?

ContinueOnError is not an option since it will just convert the errors to warnings. I want the build to fail in the end but I also want to get as much error information as I can get so I still need to compile all the sites even though some of them fail.

+2  A: 

The only way you can do this is if you can detect when an error has occurred. Basically the task will have to write out some artifact, or present you an output parameter where you can tell if it failed or not. You would use that along with setting ContinueOnError to true for the task itself. The idea is, set ContinueOnError to true, allow all the task invocations to complete then after that look to see if there was an error and act accordingly.

I did something similar for executing unit tests from MSBuild. I wanted all the unit tests to execute in all test assemblies, but also wanted to fail the build after they were done. So what I did was set ContinueOnError to true, then searched the XML file that the results were written to for any failed test cases, also I aggregated the messages from that file.

In your case the AspNetCompiler task doesn't write out any such file. The AspNetCompiler is wrapping up the aspnet_compiler.exe utility by extending ToolTask (via ToolTaskExtension) so you could keep track of the ExitCode. It is kind of tricky without writing you own task extending that task. If you use Target Batching you could invoke the AspNetCompiler task and then write each ExitCode into a file. Then after that look through that file for and non-zero exit code. You may want to consider writing your own custom task which extends the AspNetCompiler task, should be pretty simple to write.

For more info on batching see the resources at http://sedotech.com/Resources#Batching.

Sayed Ibrahim Hashimi
Yeah, thats what I thought. Do you know if Nant is better in this area?
JohannesH
Sorry I don't know much about Nant.
Sayed Ibrahim Hashimi
I ended up writing my own task that calls the AspNetCompiler task internaly.
JohannesH