Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio, Razor, BuildProviders and Intellisense

I'm trying to get Intellisense working for razor views in a non-ASP.NET project and would like to understand the relationship between VisualStudio's Razor editor and BuildProviders.

For background, I'm writing a framework on top of Manos (mono web server) that uses Razor for its view engine. I've got that part working perfectly, but Intellisense in VS doesn't work giving a range of errors from unknown types to unregistered build providers, depending on where the output DLL's of the project are placed.

My project is a .NET Class Library, with .cshtml files (build action none). The base razor view class is defined in a separate assembly (outside the project) which could be registered in the GAC, but currently isn't.

I've already read these articles:

  • http://www.west-wind.com/weblog/posts/2011/Jan/12/IntelliSense-for-Razor-Hosting-in-nonWeb-Applications
  • Need razor view engine auto-complete to work in a class library?
  • http://blogs.msdn.com/b/webdevtools/archive/2011/01/20/how-to-get-razor-intellisense-for-model-in-a-class-library-project.aspx
  • .NET - Razor outside MVC application - Problems with removing @inherits and providing @model

Sounds like I need to write my own BuildProvider, but can't find any documentation explaining the relationship between a build provider and razor intellisense.

like image 518
Brad Robinson Avatar asked Jun 28 '11 02:06

Brad Robinson


2 Answers

Razor intellisense is flaky at best currently. However, if you're using VS SP1, its slightly better. The web.config workaround (as pointed in your third link) works for me in a class library as long as the extension is cshtml (haven't tried vbhtml so can't say for sure).

Also take a look here: http://razorpad.codeplex.com/ Similar to LinqPad, this will allow you to test your razor code ahead of time.

like image 109
Mrchief Avatar answered Nov 10 '22 15:11

Mrchief


The Razor editor is pretty heavily tied in to the ASP.Net runtime, in fact it actually runs ASP.Net in the background in order to collect the necessary run-time information.

My only suggestion for getting true-fidelity IntelliSense is a bit of a super-hack. Rather than a Class Library, you could make your application a Web Application Project. A WAP is actually just a class library which VS can host a website from. if you clean out ALL the extra stuff (Global.asax, web.config, etc.) you may get exactly what you're looking for. It's a workaround, and a bit of a stretch at that but give it a shot, it may just work :)

like image 23
Andrew Stanton-Nurse Avatar answered Nov 10 '22 14:11

Andrew Stanton-Nurse