Ant*_*ott 3 resx visual-studio-2010 asp.net-mvc-2
我试图让我的MVC项目的本地化与我们现有的基础设施一起使用来编辑字符串资源.我们将所有资源字符串存储在数据库表中,并具有用于编辑它们的前端Web UI,以及生成.resx文件的导出应用程序.这一切都很好,但是我对使用MVC2和VS2010的新项目有点困难.
我已经问了另一个问题,答案几乎让我在那里,但并不完全.
我现在已根据许多人的建议将资源更改为Resources文件夹(而不是App_GlobalResources).并针对我的.resx文件进行以下设置...
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);
Run Code Online (Sandbox Code Playgroud)
...当我最初将.resx文件添加到我的项目时,生成一个几乎相同的.designer.cs文件.唯一的区别是
生成的.designer.cs文件与我从导出应用程序中运行resgen.exe工具时获得的文件略有不同.
当我第一次将.resx文件添加到我的Resources文件夹时,这是VS2010生成的代码...
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;
}
}
Run Code Online (Sandbox Code Playgroud)
...运行resgen.exe工具的不同之处在于,它将MyCompany.MyApp的前缀添加到ResourceManager的构造函数中的命名空间
new global::System.Resources.ResourceManager("MyCompany.MyApp.Resources.MyApp", typeof(MyApp).Assembly);
Run Code Online (Sandbox Code Playgroud)
现在,这对我来说似乎是resgen.exe工具中的一个错误,因为我已经告诉它我的资源的命名空间是Resources,而不是MyCompany.MyApp.Resources.
那么,这个问题是否有修复/解决方法?
我现在唯一能想到的就是使用PowerShell对生成的.designer.cs文件进行后处理并修复它!
最后,我解决了这个问题.
我决定通过将资源分解为一个名为Resources的新程序集来简化一些事情.然后我添加了我的resx文件并为它们设置属性如下...
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实用程序创建,但不需要)
这消除了构造函数上的前缀到ResourceManager,然后我只是将我的新资源程序集的引用添加到我的Web应用程序.
我已经运行了一些测试以确保一切正常,包括进入.designer.cs文件并删除其中一个属性以导致编译器错误.然后重新运行我的导出应用程序,一切都恢复正常.
所以,我是一个快乐的兔子!
| 归档时间: |
|
| 查看次数: |
7901 次 |
| 最近记录: |