I’m hoping this blow by blow hit list will help someone out there as much as it does us.
We do a lot of Umbraco installs – but you can’t commit everything you do to your own brain’s RAM – there just isn’t enough space!
You will notice herein that we create a 3 project solution – as opposed to the two project solution that Umbraco provides for directly via the command line tools that come down from the cloud. This allows us to reference the Content Models generated from your document types in the CORE solution as well as in the views in your WEB solution.
A nod here to my colleague Jonny Sedman who could equally have posted this guide – more to come from him on other subjects later.
Sign Up Start a free trial project with an appropriate naming convention (which will be used for namespace later by the way). For this guide lets call it abc-123-mysite
Follow the guidelines here: https://our.umbraco.org/documentation/Umbraco-Cloud/Set-Up/Visual-Studio/ and copy Uaas.Cmd to e.g. C:\htdocs\abc-123-mysite (this folder will ultimately comprise the solution file and three project folders)
When running UaaS.cmd give the namespace as mentioned above i.e. abc-123-mysite
When asked for user and password to git enter the your Umbraco user and password
Now to move the CORE project over to your own Git Repo
Once all is downloaded – open the root folder e.g. C:\htdocs\abc-123-mysite in source tree (or similar)
Change the git repo address to your own gitlab address
Add Initial Commit as comment
Commit then Push to master (select Master as local branch and remote branch)
You will now have a bookmark ‘abc-123-mysite’ and this is your CORE project – we tend to rename the bookmark in SourceTree to .Core so it stands out as such – e.g. ‘abc-123-mysite.Core’
Now to sort out the WEB project
Now in source control open the .WEB folder and bookmark it
You will now have a bookmark ”abc-123-mysite.WEB”
Commit the initial change – it will be the packages file
Then pull from master, then push to master
Now lets add another project
Open the solution in VS and build it, run it.
Enter Umbraco User and Pass, the local instance runs and places you in the CMS
Now let’s add in a Published Content Models Project.
Add a class library project to the solution called Umbraco.Web.PublishedContentModels
Add into that project – via nuget package manager, UmbracoCms.Core and Umbraco.ModelsBuilder
Add a reference to System.Web
Now go to web.config in WEB project and change the models builder config lines to below:
<add key="Umbraco.ModelsBuilder.Enable" value="true"/>
<add key="Umbraco.ModelsBuilder.ModelsMode" value="AppData"/>
<add key="Umbraco.ModelsBuilder.ModelsDirectory" value="~/../Umbraco.Web.PublishedContentModels"/>
<add key="Umbraco.ModelsBuilder.AcceptUnsafeModelsDirectory" value="true"/>
We’ve just told the CMS to publish the class files for the Content Models that you will create to the a folder “
Umbraco.Web.PublishedContentModels"Now build the solution
Run it and publish models from the CMS via the Developer tab
Now refresh the Umbraco.Web.PublishedContentModels project
Include all the .cs files into the project
Build the solution again
Reference the Umbraco.Web.PublishedContentModels project from both the Core and the Web projects
Build and hey presto! You can now access those models from both WEB and CORE cleanly and efficiently.
I Hope you found this article helpful, we really find this approach to be robust.