在也使用 netstandard2.1 的项目中升级到 .NET Core 3 不是在 Rider 中构建

Upgrading to .NET Core 3 in project that also uses netstandard2.1 is not building in Rider

我 运行 在 macOS 上工作,我正在处理的项目刚刚从 .NET Core 2 升级到 .NET Core 3。问题是我无法再在 Rider 中构建我的项目.如果我尝试使用 dotnet build 在终端中构建它,则构建成功。在我的项目中,有一些使用 netstandard2 的子项目,但这应该不是问题(因为它在终端中工作)。我收到以下错误消息:

Project1 is not compatible with netcoreapp3.0 (.NETCoreApp,Version=v3.0). Project2 supports: netstandard2.1 (.NETStandard,Version=v2.1)

我尝试添加一个 global.json 文件,该文件指定我使用的是 .NET Core 版本 3,但没有帮助。

如果我在终端运行 dotnet build 一次,那么新的Rider build 就会成功。所以一切正常,但总是先在终端中构建很烦人。

dotnet --info 的输出: dotnet --info

.NET Core SDK (reflecting any global.json):
 Version:   3.0.100
 Commit:    04339c3a26

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.14
 OS Platform: Darwin
 RID:         osx.10.14-x64
 Base Path:   /usr/local/share/dotnet/sdk/3.0.100/

Host (useful for support):
  Version: 3.0.0
  Commit:  7d57652f33

.NET Core SDKs installed:
  2.2.300 [/usr/local/share/dotnet/sdk]
  2.2.401 [/usr/local/share/dotnet/sdk]
  2.2.402 [/usr/local/share/dotnet/sdk]
  3.0.100 [/usr/local/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.2.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.7 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.2.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.7 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.2.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.7 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

我发现问题出在 Rider 中。解决方法是将 PackageReference Restore Engine(在 File > Settings > Build, Execution, Deployment > NuGet 中)更改为 MSBuild.

该问题将在后续的Rider版本中修复,建议版本发布后切换回EmbeddedMSBuildEmbedded的区别:

MSBuild just calls external MSBuild task; Embedded directly calls NuGet API inside Rider process. Embedded should work much faster and it provides additional logs which can be useful when restore fails

问题原因:

[...] because Rider 2019.2 EAP2 still used NuGet 4.9 internally; this version doesn't have proper support of .NET Core 3.0 / .NET Standard 2.1. In Rider 2019.2 RTM, we are going to upgrade the internal version of NuGet up to 5.1.

引用和截图来源: https://youtrack.jetbrains.com/issue/RIDER-29888