Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Web Deploy to run a batch file after publish

I'm using Web Deploy to publish a web application from Visual Studio 2012 to my target IIS server. All fine there!

I now want to deploy to multiple servers in a web farm (within a workgroup). I have produced a Robocopy script to copy the files over the network to the other hosts once it has been deployed to the first web server. I can run this bat file manually no problem but I would like to automate it within the deployment process.

So far I've managed to edit the .pubxml file in my VS project as follows.

  <ItemGroup>
    <MsDeploySourceManifest Include="runCommand">
      <Path>robocopy &quot;c:\web1&quot; &quot;\\REMOTEMACHINE\web1&quot; /MIR</Path>
    </MsDeploySourceManifest>
  </ItemGroup>

This runs the command OK but before all files have been synchronised. Also according to the publish log it's running twice. In the middle of the file sync process.

How can I adapt the .pubxml file to run that command only after all files are synchronised?

like image 390
QFDev Avatar asked Oct 21 '22 05:10

QFDev


1 Answers

I believe I've resolved this by wrapping the ItemGroup in a Target with AfterTargets set to AddIisSettingAndFileContentsToSourceManifest.

I'm still not sure why the command is being executed twice? And I would welcome any other suggestions on how I can simplify this operation.

  <Target Name="RoboCopyToHosts" AfterTargets="AddIisSettingAndFileContentsToSourceManifest">
    <ItemGroup>
      <MsDeploySourceManifest Include="runCommand">
         ....
         ....
      </MsDeploySourceManifest>
    </ItemGroup>
  </Target>
like image 183
QFDev Avatar answered Oct 23 '22 00:10

QFDev