Roslyn error only with .NET Core: “ResolvePackageFileConflicts” task failed unexpectedly

故事扮演 提交于 2020-07-10 07:00:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!