2015-03-30 277 views
8

我有TFS做一些持續集成構建。今天,它打破了一個解決方案。它似乎無法找到AutoMapper。所有其他的軟件包都可以找到。TFS無法恢復NuGet包

幾個相關要點:

  • 包都不是在源頭控制,我們讓TFS恢復它們。
  • 我們有一個內部的NuGet提要,但在其他解決方案中似乎沒有問題,並且在此解決方案中,我們仍然在使用Entity Framework進行還原 - 而不是AutoMapper。
  • 我嘗試刪除並重新添加NuGet包。沒有運氣。
  • 如果我使用遠程桌面連接到構建服務器並在Visual Studio中打開該項目,那麼它將恢復軟件包並構建正常。
  • 我可以通過執行D:\"Program Files"\"Microsoft Team Foundation Server 12.0"\Tools\Nuget.exe restore然後msbuild MySolutoin.sln
  • 手動構建我們的TFS服務器安裝在我們的D:\驅動器上。

這是從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="[email protected]$/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) 
+0

您是否僅從構建服務器上的內部NuGet源恢復?或者你還允許從nuget.org恢復?如果沒有,那麼檢查包裝是否在你的內部飼料中。另外,在手動運行構建時,您可能會以不同的訪問權限不同的用戶(以及不同的nuget.config全局文件,以及不同的nuget存儲庫)運行。 – Petrik 2015-04-13 21:15:49

回答

10

我已經看到了這一點。一旦NuGet包恢復切換到內部饋送,它似乎就會被觸發。一旦這樣做,這是不會切換回官方nuget.org飼料,並繼續尋找內部飼料的包。

確保兩個軟件包源都添加到您的NuGet.config文件中。同時確保兩個來源都是「有效」的。

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

請參閱NuGet configuration file文檔。

0

除了馬特的答案,我想從的NuGet文檔突出以下以及隱藏的東西:

的NuGet配置文件在以下優先順序 處理(最接近文件夾的NuGet .EXE從勝運行),例如假設 溶液目錄是c:\a\b\c

  • c:\a\b\c\.nuget\nuget.config - 該文件僅用於溶液 水平p ackages,而不是在的NuGet 3.0支持 - 3.4
  • c:\a\b\c\nuget.config
  • c:\a\b\nuget.config
  • c:\a\nuget.config
  • c:\nuget.config
  • 用戶特定的配置文件, %AppData%\NuGet\nuget.config
  • 或用戶指定的文件通過選項 -ConfigFile

這可以解釋在特定場景中的一些奇怪的行爲,其中一個恢復或不拿起配置飼料,這取決於無論您用的NuGet 2.x或3.x的恢復

編輯:和我發現yet another reason why packages might not be detected

我有版本1.1.1.0包「A」。

此前3.4這個命令效果很好:

nuget install A -version 1.1.1.0

用的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.

...

客戶把1.1,1.1 .0,1.01.0和1.1.0.0與使用SemVer規則的相同版本 秒。原因非標準化的版本是特別 套管在過去是因爲V2 HTTP調用客戶端完全按照用戶指定那就先01​​發送版本字符串

1

馬特的回答讓我在正確的軌道上,但我們不使用內部飼料,所以我不得不做更多的挖掘。至少,這個答案適用於在Visual Studio 2015中創建的項目,並由TFS 2015構建。

在Visual Studio中,打開NuGet程序包管理器設置(工具菜單> NuGet程序包管理器>程序包管理器設置)。從左側的選項列表中選擇「套餐來源」。

Screenshot of the NuGet Packages Sources options window

在溶液的根目錄下創建的nuget.config文件。這應該與您的「.sln」解決方案文件位於相同的文件夾位置。複製下面到配置文件:內<packageSources>標籤

​​

,創建在「包源」選項窗口中列出的每個源的<add key="" value="" />條目。關鍵是URL的上面顯示的源的名稱,值是URL本身。包括「可用軟件包源」和「機器範圍軟件包源」中列出的軟件包。我沒有爲本地文件系統創建條目,因爲它沒有在此解決方案中使用。基於上面的截圖,完整的配置文件現在包含以下內容:

<?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> 

nuget.config文件的源代碼控制後,TFS能夠下載所有必要的NuGet包,併成功地構建解決方案。