13

我需要从 Windows 服务发送电子邮件并遇到ActionMailer.net,这是一个模板电子邮件系统,可以在 ASP.Net MVC 应用程序中使用或独立使用。

按照独立教程

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

我正处于创建视图的地步。但是,当我在视图中键入任何文本时,它会带有蓝色曲线下划线。将鼠标悬停在蓝色曲线上会显示工具提示中的错误消息:

没有为扩展“.cshtml”注册构建提供程序您可以在<compilation><buildProviders>machine.config 或 web.config 部分注册一个

似乎我缺少设置 Razor 支持的步骤。

我错过了什么?

4

2 回答 2

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.

于 2012-07-21T07:06:27.357 回答
13

在 system.web 部分下的根 web.config 文件中添加以下代码块:

<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>
于 2013-01-04T20:31:17.570 回答