複製代碼 代碼以下: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本機影響是否安裝正常,以下命令行輸出