在4.7.2 Project Mono

时间:2018-11-26 10:55:55

标签: .net mono nuget .net-standard-2.0

我试图在Mono的.Net 4.7.2项目中引用.net标准的Nuget包。该版本在Windows上运行正常,但是在Ubuntu 18.04下,使用库中的属性时出现以下错误。

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

我已遵循该说明并安装了以下nuget软件包:

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

我也尝试过:

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

但是错误仍然存​​在。

由nuget生成的完整的Nuget软件包.config如下所示:

<?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来自私有的Nuget提要,并且仅针对.net标准2.0。

Netstandard库似乎正确安装,在以下部分中将构建目标添加到我的csproj文件中:

<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')" />

我检查了一下,所有文件都在预期的位置。

这是我的单声道版本:

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

从5.18.0 Preview(5.18.0.209)(https://www.mono-project.com/download/preview/)安装

更新

我尝试添加

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

到我的csproj文件,这导致以下错误:

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.

0 个答案:

没有答案