编辑/添加项目到Resources.resx

本文关键字:Resources resx 项目 添加 编辑 | 更新日期: 2023-09-27 18:06:10

我尝试动态地添加项目到Resources.resx。目前我正在使用RessourceWriter,但这不起作用(它产生*。资源文件,不要写入.resxfile).

 ResourceWriter writer = new ResourceWriter("Resources.resx");
        writer.AddResource(string.Concat("AppImage",indes.ToString()), newImg);
        writer.Close();

有人能告诉我我做错了什么,或者甚至不可能动态地添加项目到资源。resx ?

提前感谢。

编辑/添加项目到Resources.resx

resx文件被设计成在开发/设计时填充资源,而不是在运行时,请记住,有一个资源设计器类包含由IDE自动生成的代码。

您可以在项目预构建事件中填充您的resx文件

这是一个在运行时更新resx文件的方法。

string ResxFile = System.IO.File.ReadAllText("Properties/Resources.resx");
string wordResxName = resxname;
string word = resxvalue;
string ResxAddStrings = "  <data name='"" + wordResxName + "'" xml:space='"preserve'">'r'n    <value>" + word + "</value>'r'n  </data>'r'n";
ResxAddStrings += "</root>";
System.IO.File.WriteAllText("Properties/Resources.resx", ResxFile);