One of our .NET solutions recently needed to consume an assembly produced by one of our other solutions. So the output from one solution became an input into the other solution. At first I thought I’d simply add a build step to the Team Foundation Server 2015 (TFS2015) build that simply copied the file from one solution across to the other. But this didn’t seem like a very good solution. For starters, the build would be copying a development version of the assembly which hadn’t been properly tested (although the build had executed various unit tests against it). Also, this rather basic approach didn’t allow any control over the version of the assembly that was consumed by the consuming solution.
A far better proposal was to use NuGet for this. After all, resolving dependencies in an structured manner is precisely what NuGet does. So I investigated how to achieve this. The basic process is for the donor solution to package and publish the assembly to a known location. The recipient solution then installs the assembly from this location.
So first off, I needed to add two additional build steps to the TFS2015 build process of the donor solution.
- NuGet Packager — creates the NuGet package from the specified project
- NuGet Publisher — publishes the NuGet package to the specified location (in my case I published the NuGet package to a network share)
This was the easy bit, and I got this working pretty quickly. After a few test builds I was happy that the donor build was publishing the NuGet package and versioning it to the specified location.
The second part was to add a build step to the recipient solution which would install the NuGet package from this location.
- NuGet Installer — installs the NuGet package into the location specified (the recipient solution’s package folder).
This part proved to be a bit trickier as I wasn’t sure what the correct way of doing this was. Do I create a single folder for all the NuGet packages? Or create a separate folder for each where the folder name contains the version number? I also wasn’t sure what format the NuGet installer would be expecting. So I had to try various options, including changing the NuGet restore parameters, adding a NuGet.config file and updating the packages.config file. I opted to specify the NuGet source location and package directory as NuGet arguments on the NuGet Installer build step.
My NuGet arguments look something like this.
Hide Copy Code
-verbosity detailed -source "\\network\share\nuget" -packagesdirectory "Solution\Main\packages"
After a certain amount of trial and error, and reading through the online documentation for NuGet, I eventually managed to get the assembly to install in the recipient build.
It’s definitely worth spending the time to figure out how NuGet works, as it provides a very good solution for handling assembly dependencies between your various solutions. And of course, the TFS2015 build system has excellent support for NuGet, so it works seamlessly within the Microsoft development ecosystem.