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

发布于 2024-12-21 09:20:08 字数 1693 浏览 1 评论 0原文

我第一次尝试卷影复制。我有以下代码:

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 没有被复制到这个临时目录,导致应用程序崩溃。

我缺少什么?如何将它们全部复制到临时目录?

I am trying Shadow Copy for the fist time. I have the following code:

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());
    }
}

The executable is reaching the temp directory just fine and its running until I reach a referenced dll. The 14-16 dlls that I have referenced throughout the project are not being copied to this temp directory causing the app to blow up.

What am I missing? How do I get them all to get copied to the temp directory as well?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

司马昭之心 2024-12-28 09:20:09

我们的应用程序中几乎有相同的代码,并且运行良好。

唯一的区别是我们的 main 方法也用

[LoaderOptimization(LoaderOptimization.MultiDomain)]

你可以尝试一下,看看是否有区别。

We have virtually the same code in our app and it works well.

The only difference is that our main method is also decorated with

[LoaderOptimization(LoaderOptimization.MultiDomain)]

You might try that to see if it makes a difference.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文