web-dev-qa-db-ja.com

Asp.net MVC Razorビュー-CS1525:無効な式の用語 '。'

2つの同一のASP.Net4.6 MVCプロジェクトがあります。プロジェクト1は、正常に機能しているサイト内でroslyncomplierを使用しています。

c:\ windows\system32\inetsrv> C:\ Websites1\bin\roslyn\csc.exe Microsoft(R)Visual C#コンパイラバージョン1.2.0.60325

以下のエラーが発生する2番目のプロジェクトでは、.Netフレームワークのコンパイラーを使用しています。

c:\ windows\system32\inetsrv> "C:\ Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe" Microsoft(R)Visual C#コンパイラバージョン4.6.1590.

Line 6: @if (!Model?.Item?.IsDerived(Templates.PageMetadata.ID) ?? true) Line 7: { Line 8: return;

c:\Website2\Views\metadata.cshtml(6,17): error CS1525: Invalid expression term '.' c:\Website2\Views\metadata.cshtml(6,18): error CS1003: Syntax error, ':' expected c:\Website2\Views\metadata.cshtml(6,23): error CS1525: Invalid expression term '.' c:\Website2\Views\metadata.cshtml(6,24): error CS1003: Syntax error, ':' expected c:\Website2\Views\metadata.cshtml(6,68): error CS1002: ; expected c:\Website2\Views\metadata.cshtml(6,68): error CS1525: Invalid expression term ')' c:\Website2\Views\metadata.cshtml(6,69): error CS1002: ; expected

両方のプロジェクトでInstall-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatformを使用しました。

私の質問は、2番目のプロジェクトがroslyn complierを使用していないのはなぜですか?サイト内でroslyn complierを使用するように強制する方法はありますか?

私も試しましたMicrosoft.Net.Compilers nugetパッケージ。

8
Huzzi

以下をweb.configに追加した後、動作するようになりました

<system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
    </compilers>
  </system.codedom>
11
Huzzi

私はちょうど同様の問題に直面し、Huzziが提案したように、メインWebプロジェクトのweb.configにタグを追加し、nugetから「Microsoft.CodeDom.Providers.DotNetCompilerPlatform」をインストールしたことを確認することで修正しました。

3
TamerM

アプリケーションプロパティの「ターゲットフレームワーク」の値を新しい値に変更してみてください。

2
Samuil Petrov