Asp.net MVC Razor 视图 - CS1525:表达式术语“.”无效
Asp.net MVC Razor view - CS1525: Invalid expression term '.'
我有两个相同的 ASP.Net 4.6 MVC 项目,项目 1 在站点内使用 roslyn complier,运行良好。
c:\windows\system32\inetsrv>C:\Websites1\bin\roslyn\csc.exe
Microsoft (R) Visual C# 编译器版本 1.2.0.60325
第二个项目出现以下错误,它使用的是 .Net 框架的编译器。
c:\windows\system32\inetsrv> "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe"
Microsoft (R) Visual C# 编译器版本 4.6.1590.0
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。
我的问题是为什么第二个项目不使用 roslyn 编译器,有没有办法强制它在站点内使用 roslyn 编译器?
我也尝试过 Microsoft.Net.Compilers nuget 包。
尝试将应用程序属性中的 "Target framework" 值更改为更新的值。
将以下内容添加到 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=\"Web\" /optionInfer+"/>
</compilers>
</system.codedom>
我刚刚遇到了类似的问题,并按照 Huzzi 的建议通过将标签添加到主 Web 项目的 web.config 并确保已从 nuget 安装 'Microsoft.CodeDom.Providers.DotNetCompilerPlatform' 来修复它。
我有两个相同的 ASP.Net 4.6 MVC 项目,项目 1 在站点内使用 roslyn complier,运行良好。
c:\windows\system32\inetsrv>C:\Websites1\bin\roslyn\csc.exe Microsoft (R) Visual C# 编译器版本 1.2.0.60325
第二个项目出现以下错误,它使用的是 .Net 框架的编译器。
c:\windows\system32\inetsrv> "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe" Microsoft (R) Visual C# 编译器版本 4.6.1590.0
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。
我的问题是为什么第二个项目不使用 roslyn 编译器,有没有办法强制它在站点内使用 roslyn 编译器?
我也尝试过 Microsoft.Net.Compilers nuget 包。
尝试将应用程序属性中的 "Target framework" 值更改为更新的值。
将以下内容添加到 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=\"Web\" /optionInfer+"/>
</compilers>
</system.codedom>
我刚刚遇到了类似的问题,并按照 Huzzi 的建议通过将标签添加到主 Web 项目的 web.config 并确保已从 nuget 安装 'Microsoft.CodeDom.Providers.DotNetCompilerPlatform' 来修复它。