0

我尝试将项目动态添加到 Resources.resx。目前我正在使用 RessourceWriter,但这不起作用(它会生成 *.resources 文件并且不写入 .resxfile)。

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

有人可以告诉我我做错了什么,或者甚至不可能将项目动态添加到 Ressources.resx 吗?

提前谢谢了。

4

2 回答 2

1

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

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

于 2013-03-28T09:09:30.990 回答
0

这是一种在运行时更新 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);
于 2018-05-27T15:02:57.873 回答