将资源添加到生成的EXE文件中! [英] Add a resource to a generated EXE file!

查看:263
本文介绍了将资源添加到生成的EXE文件中!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿!

i在运行时向我生成的exe文件中添加资源文件有问题!

i使用''Microsoft.CSharp.CSharpCodeProvider''和'' System.CodeDom.Compiler.CompilerParameters''在运行时生成一个exe文件...我的问题是添加一个资源文件(.resx)!我使用EmbeddedResources或LinkedResources将resx文件添加到我生成的exe文件中!但是这个错误会显示出来! :

未处理的执行:System.Resources.MissingManifestResourceException:无法找到任何资源apprpriate  指定的文化或者是自然文化。确保  ChildProgram.Form1.Resources已正确嵌入或链接 into   assembly    ChildProgram在编译时,或者所有所需的附属程序集都是可加载和完全签名的。 System.Resources.ManifestBasedResourceGroveler.HandledResourceStreamMissing< string filename> 

....





我不知道该怎么办!我搜索了很多次,但分辨率对我的问题无效!

你能解释一下如何在运行时添加资源吗?也许我错过了什么!



这是该行导致错误

System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));

this.rdp.OcxState =((System.Windows.Forms.AxHost.State)(resources.GetObject(rdp.OcxState)));



非常谢谢!

解决方案

如果要将.resx文件直接嵌入到程序集中,那么这可能是不正确的。尽管编译器允许您嵌入任何文件,但托管环境所期望和理解的默认格式是二进制.resources格式。



Resx可以被认为是二进制资源的源代码,Visual Studio使用resgen.exe在两者之间进行转换,如此(经过严格编辑的)输出所示来自一个简单程序的编译。



目标CoreResGen:
C:\Program Files \ Mesrosoft Visual Studio 8 \ SDK \v2.0 \ bin\Resgen.exe
/ compile Form1.resx,obj\Debug \ ResourceTest.Form1.resources
将资源文件Form1.resx处理为obj\Debug\ResourceTest.Form1.resources。
目标CoreCompile:
任务Csc
C:\ WINDOWS \ MicroStoswork \ Framework \v2.0.50727 \Csc.exe
/ out:obj \Debug \ ResourceTest.exe
/resource:obj\Debug\ResourceTest.Form1.resources
/ target:winexe Form1.cs Form1.Designer.cs Program .cs





我不认为.NET框架类库有任何实现resgen.exe工具功能的东西你唯一的办法是通过Process.Start运行正确的参数。





使用CompilerParameters.EmbeddedResources并确保与表单关联的资源被赋予正确的名称。



对于以下表单,资源必须命名为ResourceTest.Form1.resources

 命名空间 ResourceTest {
public Form1:Form {}
}





如果ComponentResourceManager找不到正确命名的资源,将发生MissingManifestResourceException。例如如果我将二进制资源文件的名称从ResourceTest。 Form1 .resources更改为ResourceTest。 Form2 .resources,则程序会引发异常。





Alan。


hey !
i have an issue with adding a resource file to my generated exe file in runtime!
i used ''Microsoft.CSharp.CSharpCodeProvider'' and ''System.CodeDom.Compiler.CompilerParameters'' to generate a exe file in runtime... my problem is adding a resource file (.resx) ! i use EmbeddedResources or LinkedResources to add a resx file to my generated exe file! but this error will show! :

Unhandled Exeption :System.Resources.MissingManifestResourceException :Could not find any resource apprpriate for the specified culture or the nutural culture . Make sure "ChildProgram.Form1.Resources" was correctly embedded or linked into assembly "ChildProgram" at compile time ,or that all the satellite assemblies required are loadable and fully signed.
at System.Resources.ManifestBasedResourceGroveler.HandledResourceStreamMissing<string filename>
....



i dont know what should i do! i searched manytimes but resolutions not effective on my problem!
can you explain me how should add a resource in runtime?maybe i missed something!

this is that line causes error
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.rdp.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("rdp.OcxState")));

very thanks!

解决方案

If you are embedding the .resx file directly into the assembly then that is probably incorrect. Although the compiler will let you embed any file, the default format expected and understood by the managed environment is the binary ''.resources'' format.

Resx can be thought of as the source code for a binary resource and Visual Studio uses resgen.exe to convert between the two as shown by this (heavily edited) output from the compilation of a simple program.

Target CoreResGen:
    "C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\bin\Resgen.exe" 
    /compile Form1.resx,obj\Debug\ResourceTest.Form1.resources    
    Processing resource file "Form1.resx" into "obj\Debug\ResourceTest.Form1.resources".
Target CoreCompile:
  Task "Csc"
    C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Csc.exe 
    /out:obj\Debug\ResourceTest.exe 
    /resource:obj\Debug\ResourceTest.Form1.resources     
   /target:winexe Form1.cs Form1.Designer.cs Program.cs



I don''t think the .NET framework class library has anything that implements the functionality of the resgen.exe tool and your only recourse will be to run it with the correct arguments via Process.Start.

[EDIT]
Use CompilerParameters.EmbeddedResources and ensure that the resources associated with forms are given the correct name.

For the following form the resource must be named ResourceTest.Form1.resources

namespace ResourceTest {
  public class Form1 : Form {}
}



The MissingManifestResourceException will occur if the ComponentResourceManager cannot find the correctly named resource. e.g. If I change the name of the binary resource file from ResourceTest.Form1.resources to ResourceTest.Form2.resources then the program raises the exception.


Alan.


这篇关于将资源添加到生成的EXE文件中!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