.net - mac/linux `dotnet build` 找不到框架 ".NETFramework.."的引用程序集

标签 .net linux macos dotnet-cli

尝试构建面向 net47 而不是 .netcore 或 .net std 的 Microsoft.NET.Sdk 样式项目时。 dotnet build 将给出有关缺少目标包的错误。 msbuild 将改为工作,但我更愿意使用 dotnet build。有办法吗。

/usr/local/share/dotnet/sdk/2.1.200/Microsoft.Common.CurrentVersion.targets
(1179,5): error MSB3644: The reference assemblies for framework 
".NETFramework,Version=v4.7" were not found. To resolve this, install the
 SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or
 Targeting Pack installed. Note that assemblies will be resolved from the
 Global Assembly Cache (GAC) and will be used in place of reference 
assemblies. Therefore your assembly may not be correctly targeted for the 
framework you intend.

最佳答案

是的。可以使用 nuget 提取目标包。然后添加框架路径覆盖。如果您的目标框架是 .NET v4.7,这里有一个片段可以添加到 Microsoft.NET.Sdk .csproj/.fsproj 的任何位置

  <PropertyGroup Condition="'$(OS)' != 'Windows_NT' AND '$(TargetFramework)'== 'net47'">
    <!-- Make .NET 4.7 reference assemblies available even on Linux -->
    <FrameworkPathOverride>$(NuGetPackageRoot)microsoft.targetingpack.netframework.v4.7/1.0.1/lib/net47/</FrameworkPathOverride>
    <!-- Make sure the additional feed is searched. -->
    <RestoreAdditionalProjectSources>https://dotnet.myget.org/F/dotnet-core/api/v3/index.json</RestoreAdditionalProjectSources>
  </PropertyGroup>

  <ItemGroup Condition="'$(OS)' != 'Windows_NT' AND '$(TargetFramework)'== 'net47'">
      <!-- Make sure the reference assemblies are available -->
      <PackageReference Include="Microsoft.TargetingPack.NETFramework.v4.7"
                        Version="1.0.1" ExcludeAssets="All" PrivateAssets="All" />
  </ItemGroup>

关于.net - mac/linux `dotnet build` 找不到框架 ".NETFramework.."的引用程序集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50284695/

相关文章:

c# - 以编程方式构建和发布 .net Web App

macos - 我无法在界面生成器中取消选中 "Refuses First Responder"

swift - Swift 中每个 NSTabViewItem 一个 View Controller

objective-c - MacOS MTKView metal self.device.newBufferWithBytes 因断言而崩溃

c# - 如何在运行时在 .net 中向对象添加属性?

.net - 将数组传递给函数

c# - 我可以在 C# 中不指定类名的情况下将静态类作为命名空间导入来调用其方法吗?

linux - 删除桶中的对象但存储大小未增加到riak

linux - send() 什么时候返回小于长度参数?

Android ADB Linux 问题