Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include NuGet packages in TeamCity

I recently started using NuGet to manage external packages. For now I have only needed it for NLog. Everything works fine when I Build the project in VS 2012. However, I am trying out TeamCity as a CI server (I'm fairly new to CI) and it is giving me the following error:

[Csc] SomeNamespace\SomeClass.cs(10, 7): error CS0246:  The type or namespace name 'NLog' could not be found  (are you missing a using directive or an assembly reference?) 

(this error is repeated throughout where ever I use NLog)

Now I did not include the 'packages/' folder in SVN, since I thought it was good practice not to include binaries and let MSBuild in TeamCity download these on its own. However it's clearly not doing that. I DO include the 'packages.xml' file in SVN. What can I check to see what is going wrong?

Update Thanks to @DavidBrabant I was nudged in the right direction. However, I now get the following error in TeamCity:

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.' 

However I'm not in Visual Studio but TeamCity, so I do not know how to set 'consent' to true! I tried to set RestorePackages to 'true' in the NuGet.targets file:

<RestorePackages Condition="  '$(RestorePackages)' == '' ">true</RestorePackages> 

but this didn't work.

Update 2 To make it work I also set the following property NuGet.targets:

<RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'true' ">false</RequireRestoreConsent> 

This made the build run succesfully!

like image 525
HTBR Avatar asked Jan 21 '13 12:01

HTBR


2 Answers

The enable package restore feature built into NuGet allows you to very easily set up the pre-build part of the workflow. To do so, right-click the solution node in Visual Studio’s Solution Explorer, and click the Enable NuGet Package Restore option. Note that you need to have the NuGet Visual Studio Extension installed on your system. If you do, and you still don’t see this menu item appear, you either already enabled this option, or you have a folder named .nuget in your solution directory.

After having set that option, you can now delete all sub-folders of your package installation directory, by default $(SolutionDir)\packages, except for the repositories.config file, and your solution should still compile properly. During compilation, you should see NuGet installation traces in the Visual Studio output window, and you should see the required NuGet packages reappear in the package installation directory as well.

Also see Using Nuget without committing packages.

like image 111
David Brabant Avatar answered Sep 27 '22 17:09

David Brabant


Just to reiterate on update 2. If you stumbled here looking for a quick fix to TeamCity not downloading NuGet packages, try changing this line

<RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'false' ">true</RequireRestoreConsent> 

to this line

<RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'true' ">false</RequireRestoreConsent> 

in your NuGet.targets file and it should work.

like image 29
craastad Avatar answered Sep 27 '22 16:09

craastad