更新到 .NETStandard 2.0 和本地化

Update to .NETStandard 2.0 and Localization

我按照 these instructions 将我的 Xamarin.Forms 项目升级到 .NETStandard 2.0。现在我在我的 .resx 文件中添加了一个新条目并得到一个编译错误:

error CS0117: 'AppResources' does not contain a definition for 'MyKey'

我认为 AppResources.Designer.cs 文件不再更新了。以下内容似乎是错误的:

1> Task "CreateCSharpManifestResourceName" skipped, due to false condition; ('%(EmbeddedResource.ManifestResourceName)' == '' and '%(EmbeddedResource.WithCulture)' == 'true' and '%(EmbeddedResource.Type)' == 'Non-Resx') was evaluated as ('' == '' and 'false' == 'true' and 'Resx' == 'Non-Resx'). 1> Task "CreateCSharpManifestResourceName" skipped, due to false condition; ('%(EmbeddedResource.ManifestResourceName)' == '' and '%(EmbeddedResource.WithCulture)' == 'true' and '%(EmbeddedResource.Type)' == 'Non-Resx') was evaluated as ('' == '' and 'true' == 'true' and 'Resx' == 'Non-Resx'). 1> Task "CreateCSharpManifestResourceName" skipped, due to false condition; ('%(EmbeddedResource.ManifestResourceName)' == '' and '%(EmbeddedResource.WithCulture)' == 'true' and '%(EmbeddedResource.Type)' == 'Non-Resx') was evaluated as ('' == '' and 'false' == 'true' and 'Non-Resx' == 'Non-Resx').

我最好的选择是手动编辑 PCL 项目中的 .csproj。在我的旧 .csproj 中,我有这个:

<Compile Include="Common\Localization\AppResources.Designer.cs">
    <AutoGen>True</AutoGen>
    <DesignTime>True</DesignTime>
    <DependentUpon>AppResources.resx</DependentUpon>
</Compile>

<ItemGroup>
    <EmbeddedResource Include="Common\Localization\AppResources.de.resx">
        <SubType>Designer</SubType>
    </EmbeddedResource>
    <EmbeddedResource Include="Common\Localization\AppResources.resx">
        <Generator>ResXFileCodeGenerator</Generator>
        <LastGenOutput>AppResources.Designer.cs</LastGenOutput>
        <SubType>Designer</SubType>
    </EmbeddedResource>
</ItemGroup>

但我认为我不能一对一地采用它。我尝试 play with it,但没有成功:

<ItemGroup>
    <Compile Update="Common\Localization\AppResources.Designer.cs">
        <AutoGen>True</AutoGen>
        <DesignTime>True</DesignTime>
        <DependentUpon>AppResources.resx</DependentUpon>
    </Compile>
</ItemGroup>
<ItemGroup>
    <EmbeddedResource Update="Common\Localization\AppResources.de.resx">
        <SubType>Designer</SubType>
    </EmbeddedResource>
    <EmbeddedResource Update="Common\Localization\AppResources.resx">
        <Generator>ResXFileCodeGenerator</Generator>
        <LastGenOutput>AppResources.Designer.cs</LastGenOutput>
        <SubType>Designer</SubType>
    </EmbeddedResource>
</ItemGroup>

如何让我的翻译恢复正常?

似乎唯一需要做的就是将 AppResources.resx自定义工具 选项设置为 PublicResXFileCodeGenerator.这导致以下 .csproj 代码:

<ItemGroup>
    <Compile Update="Common\Localization\AppResources.Designer.cs">
        <AutoGen>True</AutoGen>
        <DesignTime>True</DesignTime>
        <DependentUpon>AppResources.resx</DependentUpon>
    </Compile>
</ItemGroup>
<ItemGroup>
    <EmbeddedResource Update="Common\Localization\AppResources.de.resx">
        <SubType>Designer</SubType>
    </EmbeddedResource>
    <EmbeddedResource Update="Common\Localization\AppResources.resx">
        <Generator>PublicResXFileCodeGenerator</Generator>
        <LastGenOutput>AppResources.Designer.cs</LastGenOutput>
        <SubType>Designer</SubType>
    </EmbeddedResource>
</ItemGroup>

AppResources.resx 的 key/value 对的 访问修饰符 现在是 Public。所有其他语言资源文件的 Access ModifierNo code generation

我还删除了其他 AssemblyInfo.cs 文件,因为它似乎在没有它们和没有 NeutralResourcesLanguage 的情况下工作,而不是 the sample in the docs。尽管如此,我在项目属性中的Package下设置了Assembly neural language。因此 .csproj 现在包含一个 <NeutralLanguage>en</NeutralLanguage> 条目。

我觉得奇怪的是你