Search code examples
asp.netmsbuildmsdeploy

How to unpack an msbuild web package without deploying it to a web server?


When MSBuild packages an ASP.Net website, it creates a .zip file and a set of xml files. Using msdeploy, I can push that zip file and a set of parameter replacements to an IIS server.

Now, here's the conundrum: given that Web Package zip file, is there a way to unpack it and do the token replacement cleanly without deploying to IIS? Just unpack it to a folder and apply the SetParameters.xml so that it would be ready to robocopy to a file system location?

Msdeploy's parameters are opaque to say the least. I've tried deploying using the file and folder providers, and that doesn't work.

I could roll my own - I'd have to reverse-engineer the token replacement logic and deal with how the zip file contains the entire folder tree right down to the drive root (instead of being relative paths from the project folder, which is what it will use when it deploys). All of this is doable... but very annoying and I was hoping there was a better way.

Thanks in advance.


Solution

  • Following up on this: In the end I had to do it in powershell. The code is tied into a whole bunch of other deployment code that's company-specific, so I can't paste it here, but in short:

    1. Unzip the .zip into a temporary location.
    2. Recurse the directories until you find the packagetmp - this is the actual meat of the zip.
    3. Delete the target web app folder on the webserver (carefully - as many sanity checks as possible need to happen before this step)
    4. Copy the contents of packagetmp to the target folder-path on the web-server.
    5. Apply use xpath operations to do the config transforms in powershell to provide connection strings and logging endpoints.
    6. Restart the app pool (do not skip this step you get subtle failures if you do).
    7. Clean-up (delete the temporary folder).