“Do we click ‘view report’ or is that for wimps?”
Battling the red lines
Never content with resting on our laurels, we made cups of tea and returned to our desks for more work. Time to copy over our media library. Copying our library into /wwwroot/media took care of that. Views and partials were next, and we were not surprised to see a whole lot of red squiggly lines when we copied these over and took a look. A change from one framework to another always requires a little (or a lot of) re-engineering.
In our case, adding a ‘using’ and an ‘inherits’ took care of many of the issues.
@using Umbraco.Cms.Web.Common.PublishedModels;
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage
Then we could take a look and see what was still red.
Some real changes came next. Umbraco 9, being based on .NET 5, asks that we approach some of our architectural choices differently: Dependency injection is a first-class citizen, async is encouraged, and we no longer have Razor helpers. We discovered this as we progressed, partials first, and then views; each time we encountered a change, we tried to find a new way to work rather than build the way we knew. We sometimes relied sometimes on intellisense (eg. is Html.PartialAsync a thing? Yes!) and used docs for things we couldn’t take educated guesses on. One thing we noticed was that while
@await RenderSectionAsync
was a thing,
@await RenderBodyAsync
was not.
This stage of the build was more fun than it was arduous. Exploring a new framework in a group of developers is a fantastic way to learn how other people work and think. Sharing ideas, keyboard shortcuts and documentation - these are all things that happen at hackathons that are incredible for learning. Working in such a dynamic environment, even just for an afternoon, really helps us to be creative as technicians.
Modelsbuilder
Modelsbuilder was our next port of call. We knew that the settings had been renamed in Umbraco 9 to better reflect the way that modelsbuilder works, and chose to set ModelsMode to ‘SourceDataAuto’. We’d love to tell you that we made this choice after much consideration but after a quick, “Which one do you use, Seb?”, we settled on that one. We then went back to appSettings.json and used autocomplete to add the modelsbuilder property and settings, also adding the path for the models to the class library project (which is where they had been before).
Hot tip: if you change the location of your models, remember to a) manually generate the models in their new location via the backoffice and b) delete any previously generated models (Umbraco 9 stores these by default in /umbraco/models) and rebuild. Forgetting (b) kept us going around in circles for a while!
Models generated, we had even less red than before. Yay! But now we were running out of low-hanging fruit. To avoid this article getting too in-depth, we wrote up the migration tasks that we worked through as GitHub issues, so please hop over there if you want to find answers to questions such as:
- Why doesn’t my Route Hijacking work?
- What should we replace Razor Helpers with?
- Is XPath still a thing?
- What happened to IHtmlString?
- Why oh why (oh why) is my API controller not working?
Pushing to Cloud
Before we could push any content or media, we needed to get the ‘meta data’ of the site (Document Types, Data Types, etc.) deployed. Because all the Document and Data Types were already in the database and not created via the backoffice, this needed to be done manually using the ‘Extract Schema to Data Files’ option on the Deploy database in Settings: