我在Ubuntu上,我有两个.NET Core 2.0项目(ProjectOranges.csprojApples.csproj)。Oranges只包含对NuGet包的引用,而Apples包含对Oranges的引用。
运行成功!dotnet build -f netcoreapp2.0 Oranges.csproj现在存在于Oranges.dll
运行/Oranges/bin/Debug/netcoreapp2.0/Oranges.dll失败,返回:dotnet build -f netcoreapp2.0 Apples.csproj
如何在没有问题的error CS0009: Metadata file '/Oranges/bin/Debug/netcoreapp2.0/Oranges.dll' could not be opened -- PE image doesn't contain managed metadata中引用Oranges,它生成时没有问题?
橙子.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <TargetFrameworks>netcoreapp2.0;net451;</TargetFrameworks>
    <RootNamespace>Oranges</RootNamespace>
    <SignAssembly>true</SignAssembly>
    <AssemblyOriginatorKeyFile>..\..\GeneratedKey.snk</AssemblyOriginatorKeyFile>
    <DelaySign>false</DelaySign>
  </PropertyGroup>

  <PropertyGroup Condition="'$(TargetFramework)' == 'netcore2.0'">
    <DefineConstants>NETCORE2_0</DefineConstants>
  </PropertyGroup>
  <PropertyGroup Condition="'$(TargetFramework)' == 'net451'">
    <DefineConstants>NET4_5_1</DefineConstants>
  </PropertyGroup>

  <ItemGroup>
    <None Remove="packages.config" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
    <PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
  </ItemGroup>
</Project>

苹果.csproj
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <TargetFrameworks>netcoreapp2.0;net451;</TargetFrameworks>
    <RootNamespace>Apples</RootNamespace>
    <SignAssembly>true</SignAssembly>
    <DelaySign>false</DelaySign>
    <AssemblyOriginatorKeyFile>..\..\GeneratedKey.snk</AssemblyOriginatorKeyFile>
  </PropertyGroup>

  <ItemGroup>
    <None Remove="packages.config" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="CommandLineParser" Version="2.1.1-beta" />
    <PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
    <PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
    <PackageReference Include="System.Composition" Version="1.1.0" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\Oranges\Oranges.csproj" />
  </ItemGroup>
</Project>

最佳答案

从项目目录中删除binobj文件夹并重新生成后,将显示另一个错误。
CSC : error CS7027: Error signing output with public key from file 'GeneratedKey.snk' -- Assembly signing not supported. [.../Oranges/Oranges.csproj]
经过一番研究,我偶然发现了一个解决办法。
Assembly Signing Not Supported
为每个需要签名的程序集将下面的行添加到.csproj文件中解决了该问题。
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
目前看来,如果需要对netcore程序集进行签名,应该在Windows上完成。

08-26 10:57