ActionMailer.Net Stand-Alone: There is no build pr

2019-02-03 07:57发布

问题:

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?

回答1:

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.



回答2:

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>