我们有一个大项目,只有英语。
业务用户有时需要更改应用程序中的文本,他们被迫等到下一个版本才能获得更改。
一种可能的解决方案是将字符串放入数据库中,另一种解决方案是将字符串放入未嵌入程序集中的文本文件中,以便能够在部署后对其进行更改。
资源文件很有吸引力,因为它们已经有一个用于创建类和访问属性的框架,但是,据我所知,它们只是嵌入到程序集中,之后无法(轻松)修改。
解决这个问题的最佳方法是什么?
最佳答案
不,您错了 - 资源可以与其他代码分开编译,并且您可以为您的应用程序提供更新:
Creating Resource Files for Desktop Apps
Resources in .resources Files You can use the
System.Resources.ResourceWriter
class to programmatically create a binary resource (.resources) file directly from code. You can also use Resource File Generator (Resgen.exe) to create a .resources file from a text file or a .resx file.After you create the .resources file, you can embed it in a run-time executable or library by including the language compiler's
/resource
switch, or embed it in a satellite assembly by using Assembly Linker (Al.exe).
当您使用 Visual Studio 时,您可以通过其界面轻松添加资源文件,然后您将可以轻松地对其进行编辑。
我建议您:
- 创建一个主资源文件,用于存储主要资源。该文件将嵌入到您的应用程序的库中。您可以在此处存储不可更新的资源。
- 为
en-US
文化创建本地化资源 - Visual Studio 会将其编译到单独的文件中,以便您可以轻松更新它,而无需重新编译整个项目。
或者:
- 更改 VS 的默认行为,并将所有资源从项目移至单独的库中。
由于您使用的是 VS 2010,我假设您的项目是 .NET 3.0,因此 MSDN 的正确链接是:
关于.net - 部署 .NET 后更改字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28042550/