我试图通过命令行运行MSBuild,并且无法使用文件here.中的/ t:restore开关来恢复NuGet包。该解决方案是一个相当简单的ASP.NET MVC应用程序和一个MSTest项目。如果我在我的本地开发文件夹或构建服务器上运行还原标志,我看到没有恢复NuGet包,即使我删除了包,obj和bin文件夹。
我已按照文档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 :(得分:1)
将上述评论确认为(痛苦但有效)修复。
我必须在文本编辑器中打开CSPROJ并用PackageReference元素替换所有Reference元素。
例如:
<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 app项目类型模板的问题,而不是MSBuild或NuGet。