简体   繁体   English

使用CodeDom.CompilerResults在运行时生成程序集(.dll)时生成清单

[英]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.

相关问题 从 codedom 生成的 dll 触发事件 - 如何加入运行时生成的 dll 表单主 exe 应用程序的事件 - event firing from codedom generated dll - how to join an event of a runtime generated dll form main exe application 使用WPF的CodeDom - 运行时出错 - CodeDom using WPF - error at runtime 如何使用 codedom 将 dll 嵌入到输出程序集中,并使用 C# 将其用作参考? - How can I embed a dll to the output assembly with codedom, and use it as reference using C#? 用CodeDom生成接口时的大括号和大括号 - braces and curly brackets when generating interface with codeDom 生成代码时,EnvDTE或CodeDom之间有区别吗 - Are there differences between EnvDTE or CodeDom when generating Code 在C#Codedom编译器参数中从DLL添加程序集时出错 - Error in adding assembly from dll in C# codedom compiler parameter 结合使用CodeDom和ILMerge合并的重载Dll文件 - Using CodeDom with empeded Dll files merged by ILMerge 使用CodeDom生成可为空的类型属性 - Generating nullable type properties using CodeDom 使用.NET CodeDom代码生成时,如何自定义自动生成的注释? - How do I customize the auto-generated comment when using .NET CodeDom Code Generation? 如何在不加载.dll的情况下读取程序集清单 - how to read the assembly manifest without loading the .dll
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM