"运行自定义工具"在MVC2项目RESX文件(从外部应用程序/脚本) [英] "Run Custom Tool" for resx files in MVC2 project (from an external application/script)

查看:190
本文介绍了"运行自定义工具"在MVC2项目RESX文件(从外部应用程序/脚本)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得本地化为我的MVC项目与我们现有的编辑字符串资源的基础设施的工作。我们存储在数据库中的表我们所有的资源字符串,并有一个前端的Web UI并进行编辑,并生成.resx文件的出口申请。这一切的伟大工程,但我有使用MVC2和VS2010一个新的项目有点困难。

I am trying to get the localization for my MVC project working with our existing infrastructure for editing string resources. We store all our resource string in database tables and have a front end web UI to edit them with, and an export application which generated the .resx files. This all works great, but I am having a little difficulty with a new project using MVC2 and VS2010.

我也问过这一另一个问题中,回答几乎让我在那里,但并不完全。

I have asked another question on this, the answer to which almost got me there, but not quite.

我现在已经改变了的资源,在一个资源文件夹(代替App_GlobalResources文件),所建议的一些人。并具有以下设置对我的.resx文件...

I have now changed the resources to be in a Resources folder (instead of App_GlobalResources), as recommended by a number of people. And have the following settings against my .resx files ...


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

我已经改变了我出口的应用程序运行 resgen.exe 使用以下参数工具...

I have changed my export application to run the resgen.exe tool with the following parameters ...

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

...产生,因为我拿到的时候我.resx文件添加到我的项目最初几乎相同了.Designer.cs文件。唯一不同的是在

... which generates an almost identical .designer.cs file as I get when I add the .resx file to my project initially. The only difference is the

生成了.Designer.cs文件略有文件我得到的,当我运行从我的出口申请中resgen.exe工具是不同的。

The generated .designer.cs file differs slightly from the file I get when I run the resgen.exe tool from within my export application.

这是VS2010生成当我第一次.resx文件添加到我的资源文件夹中的code ...

This is the code generated by VS2010 when I first add the .resx file to my Resources folder ...

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工具的区别是prefixs MyCompany.MyApp 以在构造函数中的ResourceManager命名空间

... the difference when I run the resgen.exe tool is that is prefixs MyCompany.MyApp to the namespace in the constructor to ResourceManager

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

现在,这对我来说似乎是在resgen.exe工具中的错误,因为我已经告诉它我的资源命名空间的资源,不是 MyCompany.MyApp。资源

Now, this to me seems to be a bug in the resgen.exe tool, because I've told it that the Namespace for my resources is Resources, not MyCompany.MyApp.Resources.

那么,有没有一个固定/变通这个问题?

So, is there a fix/work-around for this problem?

我能想到此刻要做的唯一一件事情就是后处理生成了.Designer.cs使用PowerShell文件,并修复它!

The only thing I can think to do at the moment is to post-process the generated .designer.cs file with powershell and fix it!

推荐答案

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

Finally, I have solved the problem.

我决定到一个名为资源新的组装打破我的资源在把事情简单化了一点。然后我说我的resx文件,并为他们设置的属性如下...

I decided to simplify things a bit by breaking my resources out in to a new assembly called Resources. I then added my resx files and set the properties for them as below ...


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

然后我改变了我的申请进出口运行...

I then changed my export application to run ...


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

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

... and to delete *.resources from the folder (created by the resgen.exe utility, but not needed)

这上了构造摆脱preFIX的为的ResourceManager ,然后我只是增加了一个参考我的新的资源装配到我的Web应用程序。

This got rid of the prefix on the constructor to ResourceManager, and then i just added a reference to my new Resources assembly to my web application.

我已经运行一些测试,以确保一切都很好,包括去到了.Designer.cs文件,并删除其中一个属性会导致编译错误。然后重新跑我出口的应用程序,一切工作再次

I've run a few tests to make sure all is good, including going in to the .designer.cs file and deleting one of the properties to cause a compiler error. Then re-ran my export app, and everything worked again.

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

So, I am a happy bunny!

这篇关于"运行自定义工具"在MVC2项目RESX文件(从外部应用程序/脚本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