13

I need to send emails from a Windows Service and came across ActionMailer.net, a templated email system that can be used either within an ASP.Net MVC application or stand-alone.

Following the stand-alone tutorial

http://geeksharp.com/2011/07/06/actionmailer-0-6-released/

I'm at the point where I'm creating a View. However, when I type any text into the view it's underlined with a blue squiggle. Mousing over the blue squiggle reveals an error message in a tool tip:

There is no build provider registered for the extension '.cshtml' You can register one in the <compilation><buildProviders> section of machine.config or web.config

Seems I'm missing a step setting up Razor support.

What am I missing?

Eric J.
  • 147,927
  • 63
  • 340
  • 553

2 Answers2

17

That's just a warning. Your project will compile and work perfectly fine when you run it. Now in order to get tooling support for your Razor templates outside of an ASP.NET MVC application you may take a look at the following blog post.

So to cheat the Visual Studio's (stupid) Intellisense simply drop a web.config (yeah web.config) in the root of your Windows Service project with the following contents:

<configuration>
  <configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
  </configSections>

  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

  <system.web>
    <compilation targetFramework="4.0">
      <assemblies>
        <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      </assemblies>
    </compilation>
  </system.web>
</configuration>

At runtime it's absolutely unnecessary and has no effect of course (your application was working before as well). It's just to trick VS into thinking that this is a web application and provide you with Intellisense.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • I added a new web.config as you suggest with the above contents to my class library project, however I'm still not getting intellisense. You're right, though, that otherwise everything is working. Will look again in the a.m. with fresh eyes... – Eric J. Jul 21 '12 at 07:36
  • You might need to close and reopen the Razor view. Maybe even restart VS or something. For me it worked by just closing and opening the .cshtml file in VS but who knows. – Darin Dimitrov Jul 21 '12 at 07:43
  • 1
    worked for me with only close/open the *.cshtml file. No VS restart required. thanks. – fiat Nov 09 '12 at 03:02
  • I did as you said and... at my Home with Win8/VS2012/NoResharper the trick works fine :) ... but at work with Win7/VS2012/Resharper, still complaning :( – Jaider May 24 '13 at 17:12
  • After compiling things Intellisense kicked in – seebiscuit Oct 15 '18 at 16:24
13

Add the following code block in the root web.config file under system.web section:

<compilation debug="true" targetFramework="4.0" >
  <!-- In order to provide MVC Intellisense support during developement-->
  <assemblies>
    <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  </assemblies>
</compilation>
Karanvir Kang
  • 2,179
  • 19
  • 16