Thursday, December 16, 2010

Build a BizTalk 2009 solution with MSBuild 4.0

I’ve been working on a MSBuild 4.0 script to build our entire product tree. The product tree contains multiple solutions in .NET 3.5, Silverlight 3.0, .NET 4.0 and BizTalk 2009. Most of it wasn’t that hard, the real exception was to let MSBuild build the BizTalk 2009 solutions.

When you build a BizTalk 2009 solution with MSBuild 4.0 you’ll probably get all sorts of messages telling you that MSBuild found 2 versions of System.XML, System.Diagnostics. One version is the correct .NET 2.0 version and the other is the .NET 4.0 version. Why MSBuild doesn’t understand that a .NET 3.5 solution won’t reference a .NET 4.0 assembly is beyond me. The worst part is: There is no way to tell MSBuild which specific assembly you want to reference.

There is a solution only you’ll need to edit your BizTalk project. In the Program Files\MSBuild\Microsoft\BizTalk directory there are two MSBuild target files (BizTalkC.targets and BizTalkCommon.targets). The BizTalk.Common.targets file contains a task AddHiddenReferences. This task will avoid the BizTalk task adding the 4.0 references on hosts with both .NET 3.5 and .NET 4.0 installed.

If you unload your *.btproj files that have a reference to Microsoft.XLANGs.BaseTypes and open it with the XML Editor. Edit your btproj files so they will look something like this:

<!-- other *.btsproj file stuff -->
<Reference Include="Microsoft.XLANGs.BaseTypes">
<Name>Microsoft.XLANGs.BaseTypes</Name>
</Reference>
<Reference Include="Microsoft.BizTalk.Interop.Agent" />
<Reference Include="Microsoft.BizTalk.Pipeline" />
<Reference Include="Microsoft.BizTalk.Messaging" />
<Reference Include="Microsoft.XLANGS.BizTalk.ProcessInterface" />
<Reference Include="Microsoft.RuleEngine" />
<Reference Include="Microsoft.XLANGs.RuntimeTypes" />
<Reference Include="Microsoft.XLANGs.Engine" />
<Reference Include="Microsoft.XLANGs.BizTalk.Engine" />
</ItemGroup>
<!-- other *.btsproj file stuff -->

<!-- AddHiddenReferences will avoid adding the .NET 4.0 references -->
<Target Name="AddHiddenReferences" />
</Project>

Reload your project file and build the solution. You will notice that you will have to add a reference to System.Web.Services. After this your solution will build and this solution will also build in MSBuild 4.0.

No comments:

Post a Comment