6

SS.Razorをテストプロジェクトにインストールしました。default.htm-> cshtmlを変更するだけで機能しますが、vsintellisense構文のサポートはありません。したがって、かみそりのコードはプレーンテキストの白黒です。

プロジェクトを.netMVCプロジェクトとして開かずにRazorをオンにする方法を知りたいです。ありがとうございました!

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

これが私のweb.configです

(addextension = "。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, 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>
4

2 に答える 2

5

VS.NET で intelli-sense を取得するには、ASP.NET Web アプリケーションに必要なビルド プロバイダーを登録する必要があります。これは、VS.NET に Razor ビューをコンパイラするよう指示し、含める基本クラスと追加する名前空間を指定します。必要なWeb.Configの例は、Razor Rockstars サンプル プロジェクトにあります。

注: セルフホスティング コンソール アプリケーションを作成する場合、Web.config に格納されている App.Config のコピーも必要です (これは、設計時に VS.NET が参照するものです)。Web.config は不要であり、開発/設計時間を超えて使用されることもありません。

ServiceStack.Razor NuGet パッケージをインストールすると、必要な web.config 情報が自動的に含まれているはずです。そのため、Web.config に適用されたweb.config 変換を削除した場合は、再度追加する必要があります。$rootnamespace$web.config.transform ファイルを手動でコピーする場合は、プロジェクトの名前空間でプレースホルダーを手動で変更する必要があります。たとえば、次のように変更します。

<add namespace="$rootnamespace$" />

<add namespace="Amce.MyWebProject" />

うーん、VS 2012 の intelli-sense に未解決の問題があるようです。VS.NET チームが Razor のビルド プロバイダーで何を変更したかがわかるまで、VS2010 の使用に戻す必要があります。

于 2012-10-04T06:14:30.490 に答える
3

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

ASP.NET ランタイム エラー: ファイルまたはアセンブリ 'ServiceStack.Razor' またはその依存関係の 1 つを読み込めませんでした。システムは、指定されたファイルを見つけることができません。

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

于 2015-06-07T13:28:28.980 に答える