c#动态编时,如何添加现有模块的引用 vCompilerParameters.ReferencedAssemblies.Add(typeof(Controls.baseControl).Module.FullyQualifiedName)//这样觉得太烂了,有好的方法吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用这个AppDomain.CurrentDomain.GetAssemblies();或者所有的Assembly string file = "System";//Systemy文件的路径string path = "System.DLL";//System.DLL文件的路径CompilerParameters compilerparams = new CompilerParameters();compilerparams.OutputAssembly = path ;CompilerResults results = compiler.CompileAssemblyFromFile(compilerparams,file); 我对lovefootball兄 答案的理解是:用AppDomain.CurrentDomain.GetAssemblies()返回Controls的Assembly对象。正如typeof(Controls.baseControl).Assembly。可是得到这个Assembly以后.我怎么把它添加到引用中去? 对于henry兄的回复,是不是把动态编辑的程序输出到硬盘文件里,我不知道这里对添加现在模块的引用是怎么处理的 ?不知道大家明白我问的什么吗?我表达能力是不是很差? 我的意思是说,我在Comp模块里动态编辑一段代码, 它是一个字符串变量,只不过里存的是代码的字符,比如说 string code="Controls.baseControl=new Controls.baseControl();";就叫它动态代码吧。而这动态代码里又使到了baseControl类。这个类在Controls模块里,Controls模块和Comp模块都在同一解决方案里,都是这个解决方案里的项目。为了动态代码能运行。就得动态编辑,动态编辑得添加对Controls模块的引用我添加引用方法是:vCompilerParameters.ReferencedAssemblies.Add(typeof(Controls.baseControl).Module.FullyQualifiedName)//这样觉得太烂了,有好的方法吗?因为在运行时,Controls模块已经在内存里,我不想再通过去读硬盘文件,来添加引用。直接对已经存在内存里的Controls模块引用。vCompilerParameters.ReferencedAssemblies.Add(string value)这个value只能是文件路径吗? CompilerParameters parameters = new CompilerParameters(); Assembly ab = Assembly.GetEntryAssembly(); AssemblyName[] ans = ab.GetReferencedAssemblies(); foreach (AssemblyName assemblyName in ans) { string codeBase = assemblyName.CodeBase; if (string.IsNullOrEmpty(codeBase)) { parameters.ReferencedAssemblies.Add(assemblyName.Name + ".dll"); continue; } string tempFileName = codeBase.StartsWith("file://") ? codeBase.Substring(8) : codeBase.Substring(codeBase.LastIndexOf("/") + 1); parameters.ReferencedAssemblies.Add(tempFileName); } 网站自动东登录问题 如何在Winfrom的DataGridView中影藏某些字段 WPF中使用DatePicker要求值显示月份不显示日期!怎么实现? DataTable表间大数据量比较的效率问题 项目转换问题! 定义一个CLASS和方法时,在它们前不加修饰符,默认的缺省修饰符是什么呢? Console.Beep()的问题 请教C#里怎么把任何文件转成图片格式? 在一个框架页面中如何将数据传到另一个框架页面,并更新该框架页面 这样一个问题,如何解决 GridView Footer 取消字体加粗 [分享]WinForm UI设计与开发思路
string path = "System.DLL";//System.DLL文件的路径
CompilerParameters compilerparams = new CompilerParameters();
compilerparams.OutputAssembly = path ;
CompilerResults results = compiler.CompileAssemblyFromFile(compilerparams,file);
正如typeof(Controls.baseControl).Assembly。可是得到这个Assembly以后.我怎么把它添加到引用中去?
我不知道这里对添加现在模块的引用是怎么处理的 ?不知道大家明白我问的什么吗?我表达能力是不是很差?
我在Comp模块里动态编辑一段代码, 它是一个字符串变量,只不过里存的是代码的字符,
比如说 string code="Controls.baseControl=new Controls.baseControl();";
就叫它动态代码吧。
而这动态代码里又使到了baseControl类。这个类在Controls模块里,Controls模块和Comp模块都在同一解决方案里,都是这个解决方案里的项目。
为了动态代码能运行。就得动态编辑,动态编辑得添加对Controls模块的引用
我添加引用方法是:
vCompilerParameters.ReferencedAssemblies.Add(typeof(Controls.baseControl).Module.FullyQualifiedName)//这样觉得太烂了,有好的方法吗?
因为在运行时,Controls模块已经在内存里,我不想再通过去读硬盘文件,来添加引用。直接对已经存在内存里的Controls模块引用。vCompilerParameters.ReferencedAssemblies.Add(string value)
这个value只能是文件路径吗?
Assembly ab = Assembly.GetEntryAssembly();
AssemblyName[] ans = ab.GetReferencedAssemblies();
foreach (AssemblyName assemblyName in ans)
{
string codeBase = assemblyName.CodeBase;
if (string.IsNullOrEmpty(codeBase))
{
parameters.ReferencedAssemblies.Add(assemblyName.Name + ".dll");
continue;
}
string tempFileName = codeBase.StartsWith("file://") ? codeBase.Substring(8) : codeBase.Substring(codeBase.LastIndexOf("/") + 1);
parameters.ReferencedAssemblies.Add(tempFileName);
}