msbuild.net-5postsharpvisual-studio-2022

Unable to build solution using PostSharp in Visual Studio 2022 after moving code to new computer


I've just recently started using a newly installed PC but am having trouble building a solution in Visual Studio 2022 that uses PostSharp (version 6.10.5). It works without problem to build the same solution on my old computer and strangely enough a colleague of mine who also recently installed a new computer has no problem building the solution.

Visual Studio throws a bunch of NU1101- and NU1102-errors such as these: enter image description here

It also hints to the following information regarding PostSharp which I'm not sure how to fix?

The process "C:\Program Files\dotnet\dotnet.exe" failed with exit code 1.    
Restore of compiler dependencies failed. To disable compiler dependencies restore use PostSharpDependencyRestoreDisabled=True MSBuild property. 
Unable to start PostSharp due to previous error encountered while creating fallback package directory.

enter image description here

We're including PostSharp via a private Nuget package where we're referencing PostSharp like this after input in this thread: How to have PostSharp included in build process for ASP.NET WebApi project when installed using our own Nuget package?.

 <PackageReference Include="PostSharp" Version="6.10.5" PrivateAssets="none" />

If I exclude everything related to PostSharp, the solution builds just fine but not with PostSharp included. Any help here would be very much appreciated.

/Martin


Solution

  • If NuGet errors are in the build output and immediately before the error stating that PostSharp's dependency restore had failed (not apparent from screenshots), PostSharp is attempting to gather its references for the first build on the machine.

    PostSharp does this by running NuGet restore under current settings for packages it depends on (e.g. System.Runtime.CompilerServices.Unsafe).

    Since NuGet sources that are enabled for the build seem to include only "Offline packages", it is not able to find required packages as these are not present on your machine.

    The solution is to run the build once with NuGet.Org package source enabled. PostSharp should then be able to download its dependencies and all subsequent builds should run without problems (unless you upgrade to a new minor version of PostSharp). The presence of NuGet.org package source is probably the difference between machines that causes this problem.