简体   繁体   中英

VS Build fails for .NET project because of NuGet package restore errors

I am working on an MVC.NET project using .NET 4.5.2 in Visual Studio 17 which is unable to build due to the error:

The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://www.postsharp.net/links/nuget-restore .

My version of PostSharp is 4.1.30.

This error happens every time I build or rebuild the proejct and doesn't disappear after building several times in a row. The error is happening for several projects which reference PostSharp.

The error only occurs after I make a change within the solution. If I checkout a fresh copy of Trunk, I can load the website. It's only after making a chance that these errors occur. The change can be small, such as adding a new controller file in an unrelated project to where the errors reference.

I've tried restoring my NuGet packages, rebooting my machine, even deleting my repo and re-checking out a clean install of Trunk. How can I get past this error? I'm not sure if it's definitely related to PostSharp, or a more general NuGet error.

After looking in the .csproj file to see what is causing the error in one of the projects, I found these lines:

 <Import Project="packages\PostSharp.4.1.25\tools\PostSharp.targets" Condition="Exists('packages\PostSharp.4.1.25\tools\PostSharp.targets')" />
 <Target Name="EnsurePostSharpImported" BeforeTargets="BeforeBuild" Condition="'$(PostSharp30Imported)' == ''">
    <Error Condition="!Exists('packages\PostSharp.4.1.25\tools\PostSharp.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://www.postsharp.net/links/nuget-restore." />
    <Error Condition="Exists('packages\PostSharp.4.1.25\tools\PostSharp.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://www.postsharp.net/links/nuget-restore." />
  </Target>

I tried removing it to see what would happen but perhaps unsuprisingly it didn't build and didn't report any errors.

This looks like an issue with upgrading of the PostSharp NuGet package. In your .csproj file, there is PostSharp 4.1.25 installed, but you say you are using PostSharp 4.1.30.

One of the following might help:

  • Either change the package version in packages.config to 4.1.25, check if the project builds and then use NuGet Package manager to upgrade to a newer version if needed,
  • or remove PostSharp from packages.confing and .csproj (the lines you are showing + reference to PostSharp.dll and any other PostSharp.*.dll), then install PostSharp using NuGet package manager.

Please note that PostSharp 4.1 is no longer supported. See https://www.postsharp.net/support/policies#support for list of supported versions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM