2012-10-04 7 views
6

Test projeme SS.Razor'u yükledim. Eğer default.htm -> cshtml 'i değiştirirsem çalışır, fakat intellisense sözdizimi desteği olmadan çalışır. Yani traş makinesi kodu siyah beyaz ve sade bir yazıdır.ServiceStack açın MVC olmadan jilet intellisense desteği

Razor'u, projeyi bir .net MVC projesi olarak açmadan nasıl açacağımı merak ediyorum. Teşekkür ederim!

DÜZENLEME ------------------------------------------

İşte benim web.config

(= eklenti uzantısı not "cshtml" ... ... yoktur) VS.NET içinde ASP intelli-fikir edinmek amacıyla

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

cevap

5

olduğunu .NET web uygulamasının, derleyici jilet görünümlerine VS.NET, hangi temel sınıfın ekleneceğini ve eklenmesini istediğiniz ad alanlarına bildiren, gerekli yapı sağlayıcılarına sahip olması gerekir. Razor Rockstars example project'da gerekli Web.Config örneğini bulabilirsiniz. Not: Kendi kendini barındıran bir Konsol Uygulaması oluşturduğunuzda, Web.config dosyasında saklanan App.Config dosyasının bir kopyasına da gereksinim duyarsınız (bu, VS.NET'in tasarım zamanında neye baktığını gösterir). Web.config, geliştirme/tasarım süresinin ötesinde gerekli değildir veya kullanılmamaktadır.

ServiceStack.Razor NuGet paketini yüklediğinizde gerekli web.config bilgisi otomatik olarak eklenmelidir. Web.config dosyanıza uygulanmış olan web.config transform kodunu sildiyseniz, geri eklemeniz gerekir. el web.config.transform dosyayı kopyalamak isterseniz elle proje ad, örneğin değişim ile $rootnamespace$ yer tutucu değiştirmeniz gerekir:

<add namespace="$rootnamespace$" /> 

için
<add namespace="Amce.MyWebProject" /> 

Hmmm, orada benziyor VS 2012'de intelli-sense ile göze çarpan bir sorun olabilir, VS2010'u, Razor'un yapım sağlayıcıları ile ne değiştiğini anlayana kadar geri dönmeniz gerekecektir.

+0

Metin düzenleyici sekmesini kapattıktan ve cshtml dosyasını tekrar açtıktan sonra keşfettim, işe yarıyor. Ancak sekmeyi açık bırakıp VS'yi kapatıp yeniden başlatsanız bile çalışmaz. SADECE bu sekmeyi kapatırsanız çalışır ... vs2010 ve vs2012 için aynı. – Tom

3

Web.config dosyasında tanımlı doğru <buildProviders> olduğundan emin olmak için, VS'deki .cshtml dosyaları açılırken aşağıdaki uyarıyı görüyorsanız.

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

Sen/bin dizine ServiceStack. *. Dll ve System.Web.Razor.dll kopyalamanız gerekir. Thats right,/bin/debug veya/bin/release dizinleri. Bu, kendi kendini barındıran bir projede bile (bir web projesi oluşturmaya gerek olmadan) tam bir Intellisense desteği sağlayacaktır.