jamespconnor
jamespconnor

Reputation: 1412

VS2010 async CTP and VS2012 async targetting pack in the same solution

I've come up against an issue here when wanting to use the async CTP keywords. All developer machines are VS2010 and therefore require the async CTP to be installed - this has been done and code has been written using these features. However, when I came to commit this code, I realised that our build server had VS2012 installed (and hence .NET 4.5) as another team requires C++11 features and share this resource.

This means that the continuous build server fails our C# builds since they are now targeting .NET 4.0 (we still have WinXP user machines) with async methods plus the CTP method of enabling these new keywords. By installing the async targetting pack into these projects, I get other compilation errors (Same class defined twice, once in CTP and once in the async targetting pack).

Is there anyway to have both of these methods play nicely together? Obviously we fully intend to either get all developers working on VS2012 shortly - not to mention get our users up and running with .NET 4.5 but this is beyond the scope of the question.

I have a solution which I've answered below but would appreciate any feedback.

Upvotes: 1

Views: 646

Answers (2)

Martin Suchan
Martin Suchan

Reputation: 10620

I would rather recommend updating dev machines to VS2012 than building against two really different libraries - AsyncCTP and Async Targeting Pack. These are not simply interchangeable, they are implemented differently and it could happen, that your code will work with AsyncCTP and not in ATP.

Updating your projects to .NET 4.5 with native async/await support could be the best solution here.

Upvotes: 1

jamespconnor
jamespconnor

Reputation: 1412

My solution to the above issue is to use Conditional References in all my "async enabled" .csproj files:

<Reference Include="AsyncCtpLibrary" 
  Condition="'$(BuiltOnNet45)'==''">
  <HintPath>..\..\lib\AsyncCtpLibrary.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CompilerServices.AsyncTargetingPack.Net4" Condition="'$(BuiltOnNet45)'=='true'">
  <HintPath>..\..\lib\Microsoft.CompilerServices.AsyncTargetingPack.Net4.dll</HintPath>
</Reference>

I then use the msbuild.exe flag "/p:BuiltOnNet45=true" when I build using our VS2012 build machine - and leave it off when using our dev machines. Since blank is the default value, this solution allows us to load and use the solutions in VS2010 without issue. I would have to tweak this if I were to use VS2012 IDE as well but I don't require this.

Upvotes: 0

Related Questions