2
  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 中添加新类并将其更新到正确的文件位置?有什么解决方案吗?

4

1 回答 1

0

更新程序集会很危险,不推荐!

反而,

1>将新编译的类[dll]存储在Isolatedstorage您想要的文件夹中或文件夹中!

2>创建一个订阅AssemblyResolve事件的方法。这个方法现在应该从文件夹或文件夹中返回应用程序要求的未解析的dll IsolatedStorage

于 2012-08-01T14:43:03.367 回答