2014-04-04 68 views
1

這是我的情景:傳遞參數給南特構建腳本

我有一個build.bat保存:

call tools\nant-0.92\bin\nant.exe -buildfile:deploy.build %* -logfile:deploy_NAnt.log 

deploy.build部分成立:

<project 
    name="EdpClient" 
    basedir="." default="build" 
    xmlns="http://nant.sf.net/release/0.92/nantContrib.xsd"> 
     <!--INIT --> 
     ... 
     <property name="version" value="1.48.0.4" /> 
     ... 
     <!--RELEVANT TARGET--> 
     <target name="BuildProductionApplication" description="Build"> 
      <property 
       name="publishFolderParameter" 
       value="/p:PublishDir=${productionPublishFolder}" /> 
      <echo message="Building..." /> 
      <exec 
       program="${msbuildExe}" 
       workingdir="." verbose="true"> 
        <arg value="${projectFile}" /> 
        <arg value="/target:Clean;Publish" /> 
        <arg value="${publishFolderParameter}" /> 
        <arg value="/property:ApplicationVersion=${version}" /> 
        <arg value="/property:PublisherName=&quot;${publisherName}&quot;" /> 
      </exec> 
      <echo message="Built" /> 
     </target> 
    ... 
</project> 

現在我的問題是:

  • 如何在我的結構中調用"build.bat -version 1.48.0.4"並替換參數 ?
  • 如果沒有提供-version參數,腳本應該在命令行中輸入一些 msg?

感謝所有幫助!

+0

可能重複的[是否有可能發送參數到Nant任務?](http://stackoverflow.com/questions/3335698/is-it-possible-to-send-parameters-into-nant-task) – CloudyMarble

回答

1

這是我做的:

deploy.build文件,我改變:

<property name="version" value="1.48.0.4" /> 

到:

<property name="version" value="${arg.version}" /> 

這是的build.bat(批)看起來像現在:

@ECHO OFF 
IF %1.==. GOTO ERROR 
ECHO:BUILDING VERSION: %1 ... 
CALL tools\nant-0.92\bin\nant.exe -buildfile:deploy.build -D:arg.version=%1 -logfile:deploy_NAnt.log 
GOTO END 
:ERROR 
ECHO. 
ECHO Please provide the version parameter (eg. "deploy 1.1.1.1") 
ECHO. 
GOTO END 
:END 

現在我可以撥打build 1.48.0.4命令。 它適合我所有的需求。