Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use MSDeploy to copy an executable to a server and to then run same

Tags:

.net

msdeploy

I've got MSDeploy/WebDeploy working a treat to update my web applications - this resolves about 90% of my deployment issues for the things I've got set up so far.

What I would like to do, in addition, is to copy an executable - pragmatically the contents of a folder - to the server and then to run that executable (which does schema updates).

I can see that this ought to be possible, but I'm struggling to put the pieces together (this is clearly an edge case).

Specifically:

  • I'd rather not copy the executable (folder) into the web directory.
  • I need to consider the result of running the executable (be useful to return a failure status, though if significant this will get thrown up by post deployment tests)

As much as anything therefore, what specific commands in what order - if I can find a pattern I can make it work but I'm struggling to work out a pattern


Notes:

It does occur to me that I could copy the folder to the web directory, run the code and then delete the folder again but I'm uncomfortable with this and in any case it would be better to have the code available on the server post deployment.

Its also worth noting that I am really really happy with the way I maintain database schemas so the fact that that's what the executable is doing is incidental to the question

like image 341
Murph Avatar asked Feb 02 '23 10:02

Murph


1 Answers

Web Deploy actually offers quite a few options here. Which options you choose kind of depends on how many things you want to put into one command.

To get a folder of files over to the destination, you could use the Web Deploy’s dirPath provider to do the copying to the location of your choice. To copy an individual file, you can use the filePath provider. If your copy source has many small files, Web Deploy is actually more performant than RoboCopy over a network (see my blog post Web Deploy vs. Robocopy).

To run the command file that you copied to the destination server, you can use the runCommand provider. (This is an important one, I would definitely read up on it.)

Note that at this point we’re talking about at least two separate Web Deploy commands, not counting any of the “usual” Web Deploy operations like deploying a website or web server.

However, if your goal is to achieve everything in one Web Deploy operation, you can use the manifest provider. Create a custom manifest file that specifies a series of Web Deploy provider operations that will execute in turn. Then, in the Web Deploy command, point the manifest provider to the custom manifest file. For more information on this approach, see Creating and Synchronizing a Custom Manifest.

If you do use the manifest provider, you could specify the dirPath provider in the manifest file to copy the file or files over, and then specify the runCommand provider on a subsequent line to actually run the executable that you copied over.

Finally, an approach one step short of using a manifest file is to use the preSync and/or postSync command line switches to run a command on the destination server before or after the actual Web Deploy operation takes place. You can find more information on preSync and postSync on the Web Deploy Operation Settings page.

All of the pages referenced have syntax examples, so that should help.

like image 99
timamm Avatar answered Feb 05 '23 03:02

timamm