Open ChrisBertrandIndus opened 2 years ago
EnablePreviewFeatures
is a .NET SDK concept, so moving this to dotnet/sdk
. I agree that a warning would be nice here.
Same issue happens for Platform Compatibility Analyzer, when a project targets a specific platform (Windows for example) assembly level SupportedOSPlatform("windows")
attribute should be added to AssmeblyInfo.cs
, but could not if GenerateAssemblyiInfo
set to false. There has been a discussion to warn about it in the PC Analyzer but it is not issue with the analyzer. Also there is an advanced scenarios like Building a library that offers preview features where a library developer might not wanted/needed to have an attribute for entire assembly, instead to have the attribute only for APIs that requires it.
In a project with only .netx.0-windows target framework the warning CA1416 is confusing.
What is added via GenerateAssemblyInfo? I need to set it to false as I use Unclassified.NetRevisionTask
to set version base on code revision which sometime caused duplicate AssemblyInfo data, so I turned GenerateAssemblyInfo off.
What is added via GenerateAssemblyInfo?
As you know when GenerateAssemblyInfo
is enabled MSBuild adds AssemblyInfo.cs
file, with required assembly attributes like [assembly: System.Runtime.Versioning.SupportedOSPlatform("windows")]
when the project targeting windows. This attribute which turns off the CA1416 when calling windows only APIs. If you are using custom AssemblyInfo.cs
you can add the assembly level SupportedOSPlatform
attribute with the target platform anywhere in your project
What is added via GenerateAssemblyInfo?
If you are using custom
AssemblyInfo.cs
you can add the assembly levelSupportedOSPlatform
attribute with the target platform anywhere in your project
this is what I did now. I created a new project targeting netX.0-windows
and copied the generated SupportedOS and TargetPlatform entries to my custom AssemblyInfo.cs.
Issue Description
When, in the csproj file, GenerateAssemblyInfo is false and EnablePreviewFeatures is true, the compiler/analyser does not warn that EnablePreviewFeatures is automatically ignored due to GenerateAssemblyInfo is false. A developer can struggle some time before finding the reason.
I first reported this to roslyn-analyzers, and buyaa-n suggested MSBuild might be in charge of such warning.
Steps to Reproduce
static abstract void A();
<EnablePreviewFeatures>True</EnablePreviewFeatures>
to the csproj.<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
to the csproj.Code:
ClassLibrary1 2022-04-04__09_01_23.zip
Expected Behavior
A warning explaining EnablePreviewFeatures is disabled when GenerateAssemblyInfo is false and what to do.
Actual Behavior
No warning at all.
Versions & Configurations
msbuild : 17.1.0.7609
analysers:
.NET SDKs installed: 5.0.405 6.0.200 6.0.201
Also tried (with same error) NuGet package : Microsoft.CodeAnalysis.NetAnalyzers Version=6.0.0