This project is read-only.

Race conditions with Tasks

May 3, 2013 at 9:24 AM
Maybe someone can help me out with some ideas, please?

All my csprojs import a common build file which hangs targets off Pre and PostBuild targets which do various stuff... including setting up IIS artifacts and updating the VistualStudio project extensions IISUrl accordingly. This means that hitting F5 sets up side by side local dev environments for different branches.

I use the MSBuild.ExtensionPack.Web namespace.
  <!-- Import the common build framework -->
  <Import Project="$(MSBuildProjectDirectory)\..\_Build\CommonBuild.proj" />
  <!-- Specify the site details and CommonBuild.proj will create it -->
This works just tickety boo in VS (with parallelism turned off as it is my default)

However, running MSBuild Solution1.sln /p:BuildInParallel=true can result in more than one MSBuild.ExtensionPack.Web task firing at the same time which then throws as follows:

MSBuild.ExtensionPack.Web: FileLoadException: Filename: \?\C:\WINDOWS\system32\inetsrv\config\applicationHost.config\r [C:\NeilTest\Branch4\Solution1\MvcApplication5\MvcApplication5.csproj]
Error: Cannot commit configuration changes because the file has changed on disk\r [C:\NeilTest\Branch4\Solution1\MvcApplication5\MvcApplication5.csproj]

I suppose I could amend the solution build order - but this kinda breaks the 'each project should be self-describing and autonomous' result I was after.

Is there a way I can mark certain tasks or targets as not runnable in parallel?

Or... do I need to amend the MSBuild.ExtensionPack.Web code to mutex?

Any help much appreciated.

Thank you

May 9, 2013 at 1:12 PM
Mutex is probably the solution. Feel free to send a patch or raise an issue and I'll look at getting it fixed. What you describe could be a wider issue though.

May 9, 2013 at 2:23 PM
Hi Mike

thanks very much for getting back to me. I won't submit a patch - as my 'fix' is quick and filthy; as I don't really have much clue where to begin and as I am mutex-ing irrespective of target machine (see below).

It is something that I've been pretty sure I'd hit now that MSBuild is more and more ||. Luckily for me you have made the source of these tasks available, so thank you for that. If you do create a task for this, please let me know - I am intrigued to know how it could get fixed.


I slung this in BaseTask

protected static Mutex IisMutex = new Mutex(false, IisMutexName);
protected const string IisMutexName = "Iis-IisMutex";
protected const int IisMutexTimeout = 5000;

And the InternalExecute() methods of Iis7Application; Iis7AppPool; Iis7Binding; Iis7Website now have:

Marked as answer by mikeFourie on 10/9/2013 at 3:28 PM