2013-03-20 41 views
0

我正在尋找一個MSBuild C#api的包裝。我的構建工作正常,但由於一些奇怪的原因,我努力讓Nuget包恢復運行,即使我傳遞參數。Nuget包恢復 - 傳入參數給MsBuild c#API

我在運行作爲NETWORK SERVICE

The command ""..\.nuget\nuget.exe" install "C:\BuildTemp\application1\packages.config" -source "" -RequireConsent -o "..\packages"" exited with code 1.

服務運行這個上午我路過他們是否正確?

var pc = new ProjectCollection(); 
var buildProperties = new Dictionary<string, string> 
{ 
    {"Configuration", "Release"}, 
    {"Platform", "Any CPU"}, 
    {"OutputPath", _outputPath}, 
    {"EnableNuGetPackageRestore", "true"} 
}; 

var buildParameters = new BuildParameters(pc); 
var buildRequest = new BuildRequestData("C:\myapplication.csproj", 
             buildProperties, 
             null, 
             new[] { "Clean", "Rebuild" }, 
             null); 

更新:這似乎在某些環境中工作,而不是其他人。爲什麼會這樣?

+0

除了那個錯誤代碼之外,從nuget.exe的MSBuild輸出中是否有錯誤消息? – 2013-03-26 23:26:39

+0

不 - 只提到它是提到的異常日誌條目。我補充說我正在運行網絡服務。 – Doug 2013-03-27 00:08:55

+0

你運行的是哪個版本的nuget.exe? – 2013-03-27 02:19:02

回答

3

所以我在我的本地機器上測試了這個命令:

.\.nuget\NuGet.exe install Akavache\packages.config -source "" -RequireConsent -o packages 

,我得到一個錯誤:

Invalid URI: The format of the URI could not be determined.

我相信這是與此相關的位:

-source ""

因爲我可以放棄該值並讓它再次運行沒有錯誤。

哪一個問題,包源定義在哪裏?

NuGet.targets file裏面有這樣一段:

<ItemGroup Condition=" '$(PackageSources)' == '' "> 
    <!-- Package sources used to restore packages. By default, registered sources under %APPDATA%\NuGet\NuGet.Config will be used --> 
    <!-- The official NuGet package source (https://nuget.org/api/v2/) will be excluded if package sources are specified and it does not appear in the list --> 
    <!-- 
     <PackageSource Include="https://nuget.org/api/v2/" /> 
     <PackageSource Include="https://my-nuget-source/nuget/" /> 
    --> 
</ItemGroup> 

所以我建議,當你說這工作「在某些環境中,而不是別人」說你沒有一個配置文件在%APPDATA%\NuGet\NuGet.Config爲服務帳戶。

可以嘗試在源代碼控制改變這一部分在你的Nuget.targets文件是:

<ItemGroup Condition=" '$(PackageSources)' == '' "> 
    <PackageSource Include="https://nuget.org/api/v2/" /> 
</ItemGroup> 

,看看是否能在其他環境中解決您的問題是什麼?

+0

這是正確的 - 將Nuget.config添加到%APPDATA%\ Roaming \ NuGet \ NuGet.Config解決了這個問題。 – Doug 2013-03-27 09:12:11