2009-01-14 9 views

Antwort

16

Eigentlich können Sie NGEN und clickone verwenden, aber Sie müssen das NGEN nach der Clickonce-Installation ausführen, da NGEN Teil der .NET-Installation ist (für 3.5 sollten Sie auf die 2.0-Installation verweisen). Hier

ist ein Beispiel, ich denke, es ist generisch genug für Sie, es zu benutzen, ohne zu ändern oder zu tun sehr wenig Änderungen am Code (mit Ausnahme den Anruf an der Form):

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()); 
    } 
} 
+4

Das funktioniert nicht auf Windows 7 (und ich glaube Vista), weil 'ngen' als Administrator laufen möchte. –

+2

Dies ist nicht sehr praktisch, da es Administratorberechtigungen erfordert. Die Natur von clickonce ist, dass es keine Administratorberechtigungen für die Installation benötigt, daher wäre das Hinzufügen dieses Codes nicht sinnvoll. – pmcilreavy

Verwandte Themen