Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build errors when multi-targeting in csproj file

I'm trying to build a class library that multi-targets both .NET 4.5.1 and .NET Standard 1.3. According to the documentation, I should be able to do this:

<PropertyGroup>
  <TargetFrameworks>net451;netstandard1.3</TargetFrameworks>
</PropertyGroup>

However, when I try to build, I get these odd errors:

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.

If I specify the target framework identifiers manually, it builds fine:

<PropertyGroup>
  <TargetFrameworks>net451;netstandard1.3</TargetFrameworks>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'net451'">
  <TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard1.3'">
  <TargetFrameworkIdentifier>.NETStandard</TargetFrameworkIdentifier>
</PropertyGroup>

I'm using Visual Studio 2017 Community. Am I doing something wrong here?

like image 295
Nate Barbettini Avatar asked Mar 28 '17 14:03

Nate Barbettini


1 Answers

Have you definitely written

<TargetFrameworks>net451;netstandard1.3</TargetFrameworks>

and not

<TargetFramework>net451;netstandard1.3</TargetFramework>

?

I was getting the same error until I added the missing s

like image 127
mcintyre321 Avatar answered Sep 25 '22 00:09

mcintyre321