简体   繁体   English

.NET Core 2.0项目会生成,但不会被另一个.NET Core 2.0项目引用

[英].NET Core 2.0 Project Builds But Not When Referenced By Another .NET Core 2.0 Project

I'm on Ubuntu and I have two .NET Core 2.0 projects (Project Oranges.csproj and Apples.csproj ). 我在Ubuntu上,我有两个.NET Core 2.0项目(Project Oranges.csprojApples.csproj )。 Oranges only contains references to NuGet packages, while Apples contains a reference to Oranges . Oranges仅包含对NuGet包的引用,而Apples仅包含对Oranges的引用。

Running dotnet build -f netcoreapp2.0 Oranges.csproj succeeds! 运行dotnet build -f netcoreapp2.0 Oranges.csproj成功! Oranges.dll now exists at /Oranges/bin/Debug/netcoreapp2.0/Oranges.dll . Oranges.dll现在位于/Oranges/bin/Debug/netcoreapp2.0/Oranges.dll

Running dotnet build -f netcoreapp2.0 Apples.csproj fails with: error CS0009: Metadata file '/Oranges/bin/Debug/netcoreapp2.0/Oranges.dll' could not be opened -- PE image doesn't contain managed metadata 运行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 metadataerror CS0009: Metadata file '/Oranges/bin/Debug/netcoreapp2.0/Oranges.dll' could not be opened -- PE image doesn't contain managed metadata

How can I go about referencing Oranges , which builds without issue, in Apples without issue? 我该如何在Apples引用没有问题的Oranges

Oranges.csproj 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>

Apples.csproj Apples.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>

After deleting the bin and obj folders from the project directory and rebuilding, a different error was being displayed. 从项目目录中删除binobj文件夹并重建后,将显示另一个错误。

CSC : error CS7027: Error signing output with public key from file 'GeneratedKey.snk' -- Assembly signing not supported. [.../Oranges/Oranges.csproj]

After some research I stumbled across a solution. 经过一番研究,我偶然发现了一个解决方案。

Assembly Signing Not Supported 不支持程序集签名

Adding the line below to the .csproj file for each assembly that required signing resolved the issue. 将下面的行添加到需要签名的每个程序集的.csproj文件中,可以解决此问题。

<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>

For now it seems like if you need to sign netcore assemblies, it should be done on Windows. 现在看来,如果您需要对netcore程序集进行签名,则应在Windows上完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM