<Project> <Target Name="AddGlobalAnalyzerConfigForPackage_MicrosoftCodeAnalysisBannedApiAnalyzers" BeforeTargets="CoreCompile" Condition="'$(SkipGlobalAnalyzerConfigForPackage)' != 'true'"> <!-- PropertyGroup to compute global analyzer config file to be used --> <PropertyGroup> <!-- Set the default analysis mode, if not set by the user --> <_GlobalAnalyzerConfigAnalysisMode_MicrosoftCodeAnalysisBannedApiAnalyzers>$(AnalysisLevelSuffix)</_GlobalAnalyzerConfigAnalysisMode_MicrosoftCodeAnalysisBannedApiAnalyzers> <_GlobalAnalyzerConfigAnalysisMode_MicrosoftCodeAnalysisBannedApiAnalyzers Condition="'$(_GlobalAnalyzerConfigAnalysisMode_MicrosoftCodeAnalysisBannedApiAnalyzers)' == ''">$(AnalysisMode)</_GlobalAnalyzerConfigAnalysisMode_MicrosoftCodeAnalysisBannedApiAnalyzers> <_GlobalAnalyzerConfigAnalysisMode_MicrosoftCodeAnalysisBannedApiAnalyzers Condition="'$(_GlobalAnalyzerConfigAnalysisMode_MicrosoftCodeAnalysisBannedApiAnalyzers)' == 'AllEnabledByDefault'">All</_GlobalAnalyzerConfigAnalysisMode_MicrosoftCodeAnalysisBannedApiAnalyzers> <_GlobalAnalyzerConfigAnalysisMode_MicrosoftCodeAnalysisBannedApiAnalyzers Condition="'$(_GlobalAnalyzerConfigAnalysisMode_MicrosoftCodeAnalysisBannedApiAnalyzers)' == 'AllDisabledByDefault'">None</_GlobalAnalyzerConfigAnalysisMode_MicrosoftCodeAnalysisBannedApiAnalyzers> <_GlobalAnalyzerConfigAnalysisMode_MicrosoftCodeAnalysisBannedApiAnalyzers Condition="'$(_GlobalAnalyzerConfigAnalysisMode_MicrosoftCodeAnalysisBannedApiAnalyzers)' == ''">Default</_GlobalAnalyzerConfigAnalysisMode_MicrosoftCodeAnalysisBannedApiAnalyzers> <!-- Default 'EffectiveCodeAnalysisTreatWarningsAsErrors' to 'CodeAnalysisTreatWarningsAsErrors' for escalating relevant code analysis warnings to errors. --> <!-- We use a separate property to allow users to override 'CodeAnalysisTreatWarningsAsErrors' implementation from .NET7 or older SDK, which had a known issue: https://github.com/dotnet/roslyn-analyzers/issues/6281 --> <EffectiveCodeAnalysisTreatWarningsAsErrors Condition="'$(EffectiveCodeAnalysisTreatWarningsAsErrors)' == ''">$(CodeAnalysisTreatWarningsAsErrors)</EffectiveCodeAnalysisTreatWarningsAsErrors> <!-- Choose GlobalAnalyzerConfig file with '_warnaserror' suffix if 'EffectiveCodeAnalysisTreatWarningsAsErrors' is 'true'. --> <_GlobalAnalyzerConfigFileName_MicrosoftCodeAnalysisBannedApiAnalyzers_WarnAsErrorSuffix Condition="'$(EffectiveCodeAnalysisTreatWarningsAsErrors)' == 'true'">_warnaserror</_GlobalAnalyzerConfigFileName_MicrosoftCodeAnalysisBannedApiAnalyzers_WarnAsErrorSuffix> <!-- GlobalAnalyzerConfig file name based on user specified package version 'MicrosoftCodeAnalysisBannedApiAnalyzersRulesVersion', if any. We replace '.' with '_' to map the version string to file name suffix. --> <_GlobalAnalyzerConfigFileName_MicrosoftCodeAnalysisBannedApiAnalyzers Condition="'$(MicrosoftCodeAnalysisBannedApiAnalyzersRulesVersion)' != ''">AnalysisLevel_$(MicrosoftCodeAnalysisBannedApiAnalyzersRulesVersion.Replace(".","_"))_$(_GlobalAnalyzerConfigAnalysisMode_MicrosoftCodeAnalysisBannedApiAnalyzers)$(_GlobalAnalyzerConfigFileName_MicrosoftCodeAnalysisBannedApiAnalyzers_WarnAsErrorSuffix).globalconfig</_GlobalAnalyzerConfigFileName_MicrosoftCodeAnalysisBannedApiAnalyzers> <_GlobalAnalyzerConfigFileName_MicrosoftCodeAnalysisBannedApiAnalyzers>$(_GlobalAnalyzerConfigFileName_MicrosoftCodeAnalysisBannedApiAnalyzers.ToLowerInvariant())</_GlobalAnalyzerConfigFileName_MicrosoftCodeAnalysisBannedApiAnalyzers> <_GlobalAnalyzerConfigDir_MicrosoftCodeAnalysisBannedApiAnalyzers Condition="'$(_GlobalAnalyzerConfigDir_MicrosoftCodeAnalysisBannedApiAnalyzers)' == ''">$(MSBuildThisFileDirectory)config</_GlobalAnalyzerConfigDir_MicrosoftCodeAnalysisBannedApiAnalyzers> <_GlobalAnalyzerConfigFile_MicrosoftCodeAnalysisBannedApiAnalyzers Condition="'$(_GlobalAnalyzerConfigFileName_MicrosoftCodeAnalysisBannedApiAnalyzers)' != ''">$(_GlobalAnalyzerConfigDir_MicrosoftCodeAnalysisBannedApiAnalyzers)\$(_GlobalAnalyzerConfigFileName_MicrosoftCodeAnalysisBannedApiAnalyzers)</_GlobalAnalyzerConfigFile_MicrosoftCodeAnalysisBannedApiAnalyzers> </PropertyGroup> <ItemGroup Condition="Exists('$(_GlobalAnalyzerConfigFile_MicrosoftCodeAnalysisBannedApiAnalyzers)')"> <EditorConfigFiles Include="$(_GlobalAnalyzerConfigFile_MicrosoftCodeAnalysisBannedApiAnalyzers)" /> </ItemGroup> </Target> <Target Name="AddGlobalAnalyzerConfigForPackage_MicrosoftCodeAnalysisBannedApiAnalyzersApiDesign" BeforeTargets="CoreCompile" AfterTargets="AddGlobalAnalyzerConfigForPackage_MicrosoftCodeAnalysisBannedApiAnalyzers" Condition="'$(SkipGlobalAnalyzerConfigForPackage)' != 'true' and ('$(AnalysisLevelApiDesign)' != '' or '$(AnalysisModeApiDesign)' != '')"> <!-- PropertyGroup to compute global analyzer config file to be used --> <PropertyGroup> <!-- Set the default analysis mode, if not set by the user --> <_GlobalAnalyzerConfigAnalysisMode_MicrosoftCodeAnalysisBannedApiAnalyzersApiDesign>$(AnalysisLevelSuffixApiDesign)</_GlobalAnalyzerConfigAnalysisMode_MicrosoftCodeAnalysisBannedApiAnalyzersApiDesign> <_GlobalAnalyzerConfigAnalysisMode_MicrosoftCodeAnalysisBannedApiAnalyzersApiDesign Condition="'$(_GlobalAnalyzerConfigAnalysisMode_MicrosoftCodeAnalysisBannedApiAnalyzersApiDesign)' == ''">$(AnalysisModeApiDesign)</_GlobalAnalyzerConfigAnalysisMode_MicrosoftCodeAnalysisBannedApiAnalyzersApiDesign> <_GlobalAnalyzerConfigAnalysisMode_MicrosoftCodeAnalysisBannedApiAnalyzersApiDesign Condition="'$(_GlobalAnalyzerConfigAnalysisMode_MicrosoftCodeAnalysisBannedApiAnalyzersApiDesign)' == 'AllEnabledByDefault'">All</_GlobalAnalyzerConfigAnalysisMode_MicrosoftCodeAnalysisBannedApiAnalyzersApiDesign> <_GlobalAnalyzerConfigAnalysisMode_MicrosoftCodeAnalysisBannedApiAnalyzersApiDesign Condition="'$(_GlobalAnalyzerConfigAnalysisMode_MicrosoftCodeAnalysisBannedApiAnalyzersApiDesign)' == 'AllDisabledByDefault'">None</_GlobalAnalyzerConfigAnalysisMode_MicrosoftCodeAnalysisBannedApiAnalyzersApiDesign> <_GlobalAnalyzerConfigAnalysisMode_MicrosoftCodeAnalysisBannedApiAnalyzersApiDesign Condition="'$(_GlobalAnalyzerConfigAnalysisMode_MicrosoftCodeAnalysisBannedApiAnalyzersApiDesign)' == ''">Default</_GlobalAnalyzerConfigAnalysisMode_MicrosoftCodeAnalysisBannedApiAnalyzersApiDesign> <!-- Default 'EffectiveCodeAnalysisTreatWarningsAsErrors' to 'CodeAnalysisTreatWarningsAsErrors' for escalating relevant code analysis warnings to errors. --> <!-- We use a separate property to allow users to override 'CodeAnalysisTreatWarningsAsErrors' implementation from .NET7 or older SDK, which had a known issue: https://github.com/dotnet/roslyn-analyzers/issues/6281 --> <EffectiveCodeAnalysisTreatWarningsAsErrors Condition="'$(EffectiveCodeAnalysisTreatWarningsAsErrors)' == ''">$(CodeAnalysisTreatWarningsAsErrors)</EffectiveCodeAnalysisTreatWarningsAsErrors> <!-- Choose GlobalAnalyzerConfig file with '_warnaserror' suffix if 'EffectiveCodeAnalysisTreatWarningsAsErrors' is 'true'. --> <_GlobalAnalyzerConfigFileName_MicrosoftCodeAnalysisBannedApiAnalyzersApiDesign_WarnAsErrorSuffix Condition="'$(EffectiveCodeAnalysisTreatWarningsAsErrors)' == 'true'">_warnaserror</_GlobalAnalyzerConfigFileName_MicrosoftCodeAnalysisBannedApiAnalyzersApiDesign_WarnAsErrorSuffix> <!-- GlobalAnalyzerConfig file name based on user specified package version 'MicrosoftCodeAnalysisBannedApiAnalyzersApiDesignRulesVersion', if any. We replace '.' with '_' to map the version string to file name suffix. --> <_GlobalAnalyzerConfigFileName_MicrosoftCodeAnalysisBannedApiAnalyzersApiDesign Condition="'$(MicrosoftCodeAnalysisBannedApiAnalyzersApiDesignRulesVersion)' != ''">AnalysisLevelApiDesign_$(MicrosoftCodeAnalysisBannedApiAnalyzersApiDesignRulesVersion.Replace(".","_"))_$(_GlobalAnalyzerConfigAnalysisMode_MicrosoftCodeAnalysisBannedApiAnalyzersApiDesign)$(_GlobalAnalyzerConfigFileName_MicrosoftCodeAnalysisBannedApiAnalyzersApiDesign_WarnAsErrorSuffix).globalconfig</_GlobalAnalyzerConfigFileName_MicrosoftCodeAnalysisBannedApiAnalyzersApiDesign> <_GlobalAnalyzerConfigFileName_MicrosoftCodeAnalysisBannedApiAnalyzersApiDesign>$(_GlobalAnalyzerConfigFileName_MicrosoftCodeAnalysisBannedApiAnalyzersApiDesign.ToLowerInvariant())</_GlobalAnalyzerConfigFileName_MicrosoftCodeAnalysisBannedApiAnalyzersApiDesign> <_GlobalAnalyzerConfigDir_MicrosoftCodeAnalysisBannedApiAnalyzersApiDesign Condition="'$(_GlobalAnalyzerConfigDir_MicrosoftCodeAnalysisBannedApiAnalyzersApiDesign)' == ''">$(MSBuildThisFileDirectory)config</_GlobalAnalyzerConfigDir_MicrosoftCodeAnalysisBannedApiAnalyzersApiDesign> <_GlobalAnalyzerConfigFile_MicrosoftCodeAnalysisBannedApiAnalyzersApiDesign Condition="'$(_GlobalAnalyzerConfigFileName_MicrosoftCodeAnalysisBannedApiAnalyzersApiDesign)' != ''">$(_GlobalAnalyzerConfigDir_MicrosoftCodeAnalysisBannedApiAnalyzersApiDesign)\$(_GlobalAnalyzerConfigFileName_MicrosoftCodeAnalysisBannedApiAnalyzersApiDesign)</_GlobalAnalyzerConfigFile_MicrosoftCodeAnalysisBannedApiAnalyzersApiDesign> </PropertyGroup> <ItemGroup Condition="Exists('$(_GlobalAnalyzerConfigFile_MicrosoftCodeAnalysisBannedApiAnalyzersApiDesign)')"> <EditorConfigFiles Include="$(_GlobalAnalyzerConfigFile_MicrosoftCodeAnalysisBannedApiAnalyzersApiDesign)" /> </ItemGroup> </Target> <!-- MSBuild properties to thread to the analyzers as options --> <ItemGroup> <CompilerVisibleProperty Include="TargetFramework" /> <CompilerVisibleProperty Include="TargetPlatformMinVersion" /> <CompilerVisibleProperty Include="UsingMicrosoftNETSdkWeb" /> <CompilerVisibleProperty Include="ProjectTypeGuids" /> <CompilerVisibleProperty Include="InvariantGlobalization" /> <CompilerVisibleProperty Include="PlatformNeutralAssembly" /> <CompilerVisibleProperty Include="EnforceExtendedAnalyzerRules" /> </ItemGroup> <!-- MSBuild item metadata to thread to the analyzers as options --> <PropertyGroup> <_SupportedPlatformList>@(SupportedPlatform, ',')</_SupportedPlatformList> </PropertyGroup> <!-- MSBuild properties to thread to the analyzers as options --> <ItemGroup> <CompilerVisibleProperty Include="_SupportedPlatformList" /> </ItemGroup> </Project> |