Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

We should not infer ".NETFramework, Version=v0.0" when we encounter a unrecognized Target Framework #798

Closed
davkean opened this issue Feb 2, 2017 · 16 comments
Assignees
Milestone

Comments

@davkean
Copy link
Member

davkean commented Feb 2, 2017

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>foobar</TargetFramework>
  </PropertyGroup>

</Project>
  1. Build:
Error	MSB3644	The reference assemblies for framework ".NETFramework,Version=v0.0" 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.	ConsoleApp160	C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets	1111	
Error	MSB3645	.NET Framework v3.5 Service Pack 1 was not found. In order to target ".NETFramework,Version=v0.0", .NET Framework v3.5 Service Pack 1 or later must be installed.	ConsoleApp160	C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets	1111	
@davkean
Copy link
Member Author

davkean commented Feb 3, 2017

Looks like I should be getting:

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

But we're not.

@nguerrera
Copy link
Contributor

I get the cannot infer error and the others.

Gravité	Code	Description	Projet	Fichier	Ligne	État de la suppression
Erreur		Impossible de déduire TargetFrameworkIdentifier et/ou TargetFrameworkVersion à partir de TargetFramework='foo'. Ils doivent être spécifiés explicitement.	ConsoleApp128	C:\Program Files (x86)\Microsoft Visual 
Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.TargetFrameworkInference.targets	84	
Erreur	MSB3644	Les assemblys de référence pour le Framework ".NETFramework,Version=v0.0" sont introuvables. Pour résoudre ce problème, installez le SDK ou le Targeting Pack pour cette version de Framework, ou reciblez votre application vers une version du Framework pour laquelle le SDK ou le Targeting Pack est installé. Les assemblys seront résolus à partir du Global Assembly Cache (GAC) et seront utilisés à la place des assemblys de référence. C'est pourquoi votre assembly peut ne pas cibler correctement le Framework souhaité.	ConsoleApp128	C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets	1111	
Erreur		Le fichier de composant 'c:\users\nicholg\documents\visual studio 2017\Projects\ConsoleApp128\ConsoleApp128\obj\project.assets.json' n'a pas de cible pour '.NETFramework,Version=v0.0'. Vérifiez que vous avez restauré ce projet pour TargetFramework='net' et RuntimeIdentifier=''.	ConsoleApp128	C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.targets	113	

@nguerrera
Copy link
Contributor

The first one above is cannot infer in French

@nguerrera
Copy link
Contributor

I think before my crash fix, we would have found the .NET 4 reference assemblies so you would only have gotten the cannot infer error.

@nguerrera
Copy link
Contributor

@davkean Are you sure you're not also getting the cannot infer error?

@nguerrera
Copy link
Contributor

I just saw an issue on @jinujoseph's machine where not all errors in output window showed up in error list. I suspect that's why you didn't see the cannot infer error. I do see it in the error list.

@jinujoseph
Copy link
Contributor

jinujoseph commented Feb 3, 2017

output says this

1>------ Build started: Project: WebApplication1, Configuration: Debug Any CPU ------
1>WebApplication1 -> C:\Users\jinuj\documents\visual studio 2017\Projects\WebApplication1\WebApplication1\bin\Debug\netcoreapp1.1\WebApplication1.dll
2>------ Build started: Project: UnitTestProject2, Configuration: Debug Any CPU ------
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.Common.targets(69,5): error : Project 'C:\Users\jinuj\documents\visual studio 2017\Projects\WebApplication1\WebApplication1\WebApplication1.csproj' targets '.NETCoreApp,Version=v1.1'. It cannot be referenced by a project that targets '.NETCoreApp,Version=v1.0'.
2>Done building project "WebApplication1.csproj" -- FAILED.
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.targets(76,5): error : Cannot find project info for 'C:\Users\jinuj\documents\visual studio 2017\Projects\WebApplication1\WebApplication1\WebApplication1.csproj'. This can indicate a missing project reference.
2>Done building project "UnitTestProject2.csproj" -- FAILED.
========== Build: 1 succeeded or up-to-date, 1 failed, 0 skipped ==========

ErrorList shows doesn't show compatibility error

image

@dsplaisted
Copy link
Member

Looking into this, I think we currently have two issues:

Design-time builds

