Sdk: Can no longer use TargetFrameworkIdentifier/TargetFrameworkVersion to specify framework

Created on 7 Aug 2018  路  6Comments  路  Source: dotnet/sdk

Build the following:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFrameworkIdentifer>.NETFramework</TargetFrameworkIdentifer>
    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
  </PropertyGroup>

</Project>

Expected: No error
Actual:

Error   NETSDK1013  The TargetFramework value '' was not recognized. It may be misspelled. If not, then the TargetFrameworkIdentifier and/or TargetFrameworkVersion properties must be specified explicitly.    ConsoleApp197   C:\Program Files\dotnet\sdk\2.1.400\Sdks\Microsoft.Net.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets   96  
Error   MSB4018 The "ResolvePackageAssets" task failed unexpectedly.
NuGet.Frameworks.FrameworkException: Invalid framework identifier ''.
   at NuGet.Frameworks.NuGetFramework.GetShortFolderName(IFrameworkNameProvider mappings)
   at Microsoft.NET.Build.Tasks.LockFileExtensions.GetTargetAndThrowIfNotFound(LockFile lockFile, NuGetFramework framework, String runtime)
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter..ctor(ResolvePackageAssets task, Stream stream)
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader.CreateReaderFromDisk(ResolvePackageAssets task, Byte[] settingsHash)
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader..ctor(ResolvePackageAssets task)
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ReadItemGroups()
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ExecuteCore()
   at Microsoft.NET.Build.Tasks.TaskBase.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() ConsoleApp197   C:\Program Files\dotnet\sdk\2.1.400\Sdks\Microsoft.Net.Sdk\targets\Microsoft.PackageDependencyResolution.targets    198 


Most helpful comment

lol, thanks for chasing this down.

All 6 comments

@nguerrera seems like a regression due to the cache we added in 2.1

This is the root cause of the regression:

"C:\Users\nicholg\source\repos\ConsoleApp40\ConsoleApp40\ConsoleApp40.csproj" (default target) (1) ->
(_CheckForUnsupportedTargetFramework target) ->
  C:\Program Files\dotnet\sdk\2.1.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(96,5): error NETSDK1013: The TargetFramework value '' was not recognized. It may be misspelled. If not, then the TargetFrameworkIdentifier and/or TargetFrameworkVersion properties must be specified explicitly. [C:\Users\nicholg\source\repos\ConsoleApp40\ConsoleApp40\ConsoleApp40.csproj]

This is bogus because we have specified TargetFrameworkIdentifier and TargetFrameworkVersion explicitly.

The subsequent crash happens only in design-time build and is https://github.com/dotnet/sdk/issues/2363

Ugh, there's more. restore only succeeds in Visual Studio:

C:\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.targets(114,5): error : Invalid framework identifier ''. [C:\Users\nicholg\source\repos\ConsoleApp40\ConsoleApp40\ConsoleApp40.csproj]

(EDIT: Restore didn't succeed, in Visual it just didn't get as far as restore due to design-time crash earlier)

OK, TargetFrameworkIdentifier is misspelled as TargetFrameworkIdentifer in the repro. :trollface:

With the typo fixed, this works as expected. 馃槃

On the command line, the error message could maybe be refined, but it is correct -- you have and empty TargetFramework AND you did not in specify both TargetFrameworkIdentifier and TargetFrameworkVersion.

The crash when the TFM is invalid in ResolvePackageAssets during design time builds is #2363, so closing this as a duplicate of that.

Filed #2461 to improve the error message.

lol, thanks for chasing this down.

Was this page helpful?
0 / 5 - 0 ratings