I'm trying to make it so when I deploy my mvc web application the app_offline screen is the first item copied to the server (using web deploy to azure vm) and then at the end of the deployment process the file is deleted.
The issue I have is that targets in my pubxml file aren't getting hit, below is an example of the targets. I've read various articles which suggest this is the correct way of going about this but I'm wondering if this information is out of date or not compatible for mvc some how.
<Target Name="TakeOffline" AfterTargets="BeforePublish" >
<Message Text="Taking application offline" Importance="high" />
</Target>
<Target Name="RestoreOnline" AfterTargets="AfterPublish" >
<Message Text="Restoring application online" Importance="high" />
</Target>
I had the same problem when publishing an MVC application. The documentation on the AfterTargets
and BeforeTargets
parameters seems to be lacking, but this page https://learn.microsoft.com/en-au/visualstudio/msbuild/target-build-order?view=vs-2015, a mixture of differing samples and some trial and error, helped me get it working.
I'm using Visual Studio 2019 version 16.7.3, ASP.NET 4.8 and MVC5 - all with the latest updates as of writing. This is what worked for me with Web Deploy, in my .pubxml file...
<Target Name="TakeOffline" BeforeTargets="MSDeployPublish" >
<Message Text="Taking application offline" Importance="high" />
[copy app_offline.htm to destination here]
</Target>
<Target Name="RestoreOnline" AfterTargets="MSDeployPublish" >
<Message Text="Restoring application online" Importance="high" />
[delete app_offline.htm from destination here]
</Target>