0

I'm on Ubuntu and I have two .NET Core 2.0 projects (Project Oranges.csproj and Apples.csproj). Oranges only contains references to NuGet packages, while Apples contains a reference to Oranges.

Running dotnet build -f netcoreapp2.0 Oranges.csproj succeeds! Oranges.dll now exists at /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

How can I go about referencing Oranges, which builds without issue, in Apples without issue?

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

<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>
Bacon
  • 783
  • 2
  • 11
  • 31
  • can you provide us the csprojs for apple and oranges. Nice project names btw. – Thomas Sep 07 '17 at 21:12
  • @Thomas Sure can! – Bacon Sep 07 '17 at 21:26
  • use CLI to add reference. MSDN doc [here](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-add-reference) – Pratik Gaikwad Sep 07 '17 at 21:41
  • @PratikGaikwad Thanks for commenting. I have already added a reference to the project. See the code for `Apples.csproj` above. – Bacon Sep 07 '17 at 21:48
  • 1
    does this build using msbuild on windows (/ mono 5.2 msbuild on linux)? Full assembly signing doesn't yet work on .net core AFAIK – Martin Ullrich Sep 08 '17 at 03:59
  • @Jeff The error you are getting because `Oranges.dll` is being used and locked for execution in its own project. And hence it can't be directly accessed in `Apples.dll`. What you need is `copytolocal` similar to .net framework. But in doing net cor we have two options. 1) you can use `dotnet publish` command or 2) or for local testing you can set `true` source from this [SO](https://stackoverflow.com/questions/43837638/how-to-get-net-core-projects-to-copy-nuget-references-to-build-output). Let me know if it works or not. – Pratik Gaikwad Sep 08 '17 at 12:44

1 Answers1

2

After deleting the bin and obj folders from the project directory and rebuilding, a different error was being displayed.

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.

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

Bacon
  • 783
  • 2
  • 11
  • 31
  • Make sense. Signing was the only "strange" thing in your sample. It is a feature of the past. – Thomas Sep 09 '17 at 06:39