Simplified usage of shared BizTalk artefacts using NuGet

Most BizTalk projects has a lot of dependencies! Since an assembly is the smallest deployable unit in BizTalk and we typically do not want to redeploy all our integrations just because we updated one map in one integration. When one artifact needs to use another artifact, it is said to be dependent on that artifact. If the artifacts are located in different assemblies, we have an assembly reference.

There is a ton of material for how to handle these dependencies when it comes to deployment but one of the big annoyances with having a lot of dependencies is just to get it to build fresh from source control.

A typical implement-fix-in-existing-project workflow could look something like this:

  1. Clone the project from the source control repository.
  2. Build
  3. < Get build errors due to missing dependencies >
  4. Clone all dependent source control repositories
  5. Build all dependent projects.
  6. Build the project that we are supposed to update (crossing fingers that we didn’t do any mistake in any of the above steps).
  7. Implement fix
  8. Commit changes.

It is not uncommon that these steps takes more time than the actual fix, especially if there is a lot of dependencies.

As most other development teams we use a build server where built, tested and versioned assemblies are stored. So why do I need to download and build code when I only need the binary?

The ideal thing would be if we can pull down the project we need to update and all dependencies would be automatically be restored against a pre-built versioned assembly from the build server.

NuGet to the rescue?

Note that BizTalk projects is not currently supported by NuGet. I have opened a pull request with support for BizTalk projects https://nuget.codeplex.com/SourceControl/network/forks/robinhultman/NuGetWithBizTalkProjectExtension/contribution/5960. This example uses my private build of NuGet.

When NuGet is mentioned people often think of public feeds for open source libraries but you could just as well use it internally with a private feed.

NuGet enabling a BizTalk project is easy. NuGet will use information from the AssemblyInfo but to add some more metadata about our artifact we can add a nuspec file. The rest is done on the build server.

We use TeamCity as build server. TeamCity has support for packing and publishing NuGet packages to both private and public feeds. TeamCity is also able to act as a NuGet feed server.

Our build process looks like this:

With the package published to our NuGet server we can simply reference it from “Manage NuGet Packages” dialog in Visual Studio:

If the NuGet Visual Studio setting “Allow NuGet to download missing packages” is enabled NuGet will, as the label indicates, download all missing packages automatically. So with this implemented the implement-fix-in-existing-project workflow will look like this:

1. Clone the project from the source control repository.
2. Build < Visual Studio automatically restores dependencies from the build server >.
3. Implement fix.
4. Commit changes.

If we investigate the MSBuild output in Visual Studio from step 2 we can see that the dependencies are downloaded from the NuGet feed.

Restoring NuGet packages… To prevent NuGet from downloading packages during build, open the Visual Studio Options dialog, click on the Package Manager node and uncheck ‘Allow NuGet to download missing packages’.
Installing ‘Demo.Shared.Schemas.EFACT_D93A_INVOIC 1.0.0.0’.
Successfully installed ‘Demo.Shared.Schemas.EFACT_D93A_INVOIC 1.0.0.0’.
Demo.CustomerInvoice.Transforms ->
C:\Projects\Demo\CustomerInvoice\Transforms\bin\Debug\Demo.CustomerInvoice.Transforms.dll

If one of our dependencies gets updated NuGet detects that and enable us to update the reference.

If you think that this could be useful please up vote my pull request on the NuGet project

https://nuget.codeplex.com/SourceControl/network/forks/robinhultman/NuGetWithBizTalkProjectExtension/contribution/5960

To read more about creating and publishing NuGet packages:

http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package

More about package restore:

http://docs.nuget.org/docs/reference/package-restore

More about nuspec files:

http://docs.nuget.org/docs/reference/nuspec-reference

Posted in: •Integration  | Tagged: •BizTalk  •NuGet  •TeamCity