使用nant msi任务创建msi

时间:2011-03-07 19:56:25

标签: windows-installer nant task nantcontrib

我正在尝试为我的应用程序创建一个msi。

我使用以下命令传递client和version参数:

C:\ my client \ nant -D:client = abc -D:version = 1.0

我收到以下错误消息:

**

[msi] Building Installer Database 'C:\irx-client\irxclient.msi'.
      [msi] Adding Properties:
      [msi]  ProductName
      [msi]  ProductVersion
      [msi]  Manufacturer
      [msi]  ProductCode
      [msi]  UpgradeCode
      [msi]  ALLUSERS
      [msi]  TARGETDIR
      [msi] Adding Directories:
      [msi]  client
      [msi]  bitmaps
      [msi]  icsrun552
      [msi]  nls
      [msi]  reports
      [msi] Compressing Files...
                 [exec] Starting 'cabarc (-r N C:\my-client\target\myclient.cab *)' in 'C:\Documents and Settings\user123\Local Settings\Temp\tmp12AE.tmp' BUILD FAILED

**

但是,我可以成功手动运行以下命令:

C:\my-client\target\cabarc -r -p n myclient.cab *.*

我已经安装了cabarc.exe,nantcontrib和microsoft platform sdk,并将它们包含在PATH变量中。

请告诉我这里的错误。

nant脚本摘要:

  1. 将文件复制到\ target \ appname-version \
  2. 创建包含\ target \ appname-version \
  3. 下所有文件和文件夹的msi
        <?xml version="1.0"?>
    <project name="my client" default="msi-package">
    <!-- import the extra libraries -->
    <loadtasks assembly="${path::combine(environment::get-variable('NANT_HOME'),'contrib/bin/NAnt.Contrib.Tasks.dll')}"/>
    
    <!--********************************************************************
      Initialize all the required variables
    ************************************************************************-->
    <property name="source-core" value="./src/core" />
    <property name="client" value="client" overwrite="false"/>    
    <property name="version" value="3.3.9.7.6" overwrite="false"/>
    <property name="client-target" value="./target/appname-version" />
    <property name="source-bank" value="./src/${client}"/>
    <property name="ProductName" value="appname" />   
    <property name="ProductVersion" value="${version}"/>  
    <property name="ProductManufacturer" value="manufacturer Inc"/>
    <echo message="${client}"/>
    <echo message="${version}"/>
    
    <!--********************************************************************
    Delete 'target' folder if it exists and create a new empty target folder.
    ************************************************************************-->
    
    <target name="clean">
      <delete dir="./target" />
    </target>
    
    <target name="prepare" depends="clean">
      <mkdir dir="target" />  
    <property name="target" value="./target" />
    </target>
    
    <!--**************************************************************************************
    Copy files from /src/core and /src/client to target/appname-version
    ****************************************************************************************-->
    
    <target name="copy-core" depends="prepare">
      <copy todir="${client-target}">
         <fileset basedir="${source-core}">
            <include name="**/*.*" />
         </fileset>
      </copy>
    </target>
    <target name="copy-bank" depends="copy-core">
      <copy todir="${client-target}" overwrite="true">
          <fileset basedir="${source-bank}">
              <include name="**/*.bmp"/>
              <include name="**/*.exe"/>
              <include name="**/*.icx"/>
              <include name="**/*.img"/>
              <include name="**/*.ini"/>
              <include name="**/*.txt"/>
              <include name="**/nls/*.*"/>
              <include name="**/Reports/*.*"/>
          </fileset>
      </copy>
    </target> 
    
    <!--**************************************************************************************
                      msi part should go in this section
    *****************************************************************************************-->  
    
    <target name="msi-package" depends="copy-bank">           
    <!--this section calls the cabarc.exe which has been installed and the PATH environment variable has been edited to include the exe-->
    <setenv>
      <variable name="PATH" path="C:\Program Files\NAnt\bin\;%PATH%" />
    </setenv>
    
    <msi sourcedir="C:\my-client\target" output="C:\my-client\myclient.msi" verbose="true" debug="true">
    
    <properties>  
      <property name="ProductName" value="appname" /> 
      <property name="ProductVersion" value="${version}"/>    
      <property name="Manufacturer" value="mamufacturer Inc."/>
      <property name="ProductCode" value="{}" />  
      <property name="UpgradeCode" value="{}" />  
      <property name="ALLUSERS" value="2" />
      <property name="TARGETDIR" value="C:\appname-version" />
    </properties>
    
    <directories>
    <directory name="C_CLIENT" foldername="client" root="TARGETDIR"/>
    <directory name="C_BITMAP" foldername="bitmaps" root="TARGETDIR"/>
    <directory name="C_ICSRUN" foldername="icsrun552" root="TARGETDIR" />
    <directory name="C_NLS" foldername="nls" root="TARGETDIR" />
    <directory name="C_RPTS" foldername="reports" root="TARGETDIR" />
    </directories>        
    
    </msi>
    </target>
    </project>
    

3 个答案:

答案 0 :(得分:0)

当我运行确切的命令时,它会因“未知命令”错误而失败,但是如果我删除了括号,它就能够创建cab文件。显然,nant将括号与参数一起传递。

答案 1 :(得分:0)

我有同样的问题。出于某种原因,添加

<components>
  <component>
    Your component here
  </component>
</components>

修正了问题。

您可以在<components>任务文档页面上检查<msi>元素所需的元素:http://nantcontrib.sourceforge.net/release/0.85/help/tasks/msi.html

另请参阅此处msi任务的一个很好的示例:Sample Request: <msi> task of nant-contrib

答案 2 :(得分:0)

您是否尝试过使用devenv.exe?我在我的nant脚本中使用它,我能够为我的应用程序创建msi。以下是供您参考的代码段:

<target name="BuildMsi">
    <echo message="Creating installables (.msi) for MyTestApplication, please wait..."/>    
    <exec program="c:\program files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe">
        <arg value="c:\My app\My_Test_solution.sln"/>
        <arg value="/build"/>
        <arg value="Release|x86" />
        <arg value="/project"/>
        <arg value="c:\My app\setup\My_Test_solution.vdproj"/>
    </exec>
</target>

确保解决方案文件(.sln)路径正确且.vdproj文件存在。希望这有助于人们在使用nant脚本创建msi文件时寻求帮助。快乐的编码!