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

Couple fixes for UseSystemResourceKeys #103463

Merged
merged 7 commits into from
Jun 17, 2024

Conversation

MichalStrehovsky
Copy link
Member

@MichalStrehovsky MichalStrehovsky commented Jun 14, 2024

Fixes #102303.

  • Set a default value for the feature switch
  • Make it possible to preinitialize the static constructor
  • Fix generation of substitutions XML
  • Update SR.vb to match SR.cs
  • Fix resources in System.Diagnostics.FileVersionInfo.csproj

@dotnet/illink

…blish time

Fixes dotnet#96539.
Fixes dotnet#102303.

Two possible approaches were discussed in dotnet#96539 but doing it in illinker feels more straightforward.
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-Tools-ILLink .NET linker development as well as trimming analyzers label Jun 14, 2024
Copy link
Contributor

Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas
See info in area-owners.md if you want to be subscribed.

<resource name="{StringResourcesName}.resources" action="remove" />
<type fullname="System.SR">
<method signature="System.Boolean UsingResourceKeys()" body="stub" value="true" />
<method signature="System.Boolean GetUsingResourceKeysSwitchValue()" body="stub" value="true" />
Copy link
Member Author

Choose a reason for hiding this comment

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

This is #95948 as a proof that it works.

@@ -37,7 +37,7 @@
<ILLinkRewritePDBs Condition="'$(ILLinkRewritePDBs)' == ''">true</ILLinkRewritePDBs>

<ILLinkResourcesSubstitutionIntermediatePath>$(IntermediateOutputPath)ILLink.Resources.Substitutions.xml</ILLinkResourcesSubstitutionIntermediatePath>
<GenerateResourcesSubstitutions Condition="'$(GenerateResourcesSubstitutions)' == '' and '$(StringResourcesPath)' != ''">true</GenerateResourcesSubstitutions>
<GenerateResourcesSubstitutions Condition="'$(GenerateResourcesSubstitutions)' == '' and '$(StringResourcesPath)' != '' and '$(OmitResources)' != 'true'">true</GenerateResourcesSubstitutions>
Copy link
Member Author

Choose a reason for hiding this comment

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

OmitResources is an existing mechanism to prevent generating resx. It was a bug that we'd still generate a substitution file when this was set.

Public Shared Function UsingResourceKeys() As Boolean
Return False
Return s_usingResourceKeys
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 synchronized SR.vb with SR.cs that we apparently neglected for years.

@@ -9,7 +9,8 @@
<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
<PropertyGroup>
<TargetPlatformIdentifier>$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)'))</TargetPlatformIdentifier>
<GeneratePlatformNotSupportedAssemblyMessage Condition="'$(TargetPlatformIdentifier)' == ''">SR.DiagnosticsFileVersionInfo_PlatformNotSupported</GeneratePlatformNotSupportedAssemblyMessage>
<GeneratePlatformNotSupportedAssemblyMessage Condition="'$(TargetPlatformIdentifier)' == ''">SR.DiagnosticsFileVersionInfo_PlatformNotSupported</GeneratePlatformNotSupportedAssemblyMessage>
<OmitResources Condition="'$(GeneratePlatformNotSupportedAssemblyMessage)' == ''">true</OmitResources>
Copy link
Member Author

@MichalStrehovsky MichalStrehovsky Jun 14, 2024

Choose a reason for hiding this comment

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

Bugfix for a customer reported issue linked from top post that I ran into myself while working on this (not sure if it's needed in this PR or it could be separated out, but I sure don't want to rebuild libraries to see if I still get a warning).

The problem was that only the PlatformNotSupported flavor of the assembly needs resource strings, but we were generating the SR class/resources/substitution anyway. Customers were getting warnings for this (see the issue for the warning).

Copy link
Member

@sbomer sbomer left a comment

Choose a reason for hiding this comment

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

Code changes LGTM but I wonder if we actually need this (see my other comment).

private static readonly bool s_usingResourceKeys = GetUsingResourceKeysSwitchValue();

// This method is a target of ILLink substitution.
private static bool GetUsingResourceKeysSwitchValue() => AppContext.TryGetSwitch("System.Resources.UseSystemResourceKeys", out bool usingResourceKeys) ? usingResourceKeys : false;
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 this could be changed to use FeatureSwitchDefinition, and then instead of featuredefault, set the defaults in Microsoft.NET.ILLink.targets. Do you see any problems with that?

If possible I'd prefer to move away from the XML for feature switches. If we can do so here, I wonder if we still need #96539 at all.

Copy link
Member

Choose a reason for hiding this comment

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

I also realized that featuredefault is potentially problematic because it could result in feature switches being substituted even without the corresponding AppContext setting. I'm starting to think we should avoid featuredefault entirely.

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 think this could be changed to use FeatureSwitchDefinition, and then instead of featuredefault, set the defaults in Microsoft.NET.ILLink.targets. Do you see any problems with that?

Much simpler. Surprising nobody thought of this in the issue, we already had the facilities. FeatureSwitchDefinition didn't look necessary so I didn't add it - it wasn't clear to me what it would buy here.

Copy link
Member

Choose a reason for hiding this comment

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

FeatureSwitchDefinition could let us get rid of some XML, but isn't necessary.

Copy link
Member

@sbomer sbomer left a comment

Choose a reason for hiding this comment

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

LGTM, thank you! (PR title should be updated)

@MichalStrehovsky MichalStrehovsky changed the title Make it possible for featuredefault substitutions to only apply at publish time Couple fixes for UseSystemResourceKeys Jun 17, 2024
@MichalStrehovsky MichalStrehovsky merged commit a0b8890 into dotnet:main Jun 17, 2024
154 of 162 checks passed
@MichalStrehovsky MichalStrehovsky deleted the fix96539 branch June 17, 2024 21:55
@github-actions github-actions bot locked and limited conversation to collaborators Jul 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Tools-ILLink .NET linker development as well as trimming analyzers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IL2008: System.Diagnostics.FileVersionInfo: Could not resolve type 'System.SR'.
2 participants