Search code examples
wixnant

creating msi using nant and wix


I am trying to create an installer for my project using NAnt. this is how my build script looks like

<?xml version="1.0"?>
<project name="pleats" default="build-release" xmlns="http://nant.sf.net/release/0.85/nant.xsd">

<target name="build-release" depends="clean, make-builddir, build, release-properties, copy-to-release, build-installer" />
<property name="tools.dir" value="${path::get-full-path('tools')}" />  
<property name="src.dir" value="${path::get-full-path('src')}" />  
<property name="build.dir" value="D:\Subrat\Projects\WPF\WpfApplicationNAntTest\WpfApplicationNAntTest\bin\Debug" />  
<target name="clean" description="Delete automated build artifacts">  
    <delete dir="${build.dir}" if="${directory::exists(build.dir)}" failonerror="false"/>  
</target>   
<target name="make-builddir" description="Create build dir and build report dir">       
    <mkdir dir="${build.dir}" unless="${directory::exists(build.dir)}" />  
</target>   
<target name="release-properties">      
    <property name="release.dir" value="D:\Subrat\Projects\WPF\WpfApplicationNAntTest\WpfApplicationNAntTest\bin\Release"/>  
    <property name="wix.dir" value="D:\Subrat\Projects\WPF\WpfApplicationNAntTest\Lib\wix"/>  
</target>   
<target name="copy-to-release">     
    <mkdir dir="${release.dir}" failonerror="false"/>  
    <copy todir="${release.dir}">           
        <fileset basedir="${src.dir}">              
            <include name="*" />  
        </fileset>          
    </copy>     
</target>
<target name="build">
    <loadtasks assembly="D:\Subrat\Projects\WPF\WpfApplicationNAntTest\Lib\nantcontrib-0.85\bin\NAnt.Contrib.Tasks.dll"/>
    <msbuild project="D:\Subrat\Projects\WPF\WpfApplicationNAntTest\WpfApplicationNAntTest.sln">
        <property name="configuration" value="debug" />
        <property name="Platform" value="any cpu" />    
    </msbuild>
</target>
<target name="build-installer">     
    <!-- for wix preprocessor so that the location of pleats files are propagated into the wxs -->  
    <setenv name="pleats.dir" value="${release.dir}"/> 
    <delete>            
        <fileset>           
            <include name="${wix.dir}/*.wixobj"/>
    </fileset>          
    </delete>       
    <exec program="${wix.dir}\candle.exe" workingdir=".\wix" commandline="SampleFirst.wxs " /> 
    <exec program="${wix.dir}\light.exe" workingdir=".\wix" commandline="-ext WixUIExtension -cultures:en-us SampleFirst.wixobj -out ${release.dir}\pleats.msi"/> 
</target>   
</project>

I am using the sample wxs file i got in wix tutorial.

 <?xml version='1.0' encoding='windows-1252'?>
 <Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>
   <Product Name='Foobar 1.0' Id='C2B662FC-82AA-11DF-93D4-6B70DFD72085' UpgradeCode='CE3E5F1C-82AA-11DF-A42F-7170DFD72085'
Language='1033' Codepage='1252' Version='1.0.0' Manufacturer='Acme Ltd.'>
<Package Id='*' Keywords='Installer' Description="Acme's Foobar 1.0 Installer"
  Comments='Foobar is a registered trademark of Acme Ltd.' Manufacturer='Acme Ltd.'
  InstallerVersion='100' Languages='1033' Compressed='yes' SummaryCodepage='1252' />

<Media Id='1' Cabinet='Sample.cab' EmbedCab='yes' DiskPrompt="CD-ROM #1" />
<Property Id='DiskPrompt' Value="Acme's Foobar 1.0 Installation [1]" />

<Directory Id='TARGETDIR' Name='SourceDir'>
  <Directory Id='ProgramFilesFolder' Name='PFiles'>
    <Directory Id='Acme' Name='Acme'>
      <Directory Id='INSTALLDIR' Name='Foobar 1.0'>

        <Component Id='MainExecutable' Guid='DD4C895C-82AA-11DF-941D-8370DFD72085'>
          <File Id='FoobarEXE' Name='WpfApplicationNAntTest.exe' DiskId='1' Source='D:\Subrat\Projects\WPF\WpfApplicationNAntTest\WpfApplicationNAntTest\bin\Debug\WpfApplicationNAntTest.exe' KeyPath='yes'>
            <Shortcut Id="startmenuFoobar10" Directory="ProgramMenuDir" Name="Foobar 1.0" WorkingDirectory='INSTALLDIR' Icon="WpfApplicationNAntTest.exe" IconIndex="0" Advertise="yes" />
            <Shortcut Id="desktopFoobar10" Directory="DesktopFolder" Name="Foobar 1.0" WorkingDirectory='INSTALLDIR' Icon="WpfApplicationNAntTest.exe" IconIndex="0" Advertise="yes" />
          </File>
        </Component>

        <!--<Component Id='HelperLibrary' Guid='YOURGUID-6BE3-460D-A14F-75658D16550B'>
          <File Id='HelperDLL' Name='Helper.dll' DiskId='1' Source='Helper.dll' KeyPath='yes' />
        </Component>

        <Component Id='Manual' Guid='YOURGUID-574D-4A9A-A266-5B5EC2C022A4'>
          <File Id='Manual' Name='Manual.pdf' DiskId='1' Source='Manual.pdf' KeyPath='yes'>
            <Shortcut Id="startmenuManual" Directory="ProgramMenuDir" Name="Instruction Manual" Advertise="yes" />
          </File>
        </Component>-->

      </Directory>
    </Directory>
  </Directory>

  <Directory Id="ProgramMenuFolder" Name="Programs">
    <Directory Id="ProgramMenuDir" Name="Foobar 1.0">
      <Component Id="ProgramMenuDir" Guid="E510F3DA-82AA-11DF-8814-8970DFD72085">
        <RemoveFolder Id='ProgramMenuDir' On='uninstall' />
        <RegistryValue Root='HKCU' Key='Software\[Manufacturer]\[ProductName]' Type='string' Value='' KeyPath='yes' />
      </Component>
    </Directory>
  </Directory>

  <Directory Id="DesktopFolder" Name="Desktop" />
</Directory>

<Feature Id='Complete' Level='1'>
  <ComponentRef Id='MainExecutable' />
  <!--<ComponentRef Id='HelperLibrary' />
  <ComponentRef Id='Manual' />-->
  <ComponentRef Id='ProgramMenuDir' />
</Feature>

<Icon Id="WpfApplicationNAntTest.exe" SourceFile="WpfApplicationNAntTest.exe" />
<UIRef Id="WixUI_Minimal" />
 </Product>
 </Wix>

when i am trying to make an installer i am geting this error -

the system cannot find the file WpfApplicationNAntTest.exe

i dont have much idea about Nant or wix as i am new to this. Please help.


Solution

  • I think you need to specify the full path in the Icon element, SourceFile attribute to where the WpfApplicationNantTest.exe is.

    Something like:

    <Icon 
     Id="WpfApplicationNAntTest.exe"      
     SourceFile="D:\Subrat\Projects\WPF\WpfApplicationNAntTest\bin\debug\WpfApplicationNAntTest.exe" />