Last week I decided to revisit my MSBuild/NuGet patterns (see 1 and 2) and see if I could make any improvements to what I had come up with before. In particular, I wanted to integrate Brad Wilson’s gist on downloading NuGet at runtime. I did that for a couple projects, including CompositionTests and it works great.
But last night, NuGet 2.0 came out and CompositionTests stopped building on my CruiseControl.NET server, along with another project I haven’t released yet. I did what I usually do when something breaks first thing in the morning: I hit “Force Build” and see what happens. But it still failed and eventually I went searching to see if there were any problems with NuGet 2.0. Sure enough I found something, but its not a bug, it’s a feature! NuGet 2.0 requires consent for package restore, because we all just know that the NSA is very interested in what packages we are using. The NuGet team has been very open about this change and gave fair warning to get ready, which I read and ignored.
Well, I can’t ignore it anymore can I?
First and most obvious is a sad red circle in CCTray:
Like I said, normally I don’t even check the log before hitting “Force Build” but I already did that dance, so lets look at the log. I formatted this to fit your screen, and pulled some paths out for brevity, but you get the idea:
<error file="...\CompositionTests\.nuget\nuget.targets" line="57" column="9" timeStamp="06/19/2012 23:36:45"> <![CDATA[ Package restore is disabled by default. To give consent, open the Visual Studio Options dialog, click on Package Manager node and check 'Allow NuGet to download missing packages during build.' You can also give consent by setting the environment variable 'EnableNuGetPackageRestore' to 'true'. ]]> </error> <error code="MSB3073" file="...\CompositionTests\.nuget\nuget.targets" line="57" column="9" timeStamp="06/19/2012 23:36:45"> <![CDATA[ The command ""...\nuget.exe" install "...\packages.config" -source "" -o "...\packages"" exited with code -1. ]]> </error>
Since we are working with a build server, checking a checkbox in package manager is not an option. In this scenario, NuGet gives us the another way to provide consent via an environment variable. Lets try that.
These steps will apply to Windows Server 2008 R2, because that’s what I’m running CC.NET on.
Set Environment Variable
- Log on to the build server and open the Control Panel
- Go to System & Security > System > Advanced System Settings
- Click “Environment Variables”
- Click “New…” under “System Variables”
- Enter “EnableNuGetPackageRestore” as the name and “true” for the value.
- Click OK > OK > OK.
Restart the CruiseControl.NET service
- Open Control Panel > System & Security > Administrative Tools > Services
- Select CruiseControl.NET and click “Restart” to restart the service.
Use “Force Build” to force a failing project to start in CC.NET.
And you’re done!