dotnet / dotnet/project-system

Analyzers apply to all target frameworks specified by conditional based on configuration

Open
#9,639 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
1k
Forks
415
PR merge metrics
No merged PRs in 30d

Description

## Summary

Code analyzers are producing errors and recommending fixes that aren't compatible with all my target frameworks, and I have yet to find a good solution. I am creating a plugin for an external application that uses a different runtime based on version. I need to write code that is both conditional on the APIs for the version of the application and runtime target.

The issue with my setup is that when I switch from net48 to a net8.0 configurations analyzers are recommending me changes that is incompatible with net48. It doesn't make much sense for me to add `net48;net8.0-windows` as it doubles build times (something I may be able to live with if there is no better solution).

My setup looks like the following.
 
```xml

Debug_23;Debug_24;Debug_25;Release_23;Release_24;Release_25;

net48
2023

net48
2024

net8.0-windows
APP2025


..\libs\2023\AppAPI.dll
false


..\libs\2024\AppAPI.dll
false


..\libs\2025\AppAPI.dll
false

```

I'm wondering if there is someway to specify net48;net8.0-windows but only ever build one of these based on configuration. Or whether VS can scan for TargetFramework based on conditions and provide analyzers that are compatible with both. For simplicity if I can write the code that is compatible with net48 with reasonable performance I would prefer this vs branching logic based on framework.

## User Impact
Analyzers giving incorrect code fixes leading to a less than ideal solution in which I either need to
a) having to add them to a list of ignores every time I encounter 1
b) reduce analyzer mode to try prevent this behaviour

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.