Pergunta

I have this code that should nGen my main application 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));
            }
        }

    }

}

What I require is that not only the EXE be nGen'd, but all the referenced DLLs (my whole solution) also get nGen'd

Say my EXE project is called:

FileOnline.DesktopClient

And it depends on these:

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

How can I nGen these through the only deployment project in the solution?

Thanks.

Foi útil?

Solução

It is automatic, ngen.exe finds those assemblies through Assembly.GetReferencedAssemblies(). You'd only have to take care of assemblies you load yourself with Assembly.Load/From(). Review the /execonfig option if you have unusual binding rules in the .exe.config file, ngen.exe needs to know those too so it can find the proper assembly.

Alternative methods are here and here.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top