How to set up visual studio to create CSHTML files in (Umbraco) Project

19,281

Solution 1

You need to have the MVC Framework installed, then when you open the project as a website, you should be able to create and edit cshtml files with syntax highlighting. See my answer to the following post for more details:

Setting up local development environment for Umbraco

Solution 2

If your project is a web site/application then the mvc templates aren't available (they only show up in MVC projects). You can just create a text file and name it with the .cshtml extension though (you could set up your own template for this in VS if you wanted to).

To get intellisense in your Razor files, see Doug Robar's blog post on the subject

Solution 3

As an alternative if you go into the Umbraco admin, go to the 'Developer' section and right click on 'Scripting Files' you can create razor scripts directly (and this will save the new .cshtml directly into your 'macroScripts' folder - although in VS2010 you will need to right click on the new script and choose 'include in project').

Also this will allow you to base your new razor macroscript on one of the pre-built snippets so you may get a bit of core functionality for free.

enter image description here

Share:
19,281
Gigi2m02
Author by

Gigi2m02

Developing websites and webapplications using C#, LINQ, ADO.NET, .. ASP.NET MVC3 NHibernate Linq to SQL (X)HTML/HTML5 CSS2.1/CSS3 LESS CSS Javascript jQuery Very motivated about social websites and site with great UX/IA.

Updated on June 09, 2022

Comments

  • Gigi2m02
    Gigi2m02 almost 2 years

    So, i'm developing my razor macroscripts in Visual studio for my Umbraco project. Everything is working fine, but there are two things really annoying.

    • If I want to make a new CSHTML file the best solution for this is to duplicate an existing file.
    • I dont have full razor IntelliSense like e.g. Html.Raw

    Is there a way to configure my project to use this features? Didn't find a .cshtml template yet.

  • Gigi2m02
    Gigi2m02 about 12 years
    So the best solution for this I guess is to make your project as an MVC project? The intellisense shown in the video is the umbraco intellisense. I'm more looking for the standard razor intellisense e.g. when you want to type Html.Raw and ask voor intellisense after type Html....
  • Gigi2m02
    Gigi2m02 almost 12 years
    A problem now is the following: Normally, I use a web application project with post build events to upload my files to my server (ftp commands). In a Web Site project this isn't possible i see. Big disadvantage now.
  • Douglas Ludlow
    Douglas Ludlow almost 12 years
    You could put those same commands into a batch file that you run when you are ready to push updates.