mirror of
https://github.com/VSadov/Satori.git
synced 2025-06-08 03:27:04 +09:00
Couple fixes for UseSystemResourceKeys (#103463)
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
This commit is contained in:
parent
ac996f3f48
commit
a0b8890f98
7 changed files with 32 additions and 16 deletions
|
@ -1,10 +1,16 @@
|
|||
<linker>
|
||||
<!-- System.Resources.UseSystemResourceKeys removes resource strings and instead uses the resource key as the exception message -->
|
||||
<assembly fullname="{AssemblyName}" feature="System.Resources.UseSystemResourceKeys" featurevalue="true">
|
||||
<!-- System.Resources.UseSystemResourceKeys removes resource strings and instead uses the resource key as the exception message -->
|
||||
<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" />
|
||||
</type>
|
||||
</assembly>
|
||||
<assembly fullname="{AssemblyName}" feature="System.Resources.UseSystemResourceKeys" featurevalue="false">
|
||||
<type fullname="System.SR">
|
||||
<method signature="System.Boolean UsingResourceKeys()" body="stub" value="false" />
|
||||
<method signature="System.Boolean GetUsingResourceKeysSwitchValue()" body="stub" value="false" />
|
||||
</type>
|
||||
</assembly>
|
||||
</linker>
|
||||
|
|
|
@ -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>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -7,7 +7,10 @@ namespace System
|
|||
{
|
||||
internal static partial class SR
|
||||
{
|
||||
private static readonly bool s_usingResourceKeys = AppContext.TryGetSwitch("System.Resources.UseSystemResourceKeys", out bool usingResourceKeys) ? usingResourceKeys : false;
|
||||
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;
|
||||
|
||||
// This method is used to decide if we need to append the exception message parameters to the message when calling SR.Format.
|
||||
// by default it returns the value of System.Resources.UseSystemResourceKeys AppContext switch or false if not specified.
|
||||
|
|
|
@ -11,17 +11,25 @@ Imports System.Resources
|
|||
Namespace System
|
||||
|
||||
Friend NotInheritable Class SR
|
||||
' This method is used to decide if we need to append the exception message parameters to the message when calling SR.Format.
|
||||
' by default it returns false.
|
||||
' Native code generators can replace the value this returns based on user input at the time of native code generation.
|
||||
' Marked as NoInlining because if this is used in an AoT compiled app that is not compiled into a single file, the user
|
||||
' could compile each module with a different setting for this. We want to make sure there's a consistent behavior
|
||||
' that doesn't depend on which native module this method got inlined into.
|
||||
<Global.System.Runtime.CompilerServices.MethodImpl(Global.System.Runtime.CompilerServices.MethodImplOptions.NoInlining)>
|
||||
Public Shared Function UsingResourceKeys() As Boolean
|
||||
Private Shared ReadOnly s_usingResourceKeys As Boolean = GetUsingResourceKeysSwitchValue()
|
||||
|
||||
Private Shared Function GetUsingResourceKeysSwitchValue() As Boolean
|
||||
Dim usingResourceKeys As Boolean
|
||||
If (AppContext.TryGetSwitch("System.Resources.UseSystemResourceKeys", usingResourceKeys)) Then
|
||||
Return usingResourceKeys
|
||||
End If
|
||||
|
||||
Return False
|
||||
End Function
|
||||
|
||||
' This method Is used to decide if we need to append the exception message parameters to the message when calling SR.Format.
|
||||
' by default it returns the value of System.Resources.UseSystemResourceKeys AppContext switch Or false if Not specified.
|
||||
' Native code generators can replace the value this returns based on user input at the time of native code generation.
|
||||
' The trimming tools are also capable of replacing the value of this method when the application Is being trimmed.
|
||||
Public Shared Function UsingResourceKeys() As Boolean
|
||||
Return s_usingResourceKeys
|
||||
End Function
|
||||
|
||||
Friend Shared Function GetResourceString(ByVal resourceKey As String, Optional ByVal defaultString As String = Nothing) As String
|
||||
If (UsingResourceKeys()) Then
|
||||
Return If(defaultString, resourceKey)
|
||||
|
|
|
@ -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="'$(TargetPlatformIdentifier)' == 'windows'">true</OmitResources>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetPlatformIdentifier)' != ''">
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
<OutputType>Exe</OutputType>
|
||||
<CLRTestPriority>0</CLRTestPriority>
|
||||
<DefineConstants>$(DefineConstants);RESOURCE_KEYS</DefineConstants>
|
||||
<UseSystemResourceKeys>true</UseSystemResourceKeys>
|
||||
|
||||
<!-- Requires the framework to also be compiled with UseSystemResourceKeys -->
|
||||
<CLRTestTargetUnsupported Condition="'$(IlcMultiModule)' == 'true'">true</CLRTestTargetUnsupported>
|
||||
|
@ -10,10 +11,6 @@
|
|||
<CLRTestTargetUnsupported Condition="'$(TargetsAppleMobile)' == 'true'">true</CLRTestTargetUnsupported>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<IlcArg Include="--feature:System.Resources.UseSystemResourceKeys=true" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -55,6 +55,7 @@ Copyright (c) .NET Foundation. All rights reserved.
|
|||
<_ComObjectDescriptorSupport Condition="'$(_ComObjectDescriptorSupport)' == ''">false</_ComObjectDescriptorSupport>
|
||||
<_DesignerHostSupport Condition="'$(_DesignerHostSupport)' == ''">false</_DesignerHostSupport>
|
||||
<_DefaultValueAttributeSupport Condition="'$(_DefaultValueAttributeSupport)' == ''">false</_DefaultValueAttributeSupport>
|
||||
<UseSystemResourceKeys Condition="'$(UseSystemResourceKeys)' == ''">false</UseSystemResourceKeys>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue