2

介绍

我正在创建我的第一个 Xamarin 应用程序(它将首先针对 UWP,然后是 Android,最后可能是 iOS)。

基本上,该应用程序需要多种语言:英语(默认)、法语、西班牙语、俄语和瑞典语。

我正在尝试添加较少的平台特定代码,因此没有添加特定代码来进行本地化。

我将UseResxLocaliaztion Xamarin GitHub 项目Xamarin Localization Documentation一起使用。

基本上,我只是复制并尝试在我的身上使用这个项目资源。但是命名空间是UsingResxLocalization.Resx和我的WhoStart.Resources,文件夹名称相同,Resources而不是Resx.

我更新了文件的ResourceManager属性Designer.cs,并尝试使用 resx 属性进行不同的操作,例如更改GeneratorCustomToolNamespace没有结果。

我在某些地方手动更改了WhoStart.projitems文件,因为我的 VisualStudio 没有缩进文件并且无法生成Designer.cs文件。

我的环境

  • Windows 10 v1607 周年更新 (14393.1066)
  • Visual Studio 2017 v15.1 (26403.7)
  • Xamarin 4.4.0.34
  • NuGet 包:
    • Xamarin.Forms 2.3.4.231
    • Microsoft.NETCore.UniversalWindowsPlatform 5.3.3

问题

我在尝试访问资源属性时遇到 System.Resources.MissingManifestResourceException。

MainPage.xaml.cs

Debug.WriteLine(AppResources.AddButton);

System.Resources.MissingManifestResourceException  : '找不到适合指定区域性或中性区域性的任何资源。确保“WhoStart.Resources.AppResources.resources”在编译时被正确嵌入或链接到程序集“WhoStart.UWP”中,或者所有所需的附属程序集都是可加载的并且完全签名。

视觉工作室

我认为它可能来自我的环境:

  • 当我使用 Visual Studio 向导创建资源文件时,它会创建一个 .resw 文件。
  • Visual Studio 不自动生成Designer.cs文件
  • 当我打开 .resx 文件时,访问修饰符菜单被禁用。
  • 似乎我没有在论坛上注意到的所有项目属性
  • 右键单击 .resx 文件时,我没有“运行自定义工具”

编码

应用资源.resx

<?xml version="1.0" encoding="utf-8"?>
<root>
    <resheader name="resmimetype">
        <value>text/microsoft-resx</value>
    </resheader>
    <resheader name="version">
        <value>2.0</value>
    </resheader>
    <resheader name="reader">
        <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
    </resheader>
    <resheader name="writer">
        <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
    </resheader>

    <data name="AddButton" xml:space="preserve">
        <value>Add new item</value>
        <comment>this string appears on a button to add a new item to the list</comment>
    </data>
</root>

MainPage.xaml.cs

namespace WhoStart.Resources {
    using System.Reflection;


    /// <summary>
    ///   A strongly-typed resource class, for looking up localized strings, etc.
    /// </summary>
    // This class was auto-generated by the StronglyTypedResourceBuilder
    // class via a tool like ResGen or Visual Studio.
    // To add or remove a member, edit your .ResX file then rerun ResGen
    // with the /str option, or rebuild your VS project.
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    internal class AppResources {

        private static global::System.Resources.ResourceManager resourceMan;

        private static global::System.Globalization.CultureInfo resourceCulture;

        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        internal AppResources() {
        }

        /// <summary>
        ///   Returns the cached ResourceManager instance used by this class.
        /// </summary>
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
        internal static global::System.Resources.ResourceManager ResourceManager {
            get {
                if (object.ReferenceEquals(resourceMan, null)) {
                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WhoStart.Resources.AppResources", typeof(AppResources).GetTypeInfo().Assembly);
                    resourceMan = temp;
                }
                return resourceMan;
            }
        }

        /// <summary>
        ///   Overrides the current thread's CurrentUICulture property for all
        ///   resource lookups using this strongly typed resource class.
        /// </summary>
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
        internal static global::System.Globalization.CultureInfo Culture {
            get {
                return resourceCulture;
            }
            set {
                resourceCulture = value;
            }
        }

        /// <summary>
        ///   Looks up a localized string similar to Add new item.
        /// </summary>
        internal static string AddButton {
            get {
                return ResourceManager.GetString("AddButton", resourceCulture);
            }
        }
    }
}

WhoStart 项目

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
    <HasSharedItems>true</HasSharedItems>
    <SharedGUID>2f09a751-1235-4d87-8839-d5828319ad81</SharedGUID>
  </PropertyGroup>
  <PropertyGroup Label="Configuration">
    <Import_RootNamespace>WhoStart</Import_RootNamespace>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="$(MSBuildThisFileDirectory)App.xaml.cs">
      <DependentUpon>App.xaml</DependentUpon>
    </Compile>
    <Compile Include="$(MSBuildThisFileDirectory)ColorUtil.cs" />
    <Compile Include="$(MSBuildThisFileDirectory)ILocalize.cs" />
    <Compile Include="$(MSBuildThisFileDirectory)MainPage.xaml.cs">
      <DependentUpon>MainPage.xaml</DependentUpon>
    </Compile>
    <Compile Include="$(MSBuildThisFileDirectory)Resources\AppResources.Designer.cs">
      <AutoGen>True</AutoGen>
      <DesignTime>True</DesignTime>
      <DependentUpon>AppResources.resx</DependentUpon>
    </Compile>
    <Compile Include="$(MSBuildThisFileDirectory)Resources\AppResources.es.Designer.cs">
      <AutoGen>True</AutoGen>
      <DesignTime>True</DesignTime>
      <DependentUpon>AppResources.es.resx</DependentUpon>
    </Compile>
    <Compile Include="$(MSBuildThisFileDirectory)Resources\AppResources.fr.Designer.cs">
      <AutoGen>True</AutoGen>
      <DesignTime>True</DesignTime>
      <DependentUpon>AppResources.fr.resx</DependentUpon>
    </Compile>
    <Compile Include="$(MSBuildThisFileDirectory)TranslateExtension.cs" />
  </ItemGroup>
  <ItemGroup>
    <EmbeddedResource Include="$(MSBuildThisFileDirectory)MainPage.xaml">
      <SubType>Designer</SubType>
      <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
    </EmbeddedResource>
    <EmbeddedResource Include="$(MSBuildThisFileDirectory)App.xaml">
      <SubType>Designer</SubType>
      <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
    </EmbeddedResource>
    <EmbeddedResource Include="$(MSBuildThisFileDirectory)Resources\AppResources.es.resx">
      <Generator>PublicResXFileCodeGenerator</Generator>
      <LastGenOutput>AppResources.es.Designer.cs</LastGenOutput>
      <CustomToolNamespace>WhoStart.Resources</CustomToolNamespace>
    </EmbeddedResource>
    <EmbeddedResource Include="$(MSBuildThisFileDirectory)Resources\AppResources.fr.resx">
      <Generator>PublicResXFileCodeGenerator</Generator>
      <LastGenOutput>AppResources.fr.Designer.cs</LastGenOutput>
      <CustomToolNamespace>WhoStart.Resources</CustomToolNamespace>
    </EmbeddedResource>
    <EmbeddedResource Include="$(MSBuildThisFileDirectory)Resources\AppResources.resx">
      <Generator>PublicResXFileCodeGenerator</Generator>
      <LastGenOutput>AppResources.Designer.cs</LastGenOutput>
      <CustomToolNamespace>WhoStart.Resources</CustomToolNamespace>
    </EmbeddedResource>
  </ItemGroup>
</Project>

研究

4

0 回答 0