复制代码 代码以下:php
ngen install filepath 服务器
复制代码 代码以下:app
Ngen uninstall filepath ide
复制代码 代码以下:工具
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
using System.Runtime.InteropServices;
using System.IO;
using System.Diagnostics;
namespace NgenInstaller
{
[RunInstaller(true)]
public partial class NgenInstaller : System.Configuration.Install.Installer
{
public NgenInstaller()
{
InitializeComponent();
}
public override void Install(IDictionary stateSaver)
{
NgenFile(InstallTypes.Install);
}
public override void Uninstall(IDictionary savedState)
{
NgenFile(InstallTypes.Uninstall);
}
private enum InstallTypes
{
Install,
Uninstall
}
private void NgenFile(InstallTypes options)
{
string envDir = RuntimeEnvironment.GetRuntimeDirectory();
string ngenPath = Path.Combine(envDir, "ngen.exe");
string exePath = Context.Parameters["assemblypath"];
string appDir = Path.GetDirectoryName(exePath);
int i = 1;
do {
string fileKey = "ngen" + i;
//须要生成本机映象的程序集名字,配置在ngen1...5,6的配置中
if (Context.Parameters.ContainsKey(fileKey))
{
string ngenFileName = Context.Parameters["ngen" + i];
string fileFullName = Path.Combine(appDir, ngenFileName);
string argument = (options == InstallTypes.Install ? "install" : "uninstall") + " \"" + fileFullName + "\"";
Process ngenProcess = new Process();
ngenProcess.StartInfo.FileName = ngenPath;
ngenProcess.StartInfo.Arguments = argument;
ngenProcess.StartInfo.CreateNoWindow = true;
ngenProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
ngenProcess.Start();
ngenProcess.WaitForExit();
i++;
}
else {
break;
}
}
while (true);
}
}
}测试
添加安装程序以后右击安装项目添加项目输出,以下图所示spa
在添加项目输出的对话框中选择Winforms项目和刚建的类库。
而后右击安装项目选择视图---自定操做打开自定义操做窗口,添加一个名字为“Ngen生成本机映象”的自定义操做,在添加操做时要选择NgenInstaller项目输出 以下图:命令行
而后将自定义操做的名字修改成“Ngen生成本机代码”,以下图所示code
而后右击新建的自定义操做,选择属性窗口,在属性窗口的CustomActionData属性中添加须要操做的程序集,注意CustomActionData是一个键值对,每一个键值对以/开始orm
完成这一步就差很少了,你能够编译一下整个解决方案。运行安装项目生成的安装包。
6. 运行安装包,若是一切正常的话就作了本机映象生成了,能够经过ngen display filePath命令来验证native本机影响是否安装正常,以下命令行输出