ServiceStack 在没有 MVC 的情况下打开 Razor 智能感知支持 [英] ServiceStack turn on Razor intellisense support without MVC

查看:52
本文介绍了ServiceStack 在没有 MVC 的情况下打开 Razor 智能感知支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将 SS.Razor 安装到我的测试项目中.如果我只是更改 default.htm -> cshtml,它可以工作,但没有 vs intellisense 语法支持.所以剃刀代码是纯文本黑白.

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

编辑 ------------------------------------------

这是我的 web.config

(注意添加扩展名=".cshtml" ...在那里...)

<add key="webPages:Enabled" value="false"/></appSettings><连接字符串/><!--有关 .NET 4.5 的 web.config 更改的说明,请参阅 http://go.microsoft.com/fwlink/?LinkId=235367.可以在 <httpRuntime> 上设置以下属性.标签.<system.Web><httpRuntime targetFramework="4.5"/></system.Web>--><system.web><编译调试="true" targetFramework="4.5"><组件><add assembly="System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/></组件><buildProviders><add extension=".cshtml" type="ServiceStack.Razor.CSharpRazorBuildProvider, ServiceStack.Razor"/></buildProviders></编译><!--<认证>部分启用配置使用的安全认证模式ASP.NET 来识别传入的用户.--><认证模式=Windows"/><!--<customErrors>部分启用配置如果/当发生未处理的错误时该怎么办在执行请求的过程中.具体来说,它使开发人员能够配置 html 错误页面以代替错误堆栈跟踪显示.<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><!--在 Internet 下运行 ASP.NET AJAX 需要 system.webServer 部分信息服务 7.0.以前版本的 IIS 不需要.--><system.webServer><validation validateIntegratedModeConfiguration="false"/><处理程序><add path="*" name="ServiceStack.Factory" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true"/></处理程序></system.webServer><system.web.webPages.razor><host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/><pages pageBaseType="ServiceStack.Razor.ViewPage"><命名空间><add namespace="ServiceStack.Html"/><add namespace="ServiceStack.Razor"/><add namespace="ServiceStack.Text"/><add namespace="ServiceStack.OrmLite"/><add namespace="Backbone.Todos"/></命名空间></页面></system.web.webPages.razor></配置>

解决方案

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

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

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

<add namespace="$rootnamespace$"/>

嗯,看起来 VS 2012 上的智能感知可能存在突出问题,您需要恢复使用 VS2010,直到我们弄清楚 VS.NET 团队对 Razor 的构建提供程序进行了哪些更改.

I have installed SS.Razor into my test project. If i simply change default.htm -> cshtml, it works, but without vs intellisense syntax support. So the razor code is plain text black and white.

I wonder how to turn on Razor without opening up the project as a .net MVC project. Thank you!

EDIT ------------------------------------------

Here is my web.config

(note the add extension=".cshtml" ... is there ...)

<?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, 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>
  <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, Version=1.0.0.0, Culture=neutral, 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, Culture=neutral, 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>

解决方案

In order to get intelli-sense in VS.NET your ASP.NET web application needs to have the necessary build providers registered which tell VS.NET to compiler razor views, what base class to include and what namespaces you want added. You can find an example of the necessary Web.Config in the Razor Rockstars example project.

Note: When you're creating a self-hosting Console Application you also need a copy of the App.Config stored in Web.config (which is what VS.NET looks at, at design-time). The Web.config isn't needed or used beyond development/design time so does.

The necessary web.config info should already be automatically included when you install the ServiceStack.Razor NuGet package. So if you've deleted the web.config transform that was applied to your Web.config, you need to add it back. If you want to copy the web.config.transform file manually you need to manually modify the $rootnamespace$ placeholder with your project namespace, e.g change:

<add namespace="$rootnamespace$" />

to

<add namespace="Amce.MyWebProject" />

Hmmm, It looks like there may be an outstanding issue with intelli-sense on VS 2012, you will need to revert back to using VS2010 until we figure out what the VS.NET team has changed with Razor's build providers.

这篇关于ServiceStack 在没有 MVC 的情况下打开 Razor 智能感知支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