0

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

2 Answers2

2

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.

Daniel Balas
  • 1,805
  • 1
  • 15
  • 20
  • 1
    We have a nuget.config file that among other package sources include a reference to the Nuget.Org package source, but this doesn't seem to do the trick in this case then? Following your answer I removed the nuget.config file and added a reference to the Nuget.org package source in Visual Studio manually and now the project builds as expected. – Martin Emanuelsson Dec 20 '21 at 20:14
  • @MartinEmanuelsson The problem is that PostSharp runs its dependency restore in a subdirectory of `C:\ProgramData`, which means that it does not consume your repository-specific `nuget.config`. There seems to be no universal solution - repo-specific configuration may get in the way or actually contain a solution. – Daniel Balas Dec 21 '21 at 21:28
  • 1
    Now that I know how to make it work again I'm satisfied with that. Hopefully this thread can also help others who come across the same problem. Thanks for your quick response once again! – Martin Emanuelsson Dec 22 '21 at 09:53
2

As mentioned in my comment to the answer above the solution to my problem was to:

  1. Remove our own nuget.config file (even if it contained a reference to the nuget.org package source)
  2. Add a reference to the nuget.org package source (https://api.nuget.org/v3/index.json) in Visual Studio under Tools --> Nuget Package Manager --> Package Manager Settings --> Package Sources
  3. Build the solution again
  4. Add our own nuget.config file to the solution again