Collection of C# class source code file, with Microsoft.Csharp.CSharpCodeProvider.CompileAssemblyFromFile(parameters,ClassFiles) we can create an assembly dll file.
public static string[] sourcefiles = new string[]{
@"D:\pro1bk\projects\WCFService.cs" ,
@"D:\pro1bk\projects\Calculator.cs"
};
public Assembly Compile()
{
CSharpCodeProvider provider;
CompilerParameters parameters;
CompilerResults results;
parameters = new System.CodeDom.Compiler.CompilerParameters();
AddAssemblyReference(
typeof(System.Runtime.Serialization.DataContractAttribute).Assembly,
parameters.ReferencedAssemblies);
AddAssemblyReference(typeof(System.Xml.XmlElement).Assembly,
parameters.ReferencedAssemblies);
........
........
parameters.GenerateInMemory = true;
parameters.GenerateExecutable = false;
parameters.OutputAssembly = @"D:\pro1bk\ServiceCal.dll";
parameters.TreatWarningsAsErrors = false;
parameters.WarningLevel = 4;
parameters.TempFiles.KeepFiles = false;
if (TargetFramework == TargetFramework.Silverlight)
{
parameters.CompilerOptions = " /nostdlib ";
}
parameters.ReferencedAssemblies.AddRange(DefaultReferencedAssemblies);
//parameters.MainClass = "App";
try
{
provider = new CSharpCodeProvider();
results = provider.CompileAssemblyFromFile(parameters, sourcefiles);
results.PathToAssembly = "";
List<ErrorInfo> errors = new List<ErrorInfo>(results.Errors.Count);
......
......
}
}
上面的代码用于创建 dll 文件。
我刚刚将该 DLL(例如 ClientProx.dll)复制到另一个项目中。现在,我创建了一个带有方法的新类,以及如何将这个新创建的类添加到带有旧类的现有 DLL(例如 ClientProx.dll)中。
在该 DLL 中添加新类(例如 ClientProx.dll)后,它应该在适当的文件中更新为新类。
我们如何在运行时做到这一点?是否可以在现有 DLL 中添加新类并将其更新到正确的文件位置?有什么解决方案吗?