如果我是你,我實際上會混合MSBuild和MSDeploy。你應該讓你的MSBuild腳本執行像啓動/停止服務等操作。然後讓MSDeploy到文件副本。使用MSDeploy,您可以使用-whatif
開關來指示您只需要執行操作的報告,而不是實際執行操作。不幸的是,MSBuild不提供這種開箱即用的選項,您必須將其「構建」到腳本中。你可以用屬性和條件來做到這一點。例如,它可能是這個樣子:
<Project ...>
<PropertyGroup>
<!--
Create the property to use, and declare a default value.
Here I've defaulted this to true because it is better to force the
caller to explicitly specify when to perform the action instead of it
being the default.
-->
<SimulateExecution Condition= '$(SimulateExecution)'==''>true</SimulateExecution>
</PropertyGroup>
<Target Name="Deploy">
<Message Text="Deploy started" />
<Message Text="Stop service ABC on server Z"/>
<WindowsService ... Condition=" '$(SimulateExecution)'=='false' "/>
<Message Text="Stop service DEF on server Z"/>
<WindowsService ... Condition=" '$(SimulateExecution)'=='false' "/>
<!-- Call MSDeploy with the Exec task. -->
<PropertyGroup>
<MSDeployCommand>...\msdeploy.exe YOUR_OPTIONS_HERE</MSDeployCommand>
<!-- Append the -whatif to the command if this is just a simulation -->
<MSDeployCommand Condition= '$(SimulateExecution)'=='false' ">$(MSDeployCommand) -whatif</MSDeployCommand>
</PropertyGroup>
<Exec Command="$(MSDeployCommand)" />
... More things here
</Target>
</Project>
對於您可以使用WindowsService任務從MSBuild Extension Pack服務行動。你將不得不填補那裏的空白。
當您調用MSDeploy時,您應該只使用Exec任務來調用帶有您的參數的msdeploy.exe。如果你通過了這個願望,它不會實際執行這些行爲,只是報告它會做什麼。這些將被記錄到msbuild日誌中。所以如果你用/ fl調用msbuild.exe,你會得到這些操作寫入文件。我採用這種方法時遇到的唯一問題是,對於msdeploy.exe,您多次必須使用完整路徑(那些沒有..),這有時會非常棘手,因此請謹慎使用此類路徑。
@jcollum:那不夠詳細嗎?在此沒有聽到任何關於你的消息。 – 2010-02-19 06:05:11
感謝您的信息。這似乎是我正在尋找的。 – jcollum 2010-03-02 20:09:35