简体   繁体   English

TFS无法恢复NuGet包

[英]TFS Can't Restore NuGet Package

I've got TFS doing some continuous integration builds. 我有TFS做一些持续的集成构建。 Today, it broke for one solution. 今天,它打破了一个解决方案。 It seems it can't find AutoMapper. 似乎找不到AutoMapper。 All the other packages can be found just fine. 所有其他包装都可以找到。

A couple relevant points: 几个相关点:

  • None of the packages are in source control, we're letting TFS restore them. 没有任何软件包在源代码管理中,我们让TFS恢复它们。
  • We have an internal NuGet feed, but it doesn't seem to be a problem in other solutions, and in this solution we are still getting Entity Framework to restore - just not AutoMapper. 我们有一个内部NuGet提要,但它似乎不是其他解决方案中的问题,在这个解决方案中我们仍然得到实体框架来恢复 - 只是不是AutoMapper。
  • I tried removing and re-adding the NuGet Packages. 我尝试删除并重新添加NuGet包。 No luck. 没运气。
  • If I use Remote Desktop to connect to the build server and open the project in Visual Studio there, it restores the packages and builds fine. 如果我使用远程桌面连接到构建服务器并在Visual Studio中打开项目,它将恢复包并构建正常。
  • I can build manually by executing D:\\"Program Files"\\"Microsoft Team Foundation Server 12.0"\\Tools\\Nuget.exe restore followed by msbuild MySolutoin.sln 我可以通过执行D:\\"Program Files"\\"Microsoft Team Foundation Server 12.0"\\Tools\\Nuget.exe restore然后执行msbuild MySolutoin.sln
  • Our TFS server is installed on our D:\\ drive. 我们的TFS服务器安装在我们的D:\\驱动器上。

This is from the TFS Logs: 这来自TFS日志:

D:\Program Files\Microsoft Team Foundation Server 12.0\Tools\nuget.exe restore "C:\Builds\1\MyCompany Web\FclQuoteWcfService\src\FclQuoteWcfService.sln" -NonInteractive
Installing 'EntityFramework 6.1.3'.
Installing 'InternalPackage 1.0'.
Successfully installed 'InternalPackage 1.0'.
Successfully installed 'EntityFramework 6.1.3'.
Unable to find version '3.3.1' of package 'AutoMapper'.
C:\Program Files (x86)\MSBuild\12.0\bin\amd64\MSBuild.exe /nologo /noconsolelogger "C:\Builds\1\MyCompany Web\FclQuoteWcfService\src\FclQuoteWcfService.sln" /nr:False /fl /flp:"logfile=C:\Builds\1\MyCompany Web\FclQuoteWcfService\src\FclQuoteWcfService.log;encoding=Unicode;verbosity=normal" /p:SkipInvalidConfigurations=true /m /p:OutDir="C:\Builds\1\MyCompany Web\FclQuoteWcfService\bin\\" /p:VCBuildOverride="C:\Builds\1\MyCompany Web\FclQuoteWcfService\src\FclQuoteWcfService.sln.vsprops" /dl:WorkflowCentralLogger,"D:\Program Files\Microsoft Team Foundation Server 12.0\Tools\Microsoft.TeamFoundation.Build.Server.Logger.dll";"Verbosity=Normal;BuildUri=vstfs:///Build/Build/230;IgnoreDuplicateProjects=False;InformationNodeId=12;TargetsNotLogged=GetNativeManifest,GetCopyToOutputDirectoryItems,GetTargetPath;TFSUrl=http://ctidev2k8:8080/tfs/MyCompany;"*WorkflowForwardingLogger,"D:\Program Files\Microsoft Team Foundation Server 12.0\Tools\Microsoft.TeamFoundation.Build.Server.Logger.dll";"Verbosity=Normal;" /p:BuildId="9aa9f8af-c9b9-4d0a-ba06-7cc959231d8e,vstfs:///Build/Build/230" /p:BuildLabel="FclQuoteWcfService_20150330.2" /p:BuildTimestamp="Mon, 30 Mar 2015 20:40:07 GMT" /p:BuildSourceVersion="LFclQuoteWcfService_20150330.2@$/MyCompany Web" /p:BuildDefinition="FclQuoteWcfService"
 Exception Message: MSBuild error 1 has ended this build. You can find more specific information about the cause of this error in above messages. (type BuildProcessTerminateException) Exception Stack Trace: at System.Activities.Statements.Throw.Execute(CodeActivityContext context) at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

I've seen this too. 我也见过这个。 It seems to be triggered as soon as NuGet package restore switches to the internal feed. 一旦NuGet包恢复切换到内部源,它似乎就会被触发。 Once it does this is doesn't switch back to the official nuget.org feed and continues to look for the packages on the internal feed. 一旦这样做,这不会切换回官方nuget.org提要并继续寻找内部提要上的包。

Ensure both package sources are added to your NuGet.config file. 确保将两个包源添加到NuGet.config文件中。 Also ensure both sources are 'active'. 同时确保两个来源都“有效”。

<configuration>
    <packageSources>
        <add key="nuget.org"
             value="https://www.nuget.org/api/v2/" />
        <add key="example.com"
             value="http://example.com/feed/nuget/" />
    </packageSources>
    <activePackageSource>
        <add key="All"
             value="(Aggregate source)" />
    </activePackageSource>
