0

I have a application that uses Roslyn API to analyze C# code inside separated solutions; After some Visual Studio updates, i'm receiving this error in my application:

Msbuild failed when processing the file '{separated solution .csproj file}' with message: Could not load type 'Microsoft.Build.Framework.SdkResultItem' from assembly 'Microsoft.Build.Framework, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

This error is shown for each project inside the analyzed solution; i can see the errors inside the variable ws.Diagnostics at:

using var ws = MSBuildWorkspace.Create();

ws.LoadMetadataForReferencedProjects = true;

var solution = await ws.OpenSolutionAsync(solutionPath,
    msbuildLogger: buildLogger,
    cancellationToken: cancellationToken);

Before the Visual Studio update my code was working; there is some way to fix it without reinstalling the Visual Studio?

I've alrey tried to renninstal the Microsoft.Build.Framework reference using the developer command prompt, but does not works.

1 Answers1

1

Follow the instructions at this site to use Microsoft.Build.Locator, and do that prior to calling MSBuildWorkspace.Create. That'll ensure you have binding redirects that will keep you version independent.

Jason Malinowski
  • 18,148
  • 1
  • 38
  • 55
  • Thanks! Following the link i've see that i was not setting the `ExcludeAssets="runtime"` at my package reference inside the csproj file; after setting that, it worked. Just one question: When i fixed it, i started to face a error "Could not load file or assembly'NuGet.Versioning, Version=5.7.0.7", and then i had to update my references from Nuget packages ("Nuget.Versioning" included) from 5.6 to 5.7. What made necessary to have a new referenced version? It was a change at my environment? – rafaatsouza Sep 10 '20 at 01:25
  • 1
    Possibly; if your VS was updated that might have also brought along a new MSBuild/SDK versions that could have some impacts there. It's hard to say without a specific error repro, and even then it's hard to diagnose. :-( – Jason Malinowski Sep 10 '20 at 05:05