2012-10-04 19 views
6

He instalado SS.Razor en mi proyecto de prueba. Si simplemente cambio default.htm -> cshtml, funciona, pero sin soporte de sintaxis de intellisense. Por lo tanto, el código de la afeitadora es texto sin formato en blanco y negro.ServiceStack active Razor intellisense sin MVC

Me pregunto cómo activar Razor sin abrir el proyecto como un proyecto .NET MVC. ¡Gracias!

EDITAR ------------------------------------------

Aquí es mi web.config

(tenga en cuenta la extensión add = "cshtml" ... está ahí ...)

<?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> 

Respuesta

5

el fin de obtener Intelli-sentido en VS.NET su ASP La aplicación web .NET necesita tener registrados los proveedores de compilación necesarios que le dicen a VS.NET las vistas de razz del compilador, qué clase base incluir y qué espacios de nombres desea agregar. Puede encontrar un ejemplo del necesario Web.Config en el Razor Rockstars example project.

Nota: Cuando está creando una aplicación de consola autohospedada, también necesita una copia de la App.Config almacenada en Web.config (que es lo que VS.NET observa, en tiempo de diseño). El Web.config no es necesario ni se usa más allá del tiempo de desarrollo/diseño.

La información web.config necesaria ya debe estar incluida automáticamente cuando instale el paquete ServiceStack.Razor NuGet. Por lo tanto, si eliminó el web.config transform que se aplicó a su Web.config, debe volver a agregarlo. Si desea copiar el archivo manualmente web.config.transform tiene que modificar manualmente el marcador de posición $rootnamespace$ con el espacio de nombres del proyecto, por ejemplo, cambio:

<add namespace="$rootnamespace$" /> 

a

<add namespace="Amce.MyWebProject" /> 

Hmmm, Parece que hay puede ser un problema pendiente con intelli-sense en VS 2012, tendrá que volver a utilizar VS2010 hasta que descubramos qué ha cambiado el equipo de VS.NET con los proveedores de compilación de Razor.

+0

Descubrí después de cerrar la pestaña del editor de texto y abrir nuevamente el archivo cshtml, funciona. Pero no funciona incluso si deja la pestaña abierta y apaga VS y lo reinicia. SOLO funciona si cierra esa pestaña ... Lo mismo para vs2010 y vs2012. – Tom

3

Además de asegurarse de tener el <buildProviders> correcto definido en web.config, si aparece la siguiente advertencia al abrir archivos .cshtml en VS.

ASP.NET runtime error: Could not load file or assembly 'ServiceStack.Razor' or one of its dependencies. The system cannot find the file specified.

tiene que copiar ServiceStack. *. Dll y System.Web.Razor.dll en el directorio/bin. Eso es correcto, NO los directorios/bin/debug o/bin/release. Esto le brindará soporte total de Intellisense, incluso en un proyecto auto alojado (sin necesidad de crear un proyecto web).