AppDomain卷影复制包括引用的程序集

时间:2011-12-14 20:27:28

标签: c# shadow-copy

我第一次尝试Shadow Copy。我有以下代码:

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {

        var sApplicationDirectory = Application.StartupPath;
        var sAppName = "propane";

        AppDomainSetup oSetup = new AppDomainSetup();
        string sApplicationFile = null;

        // Use this to ensure that if the application is running when the user performs the update, that we don't run into file locking issues.
        oSetup.ShadowCopyFiles = "true";
        oSetup.ApplicationName = "MyApplication";

        // Generate the name of the DLL we are going to launch
        sApplicationFile = System.IO.Path.Combine(sApplicationDirectory, sAppName + ".exe");

        oSetup.ApplicationBase = sApplicationDirectory;
        oSetup.ConfigurationFile = sApplicationFile + ".config";
        oSetup.LoaderOptimization = LoaderOptimization.MultiDomain;

        // Launch the application
        AppDomain oAppDomain = AppDomain.CreateDomain(sAppName, AppDomain.CurrentDomain.Evidence, oSetup);
        oAppDomain.SetData("App", sAppName);
        oAppDomain.ExecuteAssembly(sApplicationFile);

        // When the launched application closes, close this application as well
        Application.Exit();

        //Application.EnableVisualStyles();
        //Application.SetCompatibleTextRenderingDefault(false);
        //Application.Run(new Form1());
    }
}

可执行文件正好到达临时目录并运行直到我到达引用的dll。我在整个项目中引用的14-16个dll没有被复制到这个临时目录,导致应用程序爆炸。

我错过了什么?如何将它们全部复制到临时目录中?

1 个答案:

答案 0 :(得分:1)

我们的应用程序中的代码几乎相同,效果很好。

唯一的区别是我们的主要方法也装饰着

[LoaderOptimization(LoaderOptimization.MultiDomain)]

您可以尝试查看它是否有所作为。