Using WiX to run NGen 2.0 against your application during installation - part 2

Tuesday, October 11th, 2005 @ 6:42 am | Development

Following on from my previous post, here’s an
implementation of Rob’s suggestion.
The following WiX fragment will run NGen 2.0 on your
application without showing a command prompt:

<!-- Put the "wixca.dll" library in the binary table so it can be used by the following custom actions -->
<Binary Id="wixca"
	src="..\Lib\WiX\ca\wixca.dll"/>

<!-- Custom action to generate the command line to run "NGen install" -->
<CustomAction Id="MyApp.exeNGenInstall.Command"
	      Property='QtExecCmdLine'
	      Value='"[WindowsFolder]Microsoft.NET\Framework\v2.0.50215\ngen.exe" install "[#MyApp.exe]" /queue:2 /nologo /silent'/>

<!-- Custom action to perform the "NGen install" -->
<CustomAction Id="MyApp.exeNGenInstall"
	BinaryKey="wixca"
	DllEntry="CAQuietExec"
	Return="check" />

<!-- Custom action to generate the command line to run "NGen uninstall" -->
<CustomAction Id="MyApp.exeNGenUninstall.Command"
	Property="QtExecCmdLine"
	Value='"[WindowsFolder]Microsoft.NET\Framework\v2.0.50215\ngen.exe" uninstall "[#MyApp.exe]" /nologo /silent' />

<!-- Custom action to perform the "NGen uninstall" (we can ignore the result of this) -->
<CustomAction Id="MyApp.exeNGenUninstall"
	BinaryKey="wixca"
	DllEntry="CAQuietExec"
	Return="ignore" />

<InstallExecuteSequence>
	<!-- If not installed, generate the install command and execute it (after finializing the install) -->
	<Custom Action="MyApp.exeNGenInstall.Command"
		After="InstallFinalize">
		NOT Installed
	</Custom>
	<Custom Action="MyApp.exeNGenInstall"
		After="MyApp.exeNGenInstall.Command">
		NOT Installed
	</Custom>

	<!-- If installed, generate the uninstall command and execute it (before removing any files) -->
	<Custom Action="MyApp.exeNGenUninstall.Command"
		Before="MyApp.exeNGenUninstall">
		Installed
	</Custom>
	<Custom Action="MyApp.exeNGenUninstall"
		Before="RemoveFiles">
		Installed
	</Custom>
</InstallExecuteSequence>

You’ll need to modify the path to your copy of wixca.dll, change
the path to ngen.exe (if you’re not using .NET 2.0 Beta 2) and
change MyApp.exe to the Id of the file that is the "root" of your
application.





Comments

No Comment


  1. 1 Anonymous on February 3, 2006 3:08 pm

    I’m doing just that but get an error 0×80070002 in the msi log. The command line i am trying to run is “net” (net.exe under windows\system32).

    Any ideas?

  2. 2 Anonymous on March 1, 2006 6:45 pm

    after following your example, im getting errors like this in my msi log: “Error 0×8007006d: Failed to read from handle.” the commands seems to have worked, but i get that error after each one. is this normal?

  3. 3 Anonymous on November 26, 2006 1:21 pm

    The current release of WiX 2.0 has built-in NGen support, so I’m happy to say that this post is now obsolete! :)

Name (required)

Email (required)

Website

Add your comment