[英]Generating manifest when assembly (.dll) is generated at runtime using CodeDom.CompilerResults
I'm generating an assembly (*.dll) at runtime. 我在运行时生成程序集(* .dll)。 the compilation process is performed using CodeDom, as is recommended in following post:
编译过程是使用CodeDom执行的,如以下文章中所建议:
Generating DLL assembly dynamically at run time 在运行时动态生成DLL程序集
My code and assembly are generated successfully, not errors. 我的代码和程序集已成功生成,而不是错误。 The problem comes when I'm attempting load this generated assemblies at runtime via reflection using :
当我尝试在运行时通过反射使用以下方式加载生成的程序集时,就会出现问题:
// load for reflection only
var _assemblyTempLoad = Assembly.LoadFrom(assembly.FullName);
Following exception is thrown: 引发以下异常:
"Could not load file or assembly 'nameforassembly.dll' or one of its dependencies. The module was expected to contain an assembly manifest."
“无法加载文件或程序集'nameforassembly.dll'或其依赖项之一。该模块应包含程序集清单。”
How to generate the manifest file or fix this issue? 如何生成清单文件或解决此问题?
I want clarify that assembly is generated at runtime, using following code: 我想说明一下使用以下代码在运行时生成程序集:
CompilerResults compilerResult = codeDomProvider.CompileAssemblyFromFile(compilerParameters, Path.Combine(path, sourceCodeFile));`
Thank you in advance 先感谢您
Have you tried the following 您是否尝试过以下
compilerParameters.CompilerOptions = string.Format("/win32manifest: {0}", manifestFilename);
If you've already have the CompilerOptions
set to some value, just concatenate the strings 如果您已经将
CompilerOptions
设置为某个值,则只需串联字符串
compilerParameters.CompilerOptions += string.Format(" /win32manifest: {0}", manifestFilename);
The win32manifest parameter tells the compiler to also generate a manifest file. win32manifest参数告诉编译器也生成清单文件。
when an assembly is created at runtime (on the fly), the assembly info or metadata is not placed into assembly automatically. 在运行时(即时)创建装配时,装配信息或元数据不会自动放入装配中。 The use of the [Assembly] attribute was necessary too.
也需要使用[Assembly]属性。 On this way, the last step in the process was place the /platform argument to the compiler (thanks sgmoore).
这样,过程的最后一步是将/ platform参数放置到编译器中(感谢sgmoore)。 I can saw this using Redgate reflector.
我可以使用Redgate反射器看到它。 The assembly was shown without versioning and metadata attributes.
显示的程序集没有版本控制和元数据属性。 Like this:
像这样:
streamWriter.WriteLine(string.Format("[assembly: AssemblyTitle(\"{0}\")]", yourassembly.propertyfornamespace.Replace(" ", "")));
streamWriter.WriteLine(string.Format("[assembly: AssemblyDescription(\"{0}\")]", yourassembly.propertywithdescription));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.