.NET project file analyzers community

Proj0027: Override <TargetFrameworks> with <TargetFrameworks>

Because the <TargetFramework> node precedes the <TargetFramework> node, it is not possible to change the target framework for a project once it has been set using <TargetFramework>. In those cases <TargetFrameworks> must be used instead.

Non-compliant

common.props

<Project>
  <PropertyGroup>
    <TargetFrameworks>net6.0;net8.0</TargetFrameworks>
  </PropertyGroup>
</Project>

my-project.csproj

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

  <Import Project="common.props" />

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
  </PropertyGroup>

</Project>

Compliant

common.props

<Project>
  <PropertyGroup>
    <TargetFrameworks>net6.0;net8.0</TargetFrameworks>
  </PropertyGroup>
</Project>

my-project.csproj

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

  <Import Project="common.props" />

  <PropertyGroup>
    <TargetFrameworks>net8.0</TargetFrameworks>
  </PropertyGroup>

</Project>