.net - 在csproj文件中多目标时生成错误

标签 .net .net-core visual-studio-2017 csproj

我正在尝试建立一个同时针对.NET 4.5.1和.NET Standard 1.3的类库。根据the documentation,我应该能够做到这一点:

<PropertyGroup>
  <TargetFrameworks>net451;netstandard1.3</TargetFrameworks>
</PropertyGroup>
但是,当我尝试构建时,出现以下奇怪错误:

Cannot infer TargetFrameworkIdentifier and/or TargetFrameworkVersion from TargetFramework='net451'. They must be specified explicitly.

MSB3645 .NET Framework v3.5 Service Pack 1 was not found. In order to target ".NETFramework,Version=v1.3", .NET Framework v3.5 Service Pack 1 or later must be installed.

MSB3644 The reference assemblies for framework ".NETFramework,Version=v1.3" 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.


如果我手动指定目标框架标识符,它会很好地构建:
<PropertyGroup>
  <TargetFrameworks>net451;netstandard1.3</TargetFrameworks>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'net451'">
  <TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard1.3'">
  <TargetFrameworkIdentifier>.NETStandard</TargetFrameworkIdentifier>
</PropertyGroup>
我正在使用Visual Studio 2017社区。我在这里做错什么了吗?

最佳答案

您是否确实编写了<TargetFrameworks>net451;netstandard1.3</TargetFrameworks>而不是<TargetFramework>net451;netstandard1.3</TargetFramework>

在添加缺少的s之前,我遇到了同样的错误

关于.net - 在csproj文件中多目标时生成错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43072097/

相关文章:

.net-core - .Net Core 2.0 xUnit 项目 - 这些 DLL 是什么?

c# - 我在哪里可以下载 PEVerify.exe 工具?

.net-core - 得到错误 "The "RazorGenerate”任务意外失败。“。更新到 VS 16.8 并升级到 .net 5 后.. 核心版本目标是核心 2.2

c# - Entity Framework Core - 对计算字段进行排序

c# - 生成错误 - Roslyn MSB3883 : Unexpected exception: System. IO.FileNotFoundException for System.Security.Principal.Windows

c# - 为什么我无法在安装 Roslyn SDK 后创建新的分析器/代码修复提供程序项目?

c# - 无法加载 DLL 'db2app64.dll'

c# - 在异步等待中等待的工作

c# - MySQL 返回列名而不是它们的内容

visual-studio - VsVim - 默认搜索不区分大小写