</configuration>

See NuGet configuration file documentation. 请参阅NuGet配置文件文档。

Matt's answer put me on the right track but we don't use an internal feed so I had to do some more digging. Matt的回答让我走上正轨,但我们不使用内部饲料,所以我不得不做更多的挖掘。 This answer works, at least, for a project created in Visual Studio 2015 and built by TFS 2015 . 这个答案至少适用于在Visual Studio 2015中创建并由TFS 2015构建的项目。

In Visual Studio, open the NuGet package manager settings (Tools menu > NuGet Package Manager > Package Manager Settings). 在Visual Studio中,打开NuGet包管理器设置(“工具”菜单>“NuGet包管理器”>“包管理器设置”)。 Choose "Package Sources" from the options list on the left. 从左侧的选项列表中选择“包源”。

NuGet包源选项窗口的屏幕截图

Create the nuget.config file at the root of the solution. 在解决方案的根目录下创建nuget.config文件。 This should be the same folder location as your ".sln" solution file. 这应该与“.sln”解决方案文件的文件夹位置相同。 Copy the following into the config file: 将以下内容复制到配置文件中:

<configuration>
    <packageSources>

    </packageSources>
    <activePackageSource>
        <add key="All"
             value="(Aggregate source)" />
    </activePackageSource>
</configuration>

Within the <packageSources> tag, create an <add key="" value="" /> entry for each source listed in the "Package Sources" options window. <packageSources>标记内,为“Package Sources”选项窗口中列出的每个源创建一个<add key="" value="" />条目。 The key is the name of the source as shown above the URL, and the value is the URL itself. 键是URL上方显示的源名称,值是URL本身。 Include those listed in both "Available package sources" and "Machine-wide package sources". 包括“可用包源”和“计算机范围包源”中列出的那些。 I did not create an entry for the local filesystem as it wasn't used in this solution. 我没有为本地文件系统创建一个条目,因为它没有在此解决方案中使用。 Based on the screenshot above, the complete config file now contains the following: 根据上面的屏幕截图,完整的配置文件现在包含以下内容:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <packageSources>
        <add key="nuget.org"
             value="https://api.nuget.org/v3/index.json" />
        <add key="Microsoft and .NET"
             value="https://www.nuget.org/api/v2/curated-feeds/microsoftdotnet/" />
    </packageSources>
    <activePackageSource>
        <add key="All"
             value="(Aggregate source)" />
    </activePackageSource>
</configuration>

After committing the nuget.config file to source control, TFS was able to download all the necessary NuGet packages and successfully build the solution. 在将nuget.config文件提交到源代码控制之后,TFS能够下载所有必需的NuGet包并成功构建解决方案。

In addition to Matt's answer, I'd like to highlight the following well-hidden stuff from the NuGet documentation: 除了Matt的回答,我还想强调一下NuGet文档中隐藏的内容:

NuGet config files are treated in the following priority order (closest to the folder nuget.exe runs from wins), for example assuming the solution directory is c:\\a\\b\\c : NuGet配置文件按以下优先级顺序处理(最接近文件夹nuget.exe从wins运行),例如假设解决方案目录为c:\\a\\b\\c

  • c:\\a\\b\\c\\.nuget\\nuget.config - This file is only used for solution level packages, and is not supported in nuget 3.0 - 3.4 c:\\a\\b\\c\\.nuget\\nuget.config - 此文件仅用于解决方案级别包,并且在nuget 3.0 - 3.4中不受支持
  • c:\\a\\b\\c\\nuget.config
  • c:\\a\\b\\nuget.config
  • c:\\a\\nuget.config
  • c:\\nuget.config
  • User specific config file, %AppData%\\NuGet\\nuget.config . 用户特定的配置文件, %AppData%\\NuGet\\nuget.config
  • Or the user specified file thru option -ConfigFile . 或者用户指定的文件通过选项-ConfigFile

This could explain some weird behaviour in specific scenario's where a restore does or does not pick up a configured feed, depending on whether youre restoring with nuget 2.x or 3.x 这可以解释特定情况下的一些奇怪的行为,其中还原是否取消已配置的Feed,具体取决于您是使用nuget 2.x还是3.x进行还原

Edit: and I found yet another reason why packages might not be detected : 编辑:我发现了可能无法检测到包的另一个原因

I have package "A" with version 1.1.1.0 . 我的软件包“A”的版本为1.1.1.0

Prior 3.4 this command works well: 在3.4之前,此命令运行良好:

nuget install A -version 1.1.1.0

With NuGet 3.4 RC I get: 使用NuGet 3.4 RC,我得到:

An error occurred while retrieving package metadata for 'A.1.1.1' from source 'N'. An error occurred while retrieving package metadata for 'A.1.1.1' from source 'N'. Data at the root level is invalid. Line 1, position 1.

... ...

The client treats 1.1, 1.1.0, 1.01.0 and 1.1.0.0 as the same version using SemVer rules. 客户端将1.1,1.1.0,1.01.0和1.1.0.0视为使用SemVer规则的相同版本。 The reason non-normalized versions were special cased in the past is because for v2 http calls the client would first send the version string exactly as the user specified it 非规范化版本在过去特殊情况下的原因是因为对于v2 http调用,客户端将首先发送完全按用户指定的版本字符串

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM