2014-08-28 79 views
0

嗨我新來的南特,我正在尋找一些功能/任務組合一堆常規任務。如何編寫南特任務的自定義南特任務

基本上我有3個網站與web.config文件中,我需要寫的ConnectionString和IMAGEDIR值2,只有文件路徑改變

目前我通過循環的文件路徑的一個CSV做到這一點,但希望能夠將代碼從循環中提取出來,並將其作爲任務/函數/目標或其他內容。什麼是最好的方法。

 <foreach item="String" in="${webConfig.includedFilePaths}" delim="," property="File.Path"> 
      <do> 
       <xmlpoke 
        file="${File.Path}" 
        xpath="${connectionString.XPath}" 
        value="${connectionString.Value}" /> 
       <xmlpoke 
        file="${File.Path}" 
        xpath="${imageDir.XPath}" 
        value="${imageDir.Value}" /> 
      </do> 
     </foreach> 

我希望這樣的事情:

<writeWebConfig file=${file.Path}" 

回答

0

您可以創建一個自定義楠任務與像一個屬性:

<target name="UpdateConfig"> 
    <property name="config.filepath" value="" /> 
    <!-- Rest of the task code here --> 
    </target> 

然後你就可以把這個任務多次正如你想要的屬性config.filepath的自定義值。您可以使用-D像覆蓋從命令行屬性值:

-D:config.filepath=D:\TestWeb\web.config 
+0

謝謝,我結束了使用一個目標,然後只用惡性任務 – eweb 2014-09-03 13:27:37

+0

結束了使用類似的方法把它從另一個目標,並使用惡性任務從另一個目標執行目標。 – eweb 2014-09-26 16:32:29