Build errors when multi-targeting in csproj file

Nate Barbettini picture Nate Barbettini · Mar 28, 2017 · Viewed 8.3k times · Source

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?

Answer

mcintyre321 picture mcintyre321 · Mar 29, 2017

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