代码之家  ›  专栏  ›  技术社区  ›  Antony Scott

MVC2项目中resx文件的“运行自定义工具”(来自外部应用程序/脚本)

  •  3
  • Antony Scott  · 技术社区  · 14 年前

    我正在努力使我的MVC项目本地化,并与我们现有的用于编辑字符串资源的基础设施一起工作。我们将所有的资源字符串存储在数据库表中,并有一个用于编辑它们的前端web UI和一个生成.resx文件的导出应用程序。这一切都很好,但我有一个新的项目使用MVC2和VS2010有点困难。

    another question 在这个问题上,我几乎得到了答案,但不完全是。

    Build Action             = Embedded Resource
    Copy to Output Directory = Do not copy
    Custom Tool              = PublicResXFileCodeGenerator
    Custom Tool Namespace    = Resources
    File Name                = MyApp.resx
    

    我已将导出应用程序更改为运行 resgen.exe 具有以下参数的工具。。。

    string args = string.Format("/publicClass \"{0}\" /str:cs,Resources,{1},\"{2}\"", resourceFile, Path.GetFileNameWithoutExtension(resourceFile), csFilename);
    

    生成的.designer.cs文件与在导出应用程序中运行resgen.exe工具时得到的文件略有不同。

    public static global::System.Resources.ResourceManager ResourceManager {
        get {
            if (object.ReferenceEquals(resourceMan, null)) {
                global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Resources.MyApp", typeof(MyApp).Assembly);
                resourceMan = temp;
            }
            return resourceMan;
        }
    }
    

    ... 运行resgen.exe工具时的区别是前缀 MyCompany.MyApp公司 到ResourceManager的构造函数中的命名空间

    new global::System.Resources.ResourceManager("MyCompany.MyApp.Resources.MyApp", typeof(MyApp).Assembly);
    

    资源 ,不是 .

    那么,这个问题有解决方法吗?

    目前我唯一能想到的就是用powershell对生成的.designer.cs文件进行后期处理并修复它!

    1 回复  |  直到 7 年前
        1
  •  6
  •   Antony Scott    14 年前

    最后,我解决了这个问题。

    资源

    Build Action             = Embedded Resource
    Copy to Output Directory = Do not copy
    Custom Tool              = PublicResXFileCodeGenerator
    Custom Tool Namespace    = Resources
    File Name                = MyApp.resx
    

    然后我将导出应用程序更改为运行。。。

    resgen MyApp.resx /str:c#,Resources,MyApp,MyApp.designer.cs /publicClass
    

    ... 以及从文件夹中删除*.resources(由resgen.exe实用程序创建,但不需要)

    资源经理 资源

    我已经运行了一些测试来确保一切正常,包括进入.designer.cs文件并删除其中一个属性以导致编译器错误。然后重新运行我的导出应用程序,一切又正常了。

    所以,我是一只快乐的兔子!