gpt4 book ai didi

c# - 以编程方式创建资源文件

转载 作者:可可西里 更新时间:2023-11-01 08:26:39 25 4
gpt4 key购买 nike

我想创建一个资源文件(在准备部署的过程中),用某些设置(大 XML 结构)和一些文本填充它,但我不确定如何去做。

我确实找到了一些使用 ResXResourceWriter 的示例,但是在尝试打开它时找不到资源 key 。这是我到目前为止所拥有的:

private void simpleButton1_Click(object sender, EventArgs e)
{
using (System.IO.MemoryStream oStream = new System.IO.MemoryStream())
{
this.layoutControl1.SaveLayoutToStream(oStream);
using (ResXResourceWriter oWriter = new ResXResourceWriter(@"..\..\Properties\LayoutControl.resources.Resx"))
{
oWriter.AddResource("one", oStream.GetBuffer());
oWriter.Generate();
oWriter.Close();
}
}

}

private void simpleButton2_Click(object sender, EventArgs e)
{
ResourceManager rm = new ResourceManager("WindowsFormsApplication1.LayoutControl", Assembly.GetExecutingAssembly());
var one = rm.GetObject("one");
Console.WriteLine("");
}

我通过单击 simpleButton1 创建资源,然后停止应用程序,将现有项目添加到我的项目中,重新编译并单击 simpleButton2,然后我得到一个

MissingManifestResourceException (Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "WindowsFormsApplication1.LayoutControl.resources" was correctly embedded or linked into assembly "WindowsFormsApplication1" at compile time, or that all the satellite assemblies required are loadable and fully signed.)

有人可以给我一些指导或更好的例子吗?如果资源可以编译成像“普通”资源文件一样的“单独”程序集,我会更喜欢它。

最佳答案

您非常接近 - 您传递给 ResourceManager 的 baseName 有点偏离。

您在其中编译的任何 resx 文件都使用默认命名空间加上路径中的任何文件夹命名。在您的帖子中,您应该传入“WindowsFormsApplication1.Properties.LayoutControl.resources”。

关于c# - 以编程方式创建资源文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1894969/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com