11

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:

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.

Community
  • 1
  • 1
Brad Robinson
  • 44,114
  • 19
  • 59
  • 88
  • So am I to understand that you tried to drop a web.config from another MVC project into your class library project and it didn't work? Which web.config did you take: the one from the root, or the one from the Views subfolder? – Fyodor Soikin Nov 28 '11 at 05:29

2 Answers2

1

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.

Mrchief
  • 75,126
  • 20
  • 142
  • 189
1

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 :)

Andrew Stanton-Nurse
  • 6,274
  • 1
  • 28
  • 20