The design-time build doesn't run the _CheckForInvalidConfigurationAndPlatform target, and hence doesn't run our SDK _CheckForUnsupportedTargetFramework target which generates the error we want to see. Adding _CheckCompileDesignTimePrerequisite to the BeforeTargets of the SDK _CheckForUnsupportedTargetFramework fixes the VS experience.

@davkean How should we make sure this type of target runs in the design time build? Would it make sense for CompileDesignTime to depend on _CheckForInvalidConfigurationAndPlatform, or are the rest of the checks that target does not applicable to design-time builds

Command-line build

For command-line builds, the issue is that the _CheckForUnsupportedTargetFramework target is generating an error, but the build keeps on building the GetReferenceAssemblyPaths and GenerateBuildRuntimeConfigurationFiles targets. I'm not sure why it's continuing to run other targets once it hits an error, and I also haven't been able to create a minimal repro of this behavior yet.

@rainersigwald @AndyGerlicher @cdmihai Any idea what could be going on here?

@davkean
Copy link
Member Author

davkean commented Feb 28, 2017

_CheckForInvalidConfigurationAndPlatform is an initial target right? Wonder if we run initial targets during design-time builds - we probably should.

@dsplaisted
Copy link
Member

It's not an initial target. If it were, I doubt you could avoid running it.

@rainersigwald
Copy link
Member

It's no longer an InitialTarget because that caused problems with Restore: dotnet/msbuild#1280.

Nothing springs to mind for the command-line situation--is there a non-minimal repro @dsplaisted?

@dsplaisted
Copy link
Member

@rainersigwald OK, I've narrowed down a repro (or rather two of them).

When I try to build a .NET SDK project with an invalid TargetFramework, I get three errors where would like to get only one (the first):

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.TargetFrameworkInference.targets(84,5): error : Cannot infer TargetFrameworkIdentifier and/or TargetFrameworkVersion from TargetFramework='foobar'. They must be specified explicitly. [C:\Users\daplaist\Documents\Visual Studio 2017\Projects\ConsoleApp30\ConsoleApp30\ConsoleApp30.csproj]

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin\Microsoft.Common.CurrentVersion.targets(1111,5): error MSB3644: The reference assemblies for framework ".NETFramework,Version=v0.0" 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. [C:\Users\daplaist\Documents\Visual Studio 2017\Projects\ConsoleApp30\ConsoleApp30\ConsoleApp30.csproj]

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.targets(129,5): error : Assets file 'C:\Users\daplaist\Documents\Visual Studio 2017\Projects\ConsoleApp30\ConsoleApp30\obj\project.assets.json' not found. Run a NuGet package restore to generate this file. [C:\Users\daplaist\Documents\Visual Studio 2017\Projects\ConsoleApp30\ConsoleApp30\ConsoleApp30.csproj]

For the reference assembly error, here's the minimal repro:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
  
  <Target Name="_CheckForUnsupportedTargetFramework"
      BeforeTargets="_CheckForInvalidConfigurationAndPlatform;_CheckCompileDesignTimePrerequisite;GetFrameworkPaths;GetReferenceAssemblyPaths;GenerateBuildRuntimeConfigurationFiles">
    <Error Text="Error in _CheckForUnsupportedTargetFramework" />
  </Target>

  <Target Name="_CheckForInvalidConfigurationAndPlatform" BeforeTargets="$(BuildDependsOn);Build" />
  
  <PropertyGroup>
    <BuildDependsOn>
      EntityDeploy;
      CoreBuild;
    </BuildDependsOn>
  </PropertyGroup>
  
  <Target Name="Build" DependsOnTargets="$(BuildDependsOn)" Returns="$(TargetPath)" />

  <Target Name="CoreBuild" DependsOnTargets="PrepareForBuild;GenerateBuildRuntimeConfigurationFiles"/>

  <Target Name="PrepareForBuild" DependsOnTargets="GetReferenceAssemblyPaths"/>
  
  <Target Name="GetReferenceAssemblyPaths">
    <Error Text="GetReferenceAssemblyPaths Error" />
  </Target>

  <Target Name="EntityDeploy" Condition="'@(EntityDeploy)' != ''" />
</Project>

