.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/29262642/

相关文章:

.net - 商业混淆器如何实现崩溃 .net Reflector 和 ILDASM?

c# - 有什么方法可以将 ASP.NET Core 2.0 HTTPS 限制为 TLS 1.2?

c# - VS 2017 : The security debugging option is set but it requires the Visual Studio hosting process which is unavailable

visual-studio-2017 - NuGet软件包无法在Visual Studio 2017中还原

c# - 每个托管线程是否都有自己对应的 native 线程?

c# - 如何清除 rabbitmq (.net) 中的队列路由键绑定(bind)

.net - ibm.data.informix 没有从数据库中获取正确的数据

security - 如何从包含 .Net Core 中的私钥/公钥的 PEM 文件中导入 PKCS1 key

.net - Docker-compose 与 .NET Core 无法访问

c++ - 内联变量的多次销毁