3

I am trying to reference a .net standard Nuget package in my .Net 4.7.2 Project in Mono. The build works fine in Windows, however under Ubuntu 18.04, I get the following error when using an Attribute from the library.

  DataClassThing.cs(7, 10): [CS0012] The type 'Attribute' 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'.

I've followed that instruction and installed the following nuget package:

<package id="NETStandard.Library" version="2.0.3" targetFramework="net472" />

I've also tried:

<package id="NETStandard.Library" version="2.0.0" targetFramework="net472" />

But the error persists.

The full Nuget packages.config generated by nuget looks as follows:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Microsoft.NETCore.Platforms" version="1.1.0" targetFramework="net472" />
  <package id="MyMagicLibrary" version="1.0.25" />
  <package id="NETStandard.Library" version="2.0.3" targetFramework="net472" />
</packages>

MyMagicLibrary is from a private Nuget feed and only targets .net standard 2.0.

The Netstandard Library seems to install correctly, adding build targets to my csproj file in the following section:

<Import Project="..\packages\NETStandard.Library.2.0.0\build\netstandard2.0\NETStandard.Library.targets" Condition="Exists('..\packages\NETStandard.Library.2.0.0\build\netstandard2.0\NETStandard.Library.targets')" />
  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
    <PropertyGroup>
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}.</ErrorText>
    </PropertyGroup>
    <Error Condition="!Exists('..\packages\NETStandard.Library.2.0.0\build\netstandard2.0\NETStandard.Library.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NETStandard.Library.2.0.0\build\netstandard2.0\NETStandard.Library.targets'))" />
    <Error Condition="!Exists('..\packages\NETStandard.Library.2.0.3\build\netstandard2.0\NETStandard.Library.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NETStandard.Library.2.0.3\build\netstandard2.0\NETStandard.Library.targets'))" />
  </Target>
  <Import Project="..\packages\NETStandard.Library.2.0.3\build\netstandard2.0\NETStandard.Library.targets" Condition="Exists('..\packages\NETStandard.Library.2.0.3\build\netstandard2.0\NETStandard.Library.targets')" />

I checked and all the files are there as expected.

This is my mono version:

Mono JIT compiler version 5.18.0.209 (tarball Sat Nov 24 08:46:26 UTC 2018)

Installed from 5.18.0 Preview (5.18.0.209) (https://www.mono-project.com/download/preview/)

Update

I tried adding

  <ItemGroup>
    <Reference Include="netstandard"/>
  </ItemGroup>

To my csproj file, which resulted in the following error:

Target ResolveAssemblyReferences:
    Primary reference "netstandard".
    /usr/lib/mono/msbuild/15.0/bin/Microsoft.Common.CurrentVersion.targets(2127,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "netstandard". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
            For SearchPath "{TargetFrameworkDirectory}".
            Considered "/usr/lib/mono/xbuild-frameworks/.NETFramework/v4.7.2/netstandard.winmd", but it didn't exist.
            Considered "/usr/lib/mono/xbuild-frameworks/.NETFramework/v4.7.2/netstandard.dll", but it didn't exist.
            Considered "/usr/lib/mono/xbuild-frameworks/.NETFramework/v4.7.2/netstandard.exe", but it didn't exist.
            For SearchPath "{GAC}".
            Considered "netstandard", which was not found in the GAC.
            For SearchPath "{RawFileName}".
            Considered treating "netstandard" as a file name, but it didn't exist.
            For SearchPath "bin/Debug/".
            Considered "bin/Debug/netstandard.winmd", but it didn't exist.
            Considered "bin/Debug/netstandard.dll", but it didn't exist.
            Considered "bin/Debug/netstandard.exe", but it didn't exist.
Tjaart
  • 3,912
  • 2
  • 37
  • 61

0 Answers0