In this repro, I would hope that the error in _CheckForUnsupportedTargetFramework would prevent subsequent targets from being run. Something about the EntityDeploy target being added to the start of BuildDependsOn, and possibly the fact that BuildDependsOn is being used both in Build as DependsOnTargets and in _CheckForInvalidConfigurationAndPlatform as BeforeTargets is causing GetReferenceAssemblyPaths to run even after a previous target has failed.

Here's the minimal repro for the assets file not error:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
  
  <Target Name="_CheckForUnsupportedTargetFramework"
      BeforeTargets="_CheckForInvalidConfigurationAndPlatform;_CheckCompileDesignTimePrerequisite;GetFrameworkPaths;GetReferenceAssemblyPaths;GenerateBuildRuntimeConfigurationFiles">
    <Error Text="Error in _CheckForUnsupportedTargetFramework" />
  </Target>

  <Target Name="_CheckForInvalidConfigurationAndPlatform" BeforeTargets="$(BuildDependsOn);Build" />
  
  <PropertyGroup>
    <BuildDependsOn>
      CoreBuild;
    </BuildDependsOn>
  </PropertyGroup>
  
  <Target Name="Build" DependsOnTargets="$(BuildDependsOn)" Returns="$(TargetPath)" />

  <Target Name="CoreBuild" DependsOnTargets="PrepareForBuild;GenerateBuildRuntimeConfigurationFiles">
    <OnError ExecuteTargets="_CleanRecordFileWrites" />
  </Target>

  <Target Name="PrepareForBuild" DependsOnTargets="GetReferenceAssemblyPaths"/>
  
  <Target Name="GetReferenceAssemblyPaths">
    <Error Text="GetReferenceAssemblyPaths Error" />
  </Target>

  <Target Name="_CheckForCompileOutputs"/>
  <Target Name="_CleanGetCurrentAndPriorFileWrites" DependsOnTargets="_CheckForCompileOutputs" />
  <Target Name="_CleanRecordFileWrites" DependsOnTargets="_CleanGetCurrentAndPriorFileWrites"/>

  <Target Name="GenerateBuildRuntimeConfigurationFiles" BeforeTargets="_CheckForCompileOutputs">
    <Error Text="GenerateBuildRuntimeConfigurationFiles Error" />
  </Target>
  
</Project>

This is more straightforward, it looks like the OnError task in CoreBuild is causing _CleanRecordFileWrites and its dependencies to run after an error is encountered. I'm not sure exactly how to fix this yet though.

@davkean
Copy link
Member Author

davkean commented Feb 28, 2017

I think we should check that the removal of _CheckForInvalidConfigurationAndPlatform from initial targets doesn't break the legacy project system, this is such a massive change - and it is it even relevant anymore?

Hubert-Rybak added a commit to Hubert-Rybak/DotnetBenchmarks that referenced this issue Mar 3, 2017
* Added .NET Framework target
* Updated BenchmarkDotNet
* Waiting for patch: dotnet/sdk#798
@nguerrera nguerrera changed the title We should not infer ".NETFramework, Version=v1.0" when we encounter a unrecognized Target Framework We should not infer ".NETFramework, Version=v0.0" when we encounter a unrecognized Target Framework Mar 15, 2017
@dsplaisted dsplaisted modified the milestones: 2.0, 1.1 May 15, 2017
@dsplaisted
Copy link
Member

#1274, together with dotnet/msbuild#2133, should fix this

@livarcocc
Copy link
Contributor

This is working now:

sdk/2.0.0-preview2-006449/Sdks/Microsoft.NET.Sdk/build/Microsoft.NET.TargetFrameworkInference.targets(87,5): error : The TargetFramework value 'foobar' was not recognized. It may be misspelled. If not, then the TargetFrameworkIdentifier and/or TargetFrameworkVersion properties must be specified explicitly.

mmitche pushed a commit to mmitche/sdk that referenced this issue Jun 5, 2020
…0190721.5 (dotnet#798)

- Microsoft.AspNetCore.Mvc.Analyzers - 3.0.0-preview8.19371.5
- Microsoft.AspNetCore.Mvc.Api.Analyzers - 3.0.0-preview8.19371.5
- Microsoft.AspNetCore.Analyzers - 3.0.0-preview8.19371.5
- Microsoft.AspNetCore.Components.Analyzers - 3.0.0-preview8.19371.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants