Introduce a Standard `$(TargetFrameworkVersionMajor)` MSBuild Property
- Dominant language
- C#
- Stars
- 5.5k
- Forks
- 1.5k
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 141
Description
### Summary
I propose adding a new, standard MSBuild property, **`$(TargetFrameworkVersionMajor)`**, that returns only the **major version number** of the currently targeted framework. This would greatly simplify conditional logic within `.props` and `.targets` files in multi-targeted projects, particularly for users moving to the new SDK-style project format.
### Background and Motivation
In modern .NET multi-targeting projects, the primary property most-commonly used in conditional build logic is **`$(TargetFramework)`** (e.g., `net48`, `net6.0`, `net8.0`, `net9.0-windows`, etc.). When writing conditional logic, users often need to distinguish between major framework generations only (e.g., to load different reference assemblies, set specific compiler flags, or define environment variables).
Currently, this requires using verbose, repetitive MSBuild string functions in many locations:
```xml
4
8
```
### Proposed Feature
Introduce a single, read-only property:
``$(TargetFrameworkVersionMajor)``
| $(TargetFramework) Value|Proposed $(TargetFrameworkVersionMajor) Value|
|--------------------------------|--------------------------------------|
|net462|4|
|net48|4|
|net6.0|6|
|net8.0|8|
|net8.0-windows|8|
|net9.0|9|
|net10.0|10|
### Benefits
✅ **Readability:** Simplifies complex conditional logic, e.g.,
```
Condition="'$(TargetFrameworkVersionMajor)' == '8'"
Condition="'$(TargetFrameworkVersionMajor)' >= '6'"
```
✅ **Maintainability:** Reduces the need for redundant string functions or custom property definitions across numerous build files.
✅ **Consistency:** Simplifies conditional logic that only cares about the major framework version, allowing conditional testing to see different variants of the same major framework version (e.g., `net10.0`, `net10.0-windows`, etc.) as *equivalent*, thereby standardizing a common pattern currently implemented manually by developers.
This small addition would be a significant quality-of-life improvement for anyone maintaining complex multi-targeted codebases.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.