The other day, I decided that I’d publish a work-in-progress website to an Azure Website. This was a free Website as part of the free package that Azure subscribers can use. The website was a plain old vanilla ASP.NET MVC site. Nothing fancy, just some models, some controllers , some infrastructure code and of course, some views.
I was deploying this to Azure via a direct connection to a private BitBucket Git repository I had within my BitBucket account. This way, a simple “git commit” and “git push” would have, in a matter of seconds, my latest changes available for me to see in a real “on-the-internet” hosted site, thus giving me a better idea of how my site would look and feel than simply running the site on localhost.
An issue I almost instantly came up against was that, whenever I’d make a tiny change to just a view file – i.e. no code changes, just tweaks to HTML markup in the .cshtml Razor view file, and commit and push that change – the automated deployment process would kick in and the site would be successfully deployed to Azure, however, the newly changed Razor View would remain unchanged.
What on earth was going on? I could run the site locally and see the layout change just fine, however, the version deployed to Azure was the older version, prior to the change. I first decided that I now had to manually FTP the changed .cshtml files from my local machine to the relevant place in the Azure website, which did work, but was an inelegant solution. I needed to find out why the changed Razor views were not being reflected in the Azure deployments.
After some research, I found the answer.
Turns out that some of my view files (the .cshtml files themselves) had the “Build Action” property set to “None”. In order for your view to be correctly deployed when using automated Azure deployments, the Build Action property must be set to “Content”.
Now, quite how the Build Action property had come to be set that way, I have no idea. Some of the first views I’d added to the project had the Build Action set correctly, however, some of the newer views I’d added were set incorrectly. I had not explicitly changed any of these properties on any files, so how some were originally set to Content and others set to None was a mystery. And then I had an idea…..
I had been creating Views in a couple of different ways. Turns out that when I was creating the View files using the Visual Studio context menu options, the files were being created with the correct default Build Action of Content. However, when I was creating the View files using ReSharper’s QuickFix commands by hitting Alt + Enter on the line return View(); which shows the ReSharper menu allowing you to create a new Razor view with or without layout, it would create the View file with a default Build Action of None.
Bizarrely, attempting to recreate this issue in a brand new ASP.NET MVC project did not reproduce the issue (i.e. the ReSharper QuickFix command correctly created a View with a default Build Action of Content!)
I can only assume that this is some strange intermittent issue with ReSharper, although it’s quite probably caused by a specific difference between the projects that I’ve tested this on, thus far I have no idea what that difference may be… I’ll keep looking and if I find the culprit, I’ll post an update here.
Until then, I’ll remain vigilant and always remember to double-check the Build Action property and ensure it’s set to Content for all newly created Razor Views.