Skip to content

Reference ILLink analyzer matching ILLink version #32045

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

Merged
merged 11 commits into from
May 31, 2023
4 changes: 0 additions & 4 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,6 @@
<Uri>https://github.com/dotnet/runtime</Uri>
<Sha>bf7fb2ecbf69deb6a73bb8bbca1e56e7beec8d8a</Sha>
</Dependency>
<Dependency Name="Microsoft.NET.ILLink.Analyzers" Version="8.0.100-1.23067.1">
<Uri>https://github.com/dotnet/linker</Uri>
<Sha>c790896f128957acd2999208f44f09ae1e826c8c</Sha>
</Dependency>
Comment on lines -128 to -131
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the corresponding version number be removed from Versions.props? Otherwise I believe it will still be there and available for use, but won't ever get updated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we were using the ILLink.Tasks package version, and this Version.Details.xml version was never used. I removed the ILLink.Tasks packagereference and cleaned up some left-over analyzer layout logic that was using it.

I left in the ILLink.Tasks entry in Versions.props and Version.Details.xml even though these are technically unused. We test with an ILLink.Tasks version matching MicrosoftNETCoreAppRefPackageVersion, which should always be the same, but it kind of seems nice to make the dependency explicit at least in Versions.props. Let me know if you'd prefer me to remove it and I will.

<Dependency Name="System.CodeDom" Version="8.0.0-preview.6.23280.5">
<Uri>https://github.com/dotnet/runtime</Uri>
<Sha>bf7fb2ecbf69deb6a73bb8bbca1e56e7beec8d8a</Sha>
Expand Down
1 change: 0 additions & 1 deletion src/Layout/redist/redist.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="$(MicrosoftCodeAnalysisNetAnalyzersVersion)" ExcludeAssets="All" GeneratePathProperty="true"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="$(MicrosoftNetCompilersToolsetPackageVersion)" ExcludeAssets="All" GeneratePathProperty="true"/>
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.CodeStyle" Version="$(MicrosoftNetCompilersToolsetPackageVersion)" ExcludeAssets="All" GeneratePathProperty="true"/>
<PackageReference Include="Microsoft.NET.ILLink.Tasks" Version="$(MicrosoftNETILLinkTasksPackageVersion)" ExcludeAssets="All" GeneratePathProperty="true" />
<PackageReference Include="Microsoft.FSharp.Compiler" Version="$(MicrosoftFSharpCompilerPackageVersion)" ExcludeAssets="All" GeneratePathProperty="true" />
<PackageReference Include="Microsoft.NET.Sdk.Razor.SourceGenerators.Transport" Version="$(MicrosoftNETSdkRazorSourceGeneratorsTransportPackageVersion)" GeneratePathProperty="true" />

Expand Down
5 changes: 0 additions & 5 deletions src/Layout/redist/targets/GenerateLayout.targets
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@
<AnalyzerTargets Include="$(PkgMicrosoft_CodeAnalysis_NetAnalyzers)/buildTransitive/Microsoft.CodeAnalysis.NetAnalyzers.targets" />
<AnalyzerConfig Include="$(PkgMicrosoft_CodeAnalysis_NetAnalyzers)/buildTransitive/config/**/*" />

<ILLinkAnalyzersTargets Include="$(PkgMicrosoft_NET_ILLink_Tasks)/build/Microsoft.NET.ILLink.Analyzers.props" />
<ILLinkAnalyzersAssemblies Include="$(PkgMicrosoft_NET_ILLink_Tasks)/analyzers/dotnet/cs/**/*.dll" />

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

<Copy SourceFiles="@(AnalyzerAssemblies)" DestinationFiles="@(AnalyzerAssemblies->'$(AnalyzerAssembliesDirectory)/%(RecursiveDir)%(Filename)%(Extension)')" />
<Copy SourceFiles="@(AnalyzerTargets)" DestinationFiles="@(AnalyzerTargets->'$(AnalyzerTargetsDirectory)/%(RecursiveDir)%(Filename)%(Extension)')" />
Expand Down
13 changes: 11 additions & 2 deletions src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class ProcessFrameworkReferences : TaskBase

public bool ReadyToRunUseCrossgen2 { get; set; }

public bool TrimmingEnabled { get; set; }
public bool RequiresILLinkPack { get; set; }

public bool AotEnabled { get; set; }

Expand Down Expand Up @@ -384,7 +384,7 @@ var runtimeRequiredByDeployment
}
}

