Issue with PackageRestore, Silverlight, and MSBuil

2019-05-23 14:49发布

问题:

We use NugetPowerTools PackageRestore to avoid putting our packages folder in svn. This works building .NET projects with Visual Studio and MSBuild. It also works building Silverlight projects with Visual Studio.

However, when we use MSBuild to build Silverlight projects, the build fails. This appears to have to do with the tasks in Microsoft.Silverlight.Common.targets. Looking at the MSBuild output, it appears to get to the step GetXapOutputFile before it errors. Something either in that step, or after that step, is looking for the packages, but the package restore does not run until after all of this. Building a second time will succeed.

What is different from pressing build in Visual Studio than running MSBuild? Is there a command line switch I am missing?

If that won't work, is there some way I can change the NuGet.targets created by NuGetPowerTools or something I can put in my csproj file that will switch the order these steps are run?

I am running MSBuild Solution.sln /target:Clean;Rebuild

Edit

I've update NuGet to v1.6, removed all traces of NuGetPowerTools and I am now using the built in Package Restore option. I am still getting this error.

Edit Again

A discussion around this issue has come up again. I've tested this now with NuGet v2.0 and it is still happening.

回答1:

This has been corrected in NuGet v2.1.31002.9028. The details can be found in this commit.

For existing solutions, you will need to delete ./nuget/NuGet.targets from your solution. Do this through Windows Explorer. Deleting it through Visual Studio will only remove the file from your solution, it will leave the file alone.

Once you have done this, right click on your solution and select "Enable Package Restore". This will recreate NuGet.targets with the fix.