2012-10-04 6 views
6

テストプロジェクトにSS.Razorをインストールしました。私が単にdefault.htm - > cshtmlを変更すると、それは動作しますが、Intellisenseの構文サポートとの互換性はありません。剃刀コードは白黒の白黒です。ServiceStackはMVCなしでRazor Intellisenseサポートをオンにします

私は、プロジェクトを.net MVCプロジェクトとして開くことなく、Razorを有効にする方法を知りました。ありがとうございました!

編集------------------------------------------

は、ここに私のweb.config

(=追加の拡張子に注意してください "CSHTML" ... ...あり)VS.NETであなたのASPをインテリセンスを得るために

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

答えて

5

です.NET Webアプリケーションには、必要なビルドプロバイダが登録されている必要があります。このプロバイダは、VS.NETにコンパイラのカミソリのビュー、含める基本クラス、追加するネームスペースを指定します。 には、必要な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でintelli-senseに関する顕著な問題があるかもしれませんが、VS.NETチームがRazorのビルドプロバイダと何が変わったかを理解するまで、VS2010を使用することに戻る必要があります。

+0

テキストエディタタブを閉じてcshtmlファイルを再度開いた後で、それが動作します。しかし、タブを開いたままにしてVSをオフにして再起動しても機能しません。あなたがそのタブを閉じると... vs2010とvs2012と同じです。 – Tom

3

VS内の.cshtmlファイルを開くときに、次の警告が表示される場合は、正しい<buildProviders>がweb.configで定義されていることを確認します。

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

ServiceStack。* .dllとSystem.Web.Razor.dllを/ binディレクトリにコピーする必要があります。そうです、/ bin/debugまたは/ bin/releaseディレクトリではありません。これにより、セルフホストプロジェクトでもIntellisenseの完全なサポートが得られます(Webプロジェクトを作成する必要はありません)。

関連する問題