if (TrimmingEnabled)
if (RequiresILLinkPack)
{
if (!AddToolPack(ToolPackType.ILLink, _normalizedTargetFrameworkVersion, packagesToDownload, implicitPackageReferences))
{
Expand Down Expand Up @@ -712,6 +712,15 @@ private bool AddToolPack(
implicitPackageReferences.Add(buildPackage);
}

// Before net8.0, ILLink analyzers shipped in a separate package.
// Add the analyzer package with version taken from KnownILLinkPack.
if (normalizedTargetFrameworkVersion < new Version(8, 0) && toolPackType is ToolPackType.ILLink)
{
var analyzerPackage = new TaskItem("Microsoft.NET.ILLink.Analyzers");
analyzerPackage.SetMetadata(MetadataKeys.Version, packVersion);
implicitPackageReferences.Add(analyzerPackage);
Comment on lines +719 to +721
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious: where do we download this from? It seems it's not on NuGet... is the SDK adding some other public feeds for this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's downloaded from NuGet: https://www.nuget.org/packages/Microsoft.NET.ILLink.Analyzers/

For internal builds the specific version would be available on an internal feed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That package was submitted by mistake - it only has one 8.0 preview version, it definitely doesn't contain downlevel versions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll ask for it to be uploaded to nuget.

}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ Copyright (c) .NET Foundation. All rights reserved.
<!-- PublishAot depends on PublishTrimmed. This must be set early enough for the KnownILLinkPack to be restored. -->
<PublishTrimmed Condition="'$(PublishTrimmed)' == '' And '$(PublishAot)' == 'true'">true</PublishTrimmed>
<IsTrimmable Condition="'$(IsTrimmable)' == '' and '$(IsAotCompatible)' == 'true'">true</IsTrimmable>
<_IsTrimmingEnabled Condition="'$(_IsTrimmingEnabled)' == '' And ('$(PublishTrimmed)' == 'true' Or '$(IsTrimmable)' == 'true')">true</_IsTrimmingEnabled>
<_IsTrimmingEnabled Condition="'$(_IsTrimmingEnabled)' == ''">false</_IsTrimmingEnabled>
<_RequiresILLinkPack Condition="'$(_RequiresILLinkPack)' == '' And (
'$(PublishTrimmed)' == 'true' Or
'$(PublishSingleFile)' == 'true' Or
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename _IsTrimmingEnabled? It doesn't seem like a good name anymore, if we are setting it to true when I only set PublishSingleFile.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dotnet/runtime uses that property already. @sbomer can you please take care of updating it when these changes are being consumed? https://github.com/dotnet/runtime/blob/98dd1e83ba8b17299af9d3d78000f8a9c000a12e/eng/illink.targets#L5C1-L6

'$(IsTrimmable)' == 'true' Or
'$(EnableAotAnalyzer)' == 'true' Or
'$(EnableTrimAnalyzer)' == 'true' Or
'$(EnableSingleFileAnalyzer)' == 'true')">true</_RequiresILLinkPack>
<_RequiresILLinkPack Condition="'$(_RequiresILLinkPack)' == ''">false</_RequiresILLinkPack>
<DynamicCodeSupport Condition="'$(DynamicCodeSupport)' == '' And '$(PublishAot)' == 'true'">false</DynamicCodeSupport>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ Copyright (c) .NET Foundation. All rights reserved.
Condition="'$(Language)' == 'C#' Or '$(Language)' == 'VB'" />
<Import Project="$(MSBuildThisFileDirectory)..\analyzers\build\Microsoft.CodeAnalysis.NetAnalyzers.targets"
Condition="$(EnableNETAnalyzers)" />
<Import Project="$(MSBuildThisFileDirectory)..\analyzers\build\Microsoft.NET.ILLink.Analyzers.props"
Condition="'$(EnableSingleFileAnalyzer)' == 'true' Or '$(EnableTrimAnalyzer)' == 'true' Or '$(EnableAotAnalyzer)' == 'true'" />

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

<!-- ILLinker Analyzers -->
<ItemGroup Condition="'$(EnableSingleFileAnalyzer)' == 'true' Or '$(EnableTrimAnalyzer)' == 'true' Or '$(EnableAotAnalyzer)' == 'true'">
<Analyzer
Include="$(MSBuildThisFileDirectory)..\analyzers\ILLink.*.dll"
IsImplicitlyDefined="true" />
</ItemGroup>

<!-- CompilerVisibleProperties for .NET -->
<ItemGroup Condition="'$(Language)' == 'C#' Or '$(Language)' == 'VB'">
<!-- Used for analyzer to match namespace to folder structure -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Copyright (c) .NET Foundation. All rights reserved.
SelfContained="$(SelfContained)"
ReadyToRunEnabled="$(PublishReadyToRun)"
ReadyToRunUseCrossgen2="$(PublishReadyToRunUseCrossgen2)"
TrimmingEnabled="$(_IsTrimmingEnabled)"
RequiresILLinkPack="$(_RequiresILLinkPack)"
AotEnabled="$(PublishAot)"
AotUseKnownRuntimePackForTarget="$(PublishAotUsingRuntimePack)"
RuntimeIdentifier="$(RuntimeIdentifier)"
Expand Down
Loading