Skip to content

Commit b59a9ed

Browse files
authored
Reference ILLink analyzer matching ILLink version (#32045)
We were already referencing the analyzer from the ILLink package on net8.0, so there we only needed to remove the bundled analyzer to fix dotnet/runtime#84119. For older TFMs, we currently use the latest analyzer that's bundled with the SDK. I replaced this with logic to use a packagreference, matching the version of ILLink. Note that with this change, when targeting downlevel TFMs the 8.0 SDK will use the 7.0 analyzer instead of the 8.0 analyzer that we use today.
1 parent 0e048cb commit b59a9ed

File tree

8 files changed

+93
-49
lines changed

8 files changed

+93
-49
lines changed

eng/Version.Details.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,6 @@
125125
<Uri>https://github.com/dotnet/runtime</Uri>
126126
<Sha>bf7fb2ecbf69deb6a73bb8bbca1e56e7beec8d8a</Sha>
127127
</Dependency>
128-
<Dependency Name="Microsoft.NET.ILLink.Analyzers" Version="8.0.100-1.23067.1">
129-
<Uri>https://github.com/dotnet/linker</Uri>
130-
<Sha>c790896f128957acd2999208f44f09ae1e826c8c</Sha>
131-
</Dependency>
132128
<Dependency Name="System.CodeDom" Version="8.0.0-preview.6.23280.5">
133129
<Uri>https://github.com/dotnet/runtime</Uri>
134130
<Sha>bf7fb2ecbf69deb6a73bb8bbca1e56e7beec8d8a</Sha>

src/Layout/redist/redist.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="$(MicrosoftCodeAnalysisNetAnalyzersVersion)" ExcludeAssets="All" GeneratePathProperty="true"/>
3636
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="$(MicrosoftNetCompilersToolsetPackageVersion)" ExcludeAssets="All" GeneratePathProperty="true"/>
3737
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.CodeStyle" Version="$(MicrosoftNetCompilersToolsetPackageVersion)" ExcludeAssets="All" GeneratePathProperty="true"/>
38-
<PackageReference Include="Microsoft.NET.ILLink.Tasks" Version="$(MicrosoftNETILLinkTasksPackageVersion)" ExcludeAssets="All" GeneratePathProperty="true" />
3938
<PackageReference Include="Microsoft.FSharp.Compiler" Version="$(MicrosoftFSharpCompilerPackageVersion)" ExcludeAssets="All" GeneratePathProperty="true" />
4039
<PackageReference Include="Microsoft.NET.Sdk.Razor.SourceGenerators.Transport" Version="$(MicrosoftNETSdkRazorSourceGeneratorsTransportPackageVersion)" GeneratePathProperty="true" />
4140

src/Layout/redist/targets/GenerateLayout.targets

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@
5757
<AnalyzerTargets Include="$(PkgMicrosoft_CodeAnalysis_NetAnalyzers)/buildTransitive/Microsoft.CodeAnalysis.NetAnalyzers.targets" />
5858
<AnalyzerConfig Include="$(PkgMicrosoft_CodeAnalysis_NetAnalyzers)/buildTransitive/config/**/*" />
5959

60-
<ILLinkAnalyzersTargets Include="$(PkgMicrosoft_NET_ILLink_Tasks)/build/Microsoft.NET.ILLink.Analyzers.props" />
61-
<ILLinkAnalyzersAssemblies Include="$(PkgMicrosoft_NET_ILLink_Tasks)/analyzers/dotnet/cs/**/*.dll" />
62-
6360
<CodeStyleCSharpAssemblies Include="$(PkgMicrosoft_CodeAnalysis_CSharp_CodeStyle)/analyzers/dotnet/cs/**/*.dll" />
6461
<CodeStyleVisualBasicAssemblies Include="$(PkgMicrosoft_CodeAnalysis_VisualBasic_CodeStyle)/analyzers/dotnet/vb/**/*.dll" />
6562
<!-- The props files from these packages explicitly say they should never be included in the SDK -->
@@ -78,8 +75,6 @@
7875
<Error Condition="'@(CodeStyleVisualBasicTargets)' == ''" Text="Something moved around in Code style packeges, could not find targets/props. Adjust code here accordingly. TFM change?" />
7976
<Error Condition="'@(CodeStyleCSharpConfig)' == ''" Text="Something moved around in Code style packeges, could not find globalconfig files. Adjust code here accordingly. TFM change?" />
8077
<Error Condition="'@(CodeStyleVisualBasicConfig)' == ''" Text="Something moved around in Code style packeges, could not find globalconfig files. Adjust code here accordingly. TFM change?" />
81-
<Error Condition="'@(ILLinkAnalyzersTargets)' == ''" Text="Something moved around in ILLink Analyzers package, adjust code accordingly." />
82-
<Error Condition="'@(ILLinkAnalyzersAssemblies)' == ''" Text="Something moved around in ILLink Analyzers package, adjust code accordingly." />
8378

8479
<Copy SourceFiles="@(AnalyzerAssemblies)" DestinationFiles="@(AnalyzerAssemblies->'$(AnalyzerAssembliesDirectory)/%(RecursiveDir)%(Filename)%(Extension)')" />
8580
<Copy SourceFiles="@(AnalyzerTargets)" DestinationFiles="@(AnalyzerTargets->'$(AnalyzerTargetsDirectory)/%(RecursiveDir)%(Filename)%(Extension)')" />

src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class ProcessFrameworkReferences : TaskBase
4444

4545
public bool ReadyToRunUseCrossgen2 { get; set; }
4646

47-
public bool TrimmingEnabled { get; set; }
47+
public bool RequiresILLinkPack { get; set; }
4848

4949
public bool AotEnabled { get; set; }
5050

@@ -384,7 +384,7 @@ var runtimeRequiredByDeployment
384384
}
385385
}
386386

