问题
My code is responsible for get types namespaces using Roslyn API based on solution file path; before i find out namespaces, i get the documents with:
using (var ws = MSBuildWorkspace.Create())
{
var solution = await ws.OpenSolutionAsync(solutionPath);
//[...] some code
var diagnostics = ws.Diagnostics;
//[...] some code
return solution.Projects.SelectMany(p => p.Documents);
}
When i pass as parameter some solution file path from a .NET Framework solution, the code works fine. But when i pass as parameter some solution file path from a .NET Core solution, the variable diagnostics
gets some errors (one for each project inside the solution):
Msbuild failed when processing the file '
[project's .csproj file]
' with message: C:\Program\Files\dotnet\sdk\3.1.301\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ConflictResolution.targets: (39, 5): The "ResolvePackageFileConflicts" task failed unexpectedly. System.IO.FileNotFoundException: Could not load file or assembly 'NuGet.Versioning, Version=5.6.0.5, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
Both solutions (.NET Core and .NET Framework) compile correctly. Do i have to setup some specific configuration when i'm analyzing .NET Core projects with Roslyn?
回答1:
I've managed to reproduce this while loading Nodatime with a .Net Core 3.1 project. In order to solve it you can add the following NuGet
package references to your solution:
- NuGet.Frameworks
- NuGet.Packaging
- NuGet.ProjectModel
- NuGet.Versioning
来源:https://stackoverflow.com/questions/62625114/roslyn-error-only-with-net-core-resolvepackagefileconflicts-task-failed-unex