[BuildCheck Suggestion]: Non-SDK project defines TargetFramework
#10635
Open
Description
Summary
A buildcheck to catch errors like the one that is the root cause of #10629.
Background and Motivation
In the modern .NET SDK, you define <TargetFramework>
or <TargetFrameworks>
to control what the project output targets. Older non-SDK projects have other properties for this (like TargetFrameworkVersion
). Currently it is allowed and ignored to specify TargetFramework
. . . but that can lead to a lot of confusion if someone does it, thinks they have retargeted the project, and then moves on.
Sample issue or antipattern that the check should be flagging
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>22dfcebd-2972-484f-9b0c-d1c6f28626eb</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ClassLibrary2</RootNamespace>
<AssemblyName>ClassLibrary2</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworks>net46;net8.0</TargetFrameworks> <!-- THIS IS BOGUS -->
</PropertyGroup>
Sample output
No response