c# – ServiceStack在没有MVC的情况下启用Razor intellisense支持

前端之家收集整理的这篇文章主要介绍了c# – ServiceStack在没有MVC的情况下启用Razor intellisense支持前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经将SS.Razor安装到我的测试项目中.如果我只是更改default.htm – > cshtml,它的工作原理,但没有vs intellisense语法支持.因此剃刀代码是纯文本黑色和白色.

我想知道如何在不打开作为.net MVC项目的项目的情况下打开Razor.谢谢!

编辑——————————————

这是我的web.config

(注意add extension =“.cshtml”……有…)

<?xml version="1.0" encoding="utf-8"?>
<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,PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection,PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
  </configSections>
  <appSettings>
    <add key="webPages:Enabled" value="false" />
  </appSettings>
  <connectionStrings />
  <!--
    For a description of web.config changes for .NET 4.5 see http://go.microsoft.com/fwlink/?LinkId=235367.

    The following attributes can be set on the <httpRuntime> tag.
      <system.Web>
        <httpRuntime targetFramework="4.5" />
      </system.Web>
  -->
  <system.web>
    <compilation debug="true" targetFramework="4.5">
      <assemblies>
        <add assembly="System.Web.WebPages.Razor,PublicKeyToken=31BF3856AD364E35" />
      </assemblies>
      <buildProviders>
        <add extension=".cshtml" type="ServiceStack.Razor.CSharpRazorBuildProvider,ServiceStack.Razor" />
      </buildProviders>
    </compilation>
    <!--
            The <authentication> section enables configuration 
            of the security authentication mode used by 
            ASP.NET to identify an incoming user. 
        -->
    <authentication mode="Windows" />
    <!--
            The <customErrors> section enables configuration 
            of what to do if/when an unhandled error occurs 
            during the execution of a request. Specifically,it enables developers to configure html error pages 
            to be displayed in place of a error stack trace.

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm" />
            <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
        -->
    <httpHandlers>
      <add path="*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory,ServiceStack" verb="*" />
    </httpHandlers>
    <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" />
  </system.web>
  <!-- 
        The system.webServer section is required for running ASP.NET AJAX under Internet
        Information Services 7.0.  It is not necessary for prevIoUs version of IIS.
    -->
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <add path="*" name="ServiceStack.Factory" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory,ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
    </handlers>
  </system.webServer>
  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory,System.Web.Mvc,Version=3.0.0.0,PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="ServiceStack.Razor.ViewPage">
      <namespaces>
        <add namespace="ServiceStack.Html" />
        <add namespace="ServiceStack.Razor" />
        <add namespace="ServiceStack.Text" />
        <add namespace="ServiceStack.OrmLite" />
        <add namespace="Backbone.Todos" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>
</configuration>

解决方法

为了在VS.NET中获得智能,您的ASP.NET Web应用程序需要注册必要的构建提供程序,告诉VS.NET编译器razor视图,要包含的基类以及要添加的命名空间.您可以在 Razor Rockstars example project中找到必要的 Web.Config的示例.

注意:当您创建自托管控制台应用程序时,您还需要存储在Web.config中的App.Config的副本(这是VS.NET在设计时查看的内容).在开发/设计时间之外不需要或使用Web.config.

安装ServiceStack.Razor NuGet软件包时,应该已经自动包含必要的web.config信息.因此,如果您删除了应用于Web.config的web.config transform,则需要将其添加回来.如果要手动复制web.config.transform文件,则需要使用项目命名空间手动修改$rootnamespace $占位符,例如:

<add namespace="$rootnamespace$" />

<add namespace="Amce.MyWebProject" />

嗯,看起来在VS 2012上可能存在一个关于智能的突出问题,你需要恢复使用VS2010,直到我们弄清楚VS.NET团队用Razor的构建提供商改变了什么.

原文链接:https://www.f2er.com/csharp/243654.html

猜你在找的C#相关文章