【问题标题】:nGen EXE +DLLs through Setup and Deployment project通过设置和部署项目的 nGen EXE +DLL
【发布时间】:2012-01-17 11:53:13
【问题描述】:

我有这段代码,应该 nGen 我的主应用程序 EXE:

using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;

namespace FileOnline.DesktopClient.Setup.Support {
    [RunInstaller(true)]
    public partial class CustomNGen : Installer {

        public override void Install(IDictionary stateSaver) {
            base.Install(stateSaver);
            ExecuteNGen("install", true);
        }

        public override void Uninstall(IDictionary savedState) {
            base.Uninstall(savedState);
            //CleanUpShortcuts();
            ExecuteNGen("uninstall", false);
        }

        private void ExecuteNGen(string cmd, bool validate) {
            var ngenStr = Path.Combine(RuntimeEnvironment.GetRuntimeDirectory(), "ngen");
            var assemblyPath = Context.Parameters["assemblypath"];

            using (var process = new Process {
                StartInfo = {
                    FileName = ngenStr,
                    Arguments = string.Format(@"{0} ""{1}""", cmd, assemblyPath),
                    CreateNoWindow = true,
                    UseShellExecute = false
                }
            }) {
                process.Start();
                process.WaitForExit();

                if (validate && process.ExitCode != 0)
                    throw new Exception(String.Format("Ngen exit code: {0}", process.ExitCode));
            }
        }

    }

}

我需要的是不仅 EXE 是 nGen'd,而且所有引用的 DLL(我的整个解决方案)也要 nGen'd

假设我的EXE项目被称为:

FileOnline.DesktopClient

这取决于这些:

FileOnline.DesktopClient.BaseControls
FileOnline.DesktopClient.BaseForms
FileOnline.DesktopClient.Utilities
FileOnline.DesktopClient.Dialogboxes
FileOnline.DesktopClient.HelpingExtension
FileOnline.DesktopClient.*More stuff*

如何通过解决方案中唯一的部署项目来生成这些?

谢谢。

【问题讨论】:

    标签: winforms c#-4.0 setup-deployment ngen


    【解决方案1】:

    它是自动的,ngen.exe 通过 Assembly.GetReferencedAssemblies() 找到那些程序集。您只需要处理您自己使用 Assembly.Load/From() 加载的程序集。如果您在 .exe.config 文件中有不寻常的绑定规则,请查看 /execonfig 选项,ngen.exe 也需要知道这些规则,以便找到正确的程序集。

    替代方法是herehere

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-24
      • 1970-01-01
      相关资源
      最近更新 更多