Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't enable ILLink analyzers for unsupported TFMs #87071

Merged
merged 10 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@
<!-- RepositoryEngineeringDir isn't set when Installer tests import this file. -->
<Import Project="$(RepositoryEngineeringDir)native\naming.props" />
<Import Project="$(RepositoryEngineeringDir)Subsets.props" />
<Import Project="$(RepositoryEngineeringDir)Analyzers.props" />

<PropertyGroup>
<CoreLibSharedDir>$([MSBuild]::NormalizeDirectory('$(LibrariesProjectRoot)', 'System.Private.CoreLib', 'src'))</CoreLibSharedDir>
Expand Down Expand Up @@ -383,11 +382,6 @@
<IsShipping Condition="'$(IsTestProject)' == 'true' or '$(IsTestSupportProject)' == 'true' or '$(IsPublishedAppTestProject)' == 'true'">false</IsShipping>
</PropertyGroup>

<ItemGroup Condition="'$(IsTestProject)' == 'true'">
<EditorConfigFiles Remove="$(RepositoryEngineeringDir)CodeAnalysis.src.globalconfig" />
<EditorConfigFiles Include="$(RepositoryEngineeringDir)CodeAnalysis.test.globalconfig" />
</ItemGroup>

<PropertyGroup>
<!-- Treat as a generator project if either the parent or the parent parent directory is named gen. -->
<IsGeneratorProject Condition="$([System.IO.Path]::GetFileName('$(MSBuildProjectDirectory)')) == 'gen' or
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<ImportDirectoryBuildTargets>false</ImportDirectoryBuildTargets>
</PropertyGroup>

<Import Project="$(RepositoryEngineeringDir)Analyzers.targets" />
<Import Project="Sdk.targets" Sdk="Microsoft.DotNet.Arcade.Sdk" />
<Import Project="$(RepositoryEngineeringDir)liveBuilds.targets" />
<Import Project="$(RepositoryEngineeringDir)generators.targets" />
Expand Down Expand Up @@ -35,7 +36,6 @@
unconditionally in Microsoft.NETCoreSdk.BundledVersions.props.
-->
<NETCoreAppMaximumVersion>$(MajorVersion).$(MinorVersion)</NETCoreAppMaximumVersion>
<EnableNETAnalyzers Condition="'$(EnableNETAnalyzers)' == ''">$(RunAnalyzers)</EnableNETAnalyzers>
<!-- SDK sets product to assembly but we want it to be our product name -->
<Product>Microsoft%AE .NET</Product>
<!-- Use the .NET product branding version for informational version description -->
Expand Down
2 changes: 1 addition & 1 deletion docs/project/analyzers.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This repo relies on [.NET Compiler Platform analyzers](https://learn.microsoft.c

To add an analyzer package to the build:
1. Select a package you want to employ, for example https://www.nuget.org/packages/SonarAnalyzer.CSharp/. This analyzer package's name is `SonarAnalyzer.CSharp` and the latest version as of this edit is `8.50.0.58025`.
2. Add a `PackageReference` entry to <https://github.com/dotnet/runtime/blob/main/eng/Analyzers.props>, e.g.
2. Add a `PackageReference` entry to <https://github.com/dotnet/runtime/blob/main/eng/Analyzers.targets>, e.g.
```XML
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.50.0.58025" PrivateAssets="all" />
```
Expand Down
11 changes: 9 additions & 2 deletions eng/Analyzers.props → eng/Analyzers.targets
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<Project>
<PropertyGroup>
<!-- Disable analyzers in sourcebuild -->
<RunAnalyzers Condition="'$(DotNetBuildFromSource)' == 'true'">false</RunAnalyzers>
<RunAnalyzers Condition="'$(RunAnalyzers)' == '' And '$(DotNetBuildFromSource)' == 'true'">false</RunAnalyzers>
sbomer marked this conversation as resolved.
Show resolved Hide resolved
<EnableNETAnalyzers Condition="'$(EnableNETAnalyzers)' == ''">$(RunAnalyzers)</EnableNETAnalyzers>
ViktorHofer marked this conversation as resolved.
Show resolved Hide resolved
</PropertyGroup>
<PropertyGroup Condition="'$(RunAnalyzers)' != 'false'">
<EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer>
<EnableSingleFileAnalyzer Condition="
'$(EnableSingleFileAnalyzer)' == '' And
$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'netcoreapp3.0'))">true</EnableSingleFileAnalyzer>
sbomer marked this conversation as resolved.
Show resolved Hide resolved
</PropertyGroup>
<ItemGroup Condition="'$(RunAnalyzers)' != 'false'">
<EditorConfigFiles Include="$(MSBuildThisFileDirectory)CodeAnalysis.src.globalconfig" />
Expand All @@ -13,4 +16,8 @@
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="$(MicrosoftCodeAnalysisCSharpCodeStyleVersion)" PrivateAssets="all" />
<PackageReference Include="StyleCop.Analyzers" Version="$(StyleCopAnalyzersVersion)" PrivateAssets="all" />
</ItemGroup>
<ItemGroup Condition="'$(IsTestProject)' == 'true'">
<EditorConfigFiles Remove="$(RepositoryEngineeringDir)CodeAnalysis.src.globalconfig" />
<EditorConfigFiles Include="$(RepositoryEngineeringDir)CodeAnalysis.test.globalconfig" />
</ItemGroup>
</Project>
5 changes: 4 additions & 1 deletion eng/illink.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

<PropertyGroup>
<IsTrimmable Condition="'$(IsTrimmable)' == ''">true</IsTrimmable>
<!-- Don't use SDK's trimming functionality. -->
<!-- Don't use SDK's trimming functionality.
TODO: Remove this once we build using preview 6 SDK. -->
<_IsTrimmingEnabled>false</_IsTrimmingEnabled>
<!-- Same fix for preview 6 SDK. -->
<_RequiresILLinkPack>false</_RequiresILLinkPack>
<PrepareResourcesDependsOn>_EmbedILLinkXmls;$(PrepareResourcesDependsOn)</PrepareResourcesDependsOn>
<TargetsTriggeredByCompilation Condition="'$(DesignTimeBuild)' != 'true'">$(TargetsTriggeredByCompilation);ILLinkTrimAssembly</TargetsTriggeredByCompilation>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<Import Project="..\..\Directory.Build.props" />
<Import Project="..\..\Directory.Build.targets" />
<ItemGroup>
<EditorConfigFiles Remove="$(RepositoryEngineeringDir)CodeAnalysis.src.globalconfig" />
<EditorConfigFiles Include="$(RepositoryEngineeringDir)CodeAnalysis.test.globalconfig" />
Expand Down
2 changes: 2 additions & 0 deletions src/tools/illink/src/ILLink.Tasks/ILLink.Tasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<IncludeBuildOutput>false</IncludeBuildOutput>
<IncludeMultiTargetRoslynComponentTargets>false</IncludeMultiTargetRoslynComponentTargets>
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);AddBuildOutputToToolsPackage</TargetsForTfmSpecificContentInPackage>
<!-- Disable analyzer to prevent a circular dependency due to PackageReference to the LKG Microsoft.NET.ILLink.Tasks. -->
<EnableSingleFileAnalyzer>false</EnableSingleFileAnalyzer>
</PropertyGroup>

<ItemGroup>
Expand Down