TFS NuGet tricks that I don't already know about?

Topics: General
Aug 7, 2012 at 11:43 PM
Edited Aug 8, 2012 at 12:46 AM

So, I've enabled package restore on my solutions

 - Install-Package NuGetEnablePackageRestore

I've installed and updated NuGet on the TFS Build Server

I've created the environment variable on the TFS Build Server


I've deleted all of my packages.config files and started over again on every project.

I've added the .nuget folder path to the build job, along with a defined Build Agent Folder

I keep getting:

C:\Builds\10.......nuget\nuget.targets (76): 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'.


C:\Builds\10.......nuget\nuget.targets (76): The command ""C:\Builds\10.......nuget\nuget.exe" install "C:\Builds\10......\packages.config" -source "" -o "C:\Builds\10......\packages"" exited with code -1.

Removed full path for security.

I've almost finished my noose and plan on hanging myself at there something I'm missing?


Aug 8, 2012 at 5:01 PM

Right click your solution and click on Enable Package Restore. Additionally you'll need to grant NuGet permission to restore packages on a per machine basis by using the environment variable.

Aug 9, 2012 at 4:57 PM

I added the environment variable on the build server. Additionally, I've set each of my solutions to "Enable Package Restore" on my local DEV box. I can't imagine that you would have to open the solutions on the TFS build server and re-set the "Enable Package Restore" option?

Any other ideas?

Aug 9, 2012 at 5:10 PM
Might be a bug. Check one of your project files (csproj/vbproj) in notepad to see if they are importing the nuget.targets file (it will be at the bottom). I noticed this was not happening for me yesterday.
Aug 9, 2012 at 5:40 PM

Breakthrough! My TFS administrator set up the environment variable as a USER variable! I just figured I would ask her to show me exactly how she configured it and as soon as she did, I realized it was wrong.

I am no longer getting the Package restore error...wooo! I am however getting "Unable to find version" errors, which makes me think that the TFS box doesn't know of the proper package sources. I've verified that the package source is accessible from the TFS build box, also I've configured NuGet on that box to have reference to the package shares.

Is it possible to do this without a package server? I have been using file shares for all of my local builds, but I'm wondering if the rules change when it hits the TFS box. Do I need to define my package sources in the Nuget.config file?

Aug 9, 2012 at 7:36 PM

Good thought feventcoder! I see <Import Project="$(SolutionDir)\.nuget\nuget.targets" /> toward the end of all my csproj files. Does this need to be inside of the <Target Name="BeforeBuild"> node?

I have Resharper installed locally...could that affect it in any way?


Aug 9, 2012 at 7:41 PM

Here is the TFS Build log for the first set of RestorePackages errors.

"C:\Builds\11\Echo\RevereContent - DEV\Sources\RevereProjects\Lantern\Dev\.nuget\nuget.exe" install "C:\Builds\11\Echo\RevereContent - DEV\Sources\RevereProjects\RevereContent\Dev\RevereContent.Business\packages.config" -source "" -o "C:\Builds\11\Echo\RevereContent - DEV\Sources\RevereProjects\Lantern\Dev\packages"C:\Builds\11\Echo\RevereContent - DEV\Sources\RevereProjects\Lantern\Dev\.nuget\nuget.targets(76,9): error : Unable to find version '' of package 'Corp.Caching'. [C:\Builds\11\Echo\RevereContent - DEV\Sources\RevereProjects\RevereContent\Dev\RevereContent.Business\RevereContent.Business.csproj]C:\Builds\11\Echo\RevereContent - DEV\Sources\RevereProjects\Lantern\Dev\.nuget\nuget.targets(76,9): error : Unable to find version '' of package 'Corp'. [C:\Builds\11\Echo\RevereContent - DEV\Sources\RevereProjects\RevereContent\Dev\RevereContent.Business\RevereContent.Business.csproj]C:\Builds\11\Echo\RevereContent - DEV\Sources\RevereProjects\Lantern\Dev\.nuget\nuget.targets(76,9): error MSB3073: The command ""C:\Builds\11\Echo\RevereContent - DEV\Sources\RevereProjects\Lantern\Dev\.nuget\nuget.exe" install "C:\Builds\11\Echo\RevereContent - DEV\Sources\RevereProjects\RevereContent\Dev\RevereContent.Business\packages.config" -source "" -o "C:\Builds\11\Echo\RevereContent - DEV\Sources\RevereProjects\Lantern\Dev\packages"" exited with code -1. [C:\Builds\11\Echo\RevereContent - DEV\Sources\RevereProjects\RevereContent\Dev\RevereContent.Business\RevereContent.Business.csproj]

Do I need to configure a source inside of each of my project's packages.config? I was under the impression that adding the potential sources to the build server's %APPDATA%\NuGet\NuGet.Config file was sufficient.

Thanks again!!

Aug 9, 2012 at 7:46 PM

Does the CI machine's %AppData% have that config file? This is a per-user config, so it has to be the same account the CI process is running in. That said, you could specify these sources inside the NuGet.targets file (look for the PackageSource itemgroup that's commented out).

Aug 9, 2012 at 8:49 PM

Yes, the CI machine has the correct NuGet.Config which contains the sources I wanted. I added the packages to the targets file and found stuff! Now the only problem seems to be that when it adds one of our .dll files it sets "Embed Interop Types" to True. This is a problem we have with a .dll file compiled to support frameworks less than 4.0. I think I might be able to fix it by forcing the package to contain builds for 2.x and 4.x. 

Hopefully that will be the trick.

Thanks for all of the help!!

May 24, 2013 at 1:31 PM
Hi Aniraf, i am having the same problem .nuget\nuget.targets(57,5): error : Unable to find version '2.1.505.0' of package. Could you please explain what would you do to resolve this. I have correct target file and NuGet.Config file in the MSBuild user AppData folder.

Thanks in advance!
May 24, 2013 at 1:48 PM
Hello Aniraf... Thanks for your post but still I am having trouble in finding version 2.1.505.0 Please send a reply on whats could be the best way to do it?? I tried so many times using the instructions of the previous posts but nothing is OK.

slow cooker pulled pork
May 24, 2013 at 9:38 PM
If I remember correctly, the fix was simply making sure that the environment variable "EnableNuGetPackageRestore" was properly set as a machine level variable. Beyond that, I followed this article

We also had a problem where we were using a local network share to host the nuget packages, and the build machine didn't have access to them.

As far as the issue with the Embed Interop Types...we actually rebuilt that package so that the DLL no longer had the old COM code which forced .net 4+ to include that feature. I'm not certain that there is a way to flag it during the build process.

Hopefully one of those things answers your question.