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

So, I am developing my razor macros in Visual Studio for my Umbraco project. Everything works fine, but there are two things that are really annoying.

  • If I want to create a new CSHTML file, the best solution for this is to duplicate an existing file.
  • I don't have a full IntelliSense razor, for example. Html.Raw

Is there any way to configure my project to use these features? Could not find .cshtml template.

+7
source share
4 answers

You need to install the MVC Framework, and then when you open the project as a website, you can create and edit cshtml files with syntax highlighting. See my answer to the following post for more information:

Setting up a local development environment for Umbraco

+5
source

If your project is a website / application, mvc templates are not available (they are displayed only in MVC projects). You can simply create a text file and call it a .cshtml extension (you can customize your own template for this in VS, if you want).

To get intellisense in your Razor files, see the Doug Robar related blog post

+3
source

Alternatively, if you go to the Umbraco administrator, go to the "Developer" section and right-click on "Scripting Files", you can directly create razor scripts (and this will save the new .cshtml directly in your "macro prices", the folder - although in VS2010 you need to right-click on the new script and select "include in project").

In addition, it will allow you to create a new razor macro on one of the previously created fragments so that you can get basic functionality for free.

enter image description here

+1
source

From Umbraco 6, it is very convenient to install Umbraco in the local file system with Visual Studio and NuGet. Given that you have the MVC Framework installed and you are using Visual Studio 2012 or higher, you get full Razor support in Visual Studio. Umbraco We have an excellent blog post about this, where they described in detail the steps below (with screenshots!).

  • Create an empty web application.
  • Install Umbraco using Manage Nuget Packages ("Umbraco CMS") or the package manager console ( Install-Package UmbracoCms )
  • NuGet will then download the dependencies and install all the Umbraco files into your new solution. During this process, he will ask if it is allowed to overwrite the web.config file. (Back up your existing web.config if you install Umbraco in an existing project)
  • Finally, do not forget to start the F5 project. You will see that whenever you try to add or edit a file in the view folder, you have razor and intellisense support
0
source

All Articles