387-
if (TrimmingEnabled)
387+
if (RequiresILLinkPack)
388388
{
389389
if (!AddToolPack(ToolPackType.ILLink, _normalizedTargetFrameworkVersion, packagesToDownload, implicitPackageReferences))
390390
{
@@ -712,6 +712,15 @@ private bool AddToolPack(
712712
implicitPackageReferences.Add(buildPackage);
713713
}
714714

715+
// Before net8.0, ILLink analyzers shipped in a separate package.
716+
// Add the analyzer package with version taken from KnownILLinkPack.
717+
if (normalizedTargetFrameworkVersion < new Version(8, 0) && toolPackType is ToolPackType.ILLink)
718+
{
719+
var analyzerPackage = new TaskItem("Microsoft.NET.ILLink.Analyzers");
720+
analyzerPackage.SetMetadata(MetadataKeys.Version, packVersion);
721+
implicitPackageReferences.Add(analyzerPackage);
722+
}
723+
715724
return true;
716725
}
717726

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,14 @@ Copyright (c) .NET Foundation. All rights reserved.
2222
<!-- PublishAot depends on PublishTrimmed. This must be set early enough for the KnownILLinkPack to be restored. -->
2323
<PublishTrimmed Condition="'$(PublishTrimmed)' == '' And '$(PublishAot)' == 'true'">true</PublishTrimmed>
2424
<IsTrimmable Condition="'$(IsTrimmable)' == '' and '$(IsAotCompatible)' == 'true'">true</IsTrimmable>
25-
<_IsTrimmingEnabled Condition="'$(_IsTrimmingEnabled)' == '' And ('$(PublishTrimmed)' == 'true' Or '$(IsTrimmable)' == 'true')">true</_IsTrimmingEnabled>
26-
<_IsTrimmingEnabled Condition="'$(_IsTrimmingEnabled)' == ''">false</_IsTrimmingEnabled>
25+
<_RequiresILLinkPack Condition="'$(_RequiresILLinkPack)' == '' And (
26+
'$(PublishTrimmed)' == 'true' Or
27+
'$(PublishSingleFile)' == 'true' Or
28+
'$(IsTrimmable)' == 'true' Or
29+
'$(EnableAotAnalyzer)' == 'true' Or
30+
'$(EnableTrimAnalyzer)' == 'true' Or
31+
'$(EnableSingleFileAnalyzer)' == 'true')">true</_RequiresILLinkPack>
32+
<_RequiresILLinkPack Condition="'$(_RequiresILLinkPack)' == ''">false</_RequiresILLinkPack>
2733
<DynamicCodeSupport Condition="'$(DynamicCodeSupport)' == '' And '$(PublishAot)' == 'true'">false</DynamicCodeSupport>
2834
</PropertyGroup>
2935

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.Analyzers.targets

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ Copyright (c) .NET Foundation. All rights reserved.
101101
Condition="'$(Language)' == 'C#' Or '$(Language)' == 'VB'" />
102102
<Import Project="$(MSBuildThisFileDirectory)..\analyzers\build\Microsoft.CodeAnalysis.NetAnalyzers.targets"
103103
Condition="$(EnableNETAnalyzers)" />
104-
<Import Project="$(MSBuildThisFileDirectory)..\analyzers\build\Microsoft.NET.ILLink.Analyzers.props"
105-
Condition="'$(EnableSingleFileAnalyzer)' == 'true' Or '$(EnableTrimAnalyzer)' == 'true' Or '$(EnableAotAnalyzer)' == 'true'" />
106104

107105
<Import Project="$(MSBuildThisFileDirectory)..\codestyle\cs\build\Microsoft.CodeAnalysis.CSharp.CodeStyle.targets"
108106
Condition="$(EnforceCodeStyleInBuild) And '$(Language)' == 'C#'" />
@@ -124,13 +122,6 @@ Copyright (c) .NET Foundation. All rights reserved.
124122
IsImplicitlyDefined="true" />
125123
</ItemGroup>
126124

127-
<!-- ILLinker Analyzers -->
128-
<ItemGroup Condition="'$(EnableSingleFileAnalyzer)' == 'true' Or '$(EnableTrimAnalyzer)' == 'true' Or '$(EnableAotAnalyzer)' == 'true'">
129-
<Analyzer
130-
Include="$(MSBuildThisFileDirectory)..\analyzers\ILLink.*.dll"
131-
IsImplicitlyDefined="true" />
132-
</ItemGroup>
133-
134125
<!-- CompilerVisibleProperties for .NET -->
135126
<ItemGroup Condition="'$(Language)' == 'C#' Or '$(Language)' == 'VB'">
136127
<!-- Used for analyzer to match namespace to folder structure -->

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Copyright (c) .NET Foundation. All rights reserved.
9999
SelfContained="$(SelfContained)"
100100
ReadyToRunEnabled="$(PublishReadyToRun)"
101101
ReadyToRunUseCrossgen2="$(PublishReadyToRunUseCrossgen2)"
102-
TrimmingEnabled="$(_IsTrimmingEnabled)"
102+
RequiresILLinkPack="$(_RequiresILLinkPack)"
103103
AotEnabled="$(PublishAot)"
104104
AotUseKnownRuntimePackForTarget="$(PublishAotUsingRuntimePack)"
105105
RuntimeIdentifier="$(RuntimeIdentifier)"

0 commit comments

Comments
 (0)