是否可以在部署ClickOnce时使用NGen?
答案 0 :(得分:16)
实际上你可以使用NGEN和clickone,但是你需要在clickonce安装完成后运行NGEN,因为NGEN是.NET安装的一部分(对于3.5你应该参考2.0安装)。 / p>
以下是一个示例,我认为它足够通用,您可以在不更改或对代码进行少量更改的情况下使用它(除了对表单的调用):
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
if (ApplicationDeployment.IsNetworkDeployed && ApplicationDeployment.CurrentDeployment.IsFirstRun)
{
string appPath = Application.StartupPath;
string winPath = Environment.GetEnvironmentVariable("WINDIR");
Process proc = new Process();
System.IO.Directory.SetCurrentDirectory(appPath);
proc.EnableRaisingEvents = false;
proc.StartInfo.CreateNoWindow = false;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.FileName = winPath + @"\Microsoft.NET\Framework\v2.0.50727\ngen.exe";
proc.StartInfo.Arguments = "uninstall " + Application.ProductName + " /nologo /silent";
proc.Start();
proc.WaitForExit();
proc.StartInfo.FileName = winPath + @"\Microsoft.NET\Framework\v2.0.50727\ngen.exe";
proc.StartInfo.Arguments = "install " + Application.ProductName + " /nologo /silent";
proc.Start();
proc.WaitForExit();
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
答案 1 :(得分:4)