8

We are using VSO with an on-prem build controller (TFS 2013). I've enabled NuGet package restore in the Options menu of Visual Studio (migrated away from the old, deprecated way with the .nuget folder).

Inside VS, restoring packages works just fine, however the build controller does not restore NuGet packages. The build controller runs under a service account and if I start VS (on the build server) as the service account and build my code it DOES restore the packages. How can I get the build controller to restore the missing packages?

In my BuildProcessTemplate folder of TFS, I DO NOT have a TfvcTemplate.12.xaml, I only have DefaultTemplate.11.1.xaml and as I've never edited the xaml file, I see that there is a Toolbox item for NuGetRestore

I'm unsure as to how to proceed, I'm kind of wondering why I don't have the TfvcTemplate.12.xaml template, but since I don't, how can I get my build server/controller to restore NuGet packages?

I have edited the NuGet.config file for the service account (that lives in the AppData folder) as well as the NuGet.config file that lives in the .nuget folder in the root of my solution, however my builds always fail because of missing dependencies (NuGet packages).

Is there any way to solve this issue? Also, how can I get a TfvcTemplate.12.xaml build template?

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
djm61
  • 464
  • 1
  • 8
  • 23

2 Answers2

8

To enable restore NuGet package with TFS build, please follow steps below. Check this blog for the details.

  1. In VS IDE, go to Tools -> Options -> NuGet Package Manager -> enable Allow NuGet to download missing packages.
  2. Delete NuGet.exe and NuGet.targets files from .nuget folder. Be these two files are deleted from version control as well.
  3. Remove the following tags from .proj file:

    1. <RestorePackages>true</RestorePackages>

    2.<Import Project="$(SolutionDir)\.nuget\nuget.targets" />  

    3. <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">  
        <PropertyGroup>
            <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, 
    see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
        </PropertyGroup>
        <Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
    </Target>

For your another issue about can't find the TfvcTemplate.12.xaml process template, you can first create a new team project in VSO, download the process file and check it in to Version Control. Then edit the build definition, click the New button on the Process tab, browse the process file in the version control.

Vicky - MSFT
  • 4,970
  • 1
  • 14
  • 22
  • I read a similar blog post that walked me through removing the nuget .targets and .exe file and editing the proj files, however it did not mention removing the true. I have since done that and done another build which failed - same issue as I originally stated - no NuGet packages are restoring. – djm61 Aug 20 '15 at 15:19
  • Build templates no longer get added to Source Control. If you hit the drop Dow for selecting the template in Visual Studio's build edit menu then you can select the new templates. – MrHinsh - Martin Hinshelwood Aug 20 '15 at 19:26
  • Thanks @MrHinsh, I found where to change the dropdown and it appears to have solved my issue. [This](https://github.com/owen2/AutomaticPackageRestoreMigrationScript) also helped. – djm61 Aug 20 '15 at 20:50
  • I'm running into the same issue. I am using the AzureContinuousDeployment.11.xaml template though. Do you know if this has nuget package restore task inside it? I'm searching through the xaml files and can't find anything related to nuget. – TWilly Nov 04 '15 at 22:14
  • 1
    @TWilly Nuget Restore was added to the 2013 (v12) templates. You can edit the 2012 templates and drag in the NugetRestore. I added the NuGetRestore step before the MsBuild step that does the actual build (not the clean). Only property i added was to pass the variable {localProject} to the Solutions property. This was the same variable that was passed into the MsBuild Project variable. – felickz Feb 23 '16 at 04:26
  • More official link than the geek blog :D http://docs.nuget.org/consume/package-restore/migrating-to-automatic-package-restore – felickz Feb 23 '16 at 04:28
  • I still cannot get this working with Microsoft's hosted TFS. I changed to my own build server running TFS and it just works... so annoying. – The Muffin Man Apr 26 '16 at 20:05
1

For anyone who stumbles here with the issue I had (some but not all packages being restored on a build server), the final piece of the puzzle for me was adding a NuGet.config in the root of my solution, sibling to the .SLN file as David Ebbo explained here: http://blog.davidebbo.com/2014/01/the-right-way-to-restore-nuget-packages.html.

From Ebbo's blog post, the file contents for me are simply

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://www.nuget.org/api/v2/" />
  </packageSources>
</configuration>

Sadly, I don't understand why that changed things for me. But it's working now and I'm moving on!

UPDATE:

The NuGet API URL has changed for v3 (current as of Sept 2016). From https://www.nuget.org/

<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
madannes
  • 523
  • 1
  • 8
  • 14