问题
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?
回答1:
To enable restore NuGet package with TFS build, please follow steps below. Check this blog for the details.
- In VS IDE, go to Tools -> Options -> NuGet Package Manager -> enable Allow NuGet to download missing packages.
- Delete NuGet.exe and NuGet.targets files from .nuget folder. Be these two files are deleted from version control as well.
- 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.
回答2:
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" />
来源:https://stackoverflow.com/questions/32101429/tfs-2013-build-controller-not-respecting-nuget-package-restore