2017-06-22 91 views
1

,並不能得到的NuGet包使用還原/ T:作爲記錄here.恢復開關。該解決方案是一個相當簡單的ASP.NET MVC應用程序和MSTest項目。如果我在本地開發文件夾或構建服務器上運行恢復標誌,我看不到要恢復的NuGet包,即使我刪除了包,obj和bin文件夾。的MSBuild 15.1/4的NuGet不恢復我試圖通過命令行運行的MSBuild包

我已經啓用自動下載的文件here。如果我使用Studio打開該項目並構建它,則會按預期恢復包。這僅在使用MSBuild時失敗。

這一切正在與Visual Studio 2017年最新的補丁級別進行。生成機器有Professional,我的機器有Enterprise。兩者都有相同的行爲。

有沒有人得到的MSBuild使用的MSBuild 15.1挽回的NuGet包?

C:\Users\me\Documents\Visual Studio 2017\Projects\cmbs-admin>"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe" /t:Restore 
Microsoft (R) Build Engine version 15.1.1012.6693 
Copyright (C) Microsoft Corporation. All rights reserved. 

Building the projects in this solution one at a time. To enable parallel build, please add the "/m"switch. 
Build started 6/22/2017 2:01:57 PM. 
Project "C:\Users\me\Documents\Visual Studio 2017\Projects\MyProject\MyProject.sln" on node 
1 (Restore target(s)). 
ValidateSolutionConfiguration: 
    Building solution configuration "Debug|Any CPU". 
Restore: 
    Restoring packages for C:\Users\me\Documents\Visual Studio 2017\Projects\MyProject\MyProject.Tests\MyProject.Tests.csproj... 
    Restoring packages for C:\Users\me\Documents\Visual Studio 2017\Projects\MyProject\MyProject\MyProject.csproj... 
    Committing restore... 
    Committing restore... 
    Lock file has not changed. Skipping lock file write. Path: C:\Users\me\Documents\Visual Studio 2017\Projects\MyProject\MyProject\obj\project.assets.json 
    Lock file has not changed. Skipping lock file write. Path: C:\Users\me\Documents\Visual Studio 2017\Projects\MyProject\MyProject.Tests\obj\project.assets.json 
    Restore completed in 350.01 ms for C:\Users\me\Documents\Visual Studio 2017\Projects\MyProject\MyProject\MyProject.csproj. 
    Restore completed in 349.87 ms for C:\Users\me\Documents\Visual Studio 2017\Projects\MyProject\MyProject.Tests\MyProject.Tests.csproj. 

    NuGet Config files used: 
     C:\Users\me\AppData\Roaming\NuGet\NuGet.Config 
     C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config 

    Feeds used: 
     https://api.nuget.org/v3/index.json 
     C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\ 
Done Building Project "C:\Users\me\Documents\Visual Studio 2017\Projects\MyProject\MyProject.sln" (Restore target(s)). 


Build succeeded. 
    0 Warning(s) 
    0 Error(s) 

Time Elapsed 00:00:01.18 

C:\Users\me\Documents\Visual Studio 2017\Projects\MyProject> 
+0

你嘗試恢復什麼樣的項目? 'NuGet.exe恢復'仍然是非.NET核心項目的選項。 –

+0

它是一個傳統的基於CSPROJ的項目。你是說Nuget.exe是選項還是AN選項? http://blog.nuget.org/20170316/NuGet-now-fully-integrated-into-MSBuild.html –

+1

我發現,通過改變的csproj使用PackageReference語法代替參考(如在我以前的鏈接注意評論),事情工作。看起來這是MVC Web App CSPROJ模板的問題,而不是MSBuild。 –

回答

0

確認我上面的評論是(痛苦但有效的)修復。

我曾在一個文本編輯器,破解打開的csproj並更換所有PackageReference元素的參考要素。

例如:

<Reference Include="WebGrease"> 
    <Private>True</Private> 
    <HintPath>..\packages\WebGrease.1.5.2\lib\WebGrease.dll</HintPath> 
</Reference> 

變爲:

<PackageReference Include="WebGrease"> 
    <Version>1.6.0</Version> 
</PackageReference> 

所有未來的NuGet增加了尊重PackageReference語法,似乎與MSBuild的工作。這就是爲什麼我懷疑MVC應用程序項目類型模板而不是MSBuild或NuGet的問題。

+0

如果這樣做會自動完成會不會很好?例如。你改變選項中的設置,然後打開一個項目,並提供自動更改爲新的格式....哦! :-) – Manfred

+0

我似乎記得過去做過這樣的IDE。已經有幾年了。是的,這很不錯。 :) –

+0

一個善良的用戶用ps腳本創建了一個要點來達到這個目的。爲我工作。確保你的packages.config被備份或者事先在vc中,當腳本刪除它時。 https://gist.github.com/a4099181/074a6c3dd524ea0d343382137492399c – murraybiscuit