When using Octopus Deploy to deploy an Umbraco web site, the binaries and other source files are extracted from the Nuget package into a new directory created by the Tentacle agent on the target machine(s).
As a practice I generally advise against storing Media in the repo (although there some cases where it makes sense), however following this practice means that the Media folder effectively goes missing each time a release is deployed.
Octopus Deploy provides a number of hooks for each package that is deployed in a release. In fact there are a few places where you can respond to the deployment with a scripts that you can include in your final build artifact.
The strategy here is to find the directory of the deployment path of the previous version and copy the Media folder from there to the path of the current version. Because the semantic versioning policy of the package versions, sorting the folders by name will let us find the most recent previous deployment path to copy from.
Include the following in your csproj file as PostDeploy.ps1 to include the solution in your project: