.net core 在.net 4.7.1上使用枚举中断的.net标准2引用,但在.net 4.6.1上使用

.net core 在.net 4.7.1上使用枚举中断的.net标准2引用,但在.net 4.6.1上使用,.net-core,.net-core-2.0,.net-standard-2.0,.net-4.7,.net Core,.net Core 2.0,.net Standard 2.0,.net 4.7,启动新项目,选择.netcore2控制台应用程序。 将目标框架更改为.NET461。您可以通过编辑.csproj文件来完成此操作,如图所示: <TargetFramework>net461</TargetFramework> 在控制台应用程序中使用所述枚举 class Program { static void Main(string[] args) { TestEnum t = TestEnum.One; Console

启动新项目,选择.netcore2控制台应用程序。 将目标框架更改为.NET461。您可以通过编辑.csproj文件来完成此操作,如图所示:

<TargetFramework>net461</TargetFramework>
在控制台应用程序中使用所述枚举

class Program
{
    static void Main(string[] args)
    {
        TestEnum t = TestEnum.One;
        Console.WriteLine("Hello World!");
    }
}
工作。酷。现在将控制台应用程序上的目标框架更改为.net471。像这样

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net471</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\LibStandard\LibStandard.csproj" />
  </ItemGroup>
我尝试(通过nuget.netstandard2.0.0)添加到控制台应用程序项目中,但这并不能解决问题

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net471</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="NETStandard.Library" Version="2.0.0" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\LibStandard\LibStandard.csproj" />
  </ItemGroup>

Exe
net471
如果您以前没有尝试过,您可以在461中为1.x标准运行.net标准库。但是对于.netstandard2和471,这一点并不适用。您还可以尝试添加新的控制台应用程序(桌面应用程序full netcore 471)。同样的结果。从.netcore控制台应用程序开始,然后以.netfx为目标,或者在没有.netcore的情况下开始,都会出现相同的错误

我被难住了


示例解决方案:

似乎与每个VS团队都有关系

解决方法似乎有效:添加\u HasReferenceToSystemRuntime

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net471</TargetFramework>
    <_HasReferenceToSystemRuntime>true</_HasReferenceToSystemRuntime>
  </PropertyGroup>

Exe
net471
真的

visual studio似乎仍然对处理.net标准感到有点困惑

似乎与此per VS团队有关

解决方法似乎有效:添加\u HasReferenceToSystemRuntime

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net471</TargetFramework>
    <_HasReferenceToSystemRuntime>true</_HasReferenceToSystemRuntime>
  </PropertyGroup>

Exe
net471
真的

似乎visual studio在处理.net标准时仍然有点困惑

加入GitHub讨论,如添加到GitHub讨论,如添加到
2>Program.cs(10,13,10,21): error CS0012: The type 'Enum' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
2>Program.cs(10,26,10,34): error CS0012: The type 'Enum' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
2>Program.cs(10,35,10,38): error CS0012: The type 'Enum' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
2>Done building project "ConsoleOne.csproj" -- FAILED.
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net471</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="NETStandard.Library" Version="2.0.0" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\LibStandard\LibStandard.csproj" />
  </ItemGroup>
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net471</TargetFramework>
    <_HasReferenceToSystemRuntime>true</_HasReferenceToSystemRuntime>
  </PropertyGroup>