.net - mac/linux `dotnet build` 没有找到框架“.NETFramework..”的参考程序集
问题描述
在尝试构建针对 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>
推荐阅读
- c# - 从字符串转换日期和/或时间时转换失败 - 在数据库中插入 datetimepicker.value
- javascript - 为什么控制台中有值但页面中没有显示?
- javascript - 运行 .click() 命令时出错:从 NightwatchJS 中分离的目标框架
- c - 是什么导致了分段错误?
- javascript - 如何避免 [Vue 警告]:组件渲染函数中可能存在无限更新循环。在 VUEJS 中
- sql - 带有案例和变量的触发器后的Oracle
- algorithm - 时间复杂度分析
- git - 撤消 git squash rebase
- visual-studio - Xamarin Android:network_security_config.xml 仅用于调试
- reactjs - 渲染时反应超时