Roslyn仅在.NET Core中出现错误:"ResolvePackageFileConflicts"任务意外失败 [英] Roslyn error only with .NET Core: "ResolvePackageFileConflicts" task failed unexpectedly

查看:304
本文介绍了Roslyn仅在.NET Core中出现错误:"ResolvePackageFileConflicts"任务意外失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码负责根据解决方案文件路径使用Roslyn API来获取类型名称空间;在我找到名称空间之前,我先获得了以下文件:

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);
}

当我从.NET Framework解决方案传递一些解决方案文件路径作为参数时,代码可以正常工作.但是,当我从.NET Core解决方案传递一些解决方案文件路径作为参数时,变量diagnostics会遇到一些错误(解决方案中的每个项目一个):

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在处理文件"[project's .csproj file]" 时失败 有消息: C:\ Program \ Files \ dotnet \ sdk \ 3.1.301 \ Sdks \ Microsoft.NET.Sdk \ targets \ Microsoft.NET.ConflictResolution.targets: (39,5):"ResolvePackageFileConflicts"任务意外失败. System.IO.FileNotFoundException:无法加载文件或程序集 'NuGet.Versioning,版本= 5.6.0.5,文化=中性, PublicKeyToken = 31bf3856ad364e35'.系统找不到指定的文件.

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.

两个解决方案(.NET Core和.NET Framework)都可以正确编译.使用Roslyn分析.NET Core项目时,是否必须设置一些特定的配置?

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?

推荐答案

在加载 Nodatime 和一个.Net Core 3.1项目.为了解决这个问题,您可以在解决方案中添加以下NuGet软件包引用:

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

这篇关于Roslyn仅在.NET Core中出现错误:"ResolvePackageFileConflicts"任务意外失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