Asp.net MVC剃刀视图-CS1525:无效的表达式术语“." [英] Asp.net MVC Razor view - CS1525: Invalid expression term '.'

查看:510
本文介绍了Asp.net MVC剃刀视图-CS1525:无效的表达式术语“."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个相同的ASP.Net 4.6 MVC项目,项目1在站点内使用roslyn编译器,效果很好.

I have two identical ASP.Net 4.6 MVC project, project 1 is using roslyn complier within the site which is working fine.

c:\ windows \ system32 \ inetsrv> C:\ Websites1 \ bin \ roslyn \ csc.exe Microsoft(R)Visual C#编译器版本1.2.0.60325

c:\windows\system32\inetsrv>C:\Websites1\bin\roslyn\csc.exe Microsoft (R) Visual C# Compiler version 1.2.0.60325

在第二个项目中,我得到下面的错误,它使用的是.Net框架中的编译器.

With the second project I'm getting the error below, it's using the complier from .Net framework.

c:\ windows \ system32 \ inetsrv>"C:\ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ csc.exe" Microsoft(R)Visual C#编译器版本4.6.1590.0

c:\windows\system32\inetsrv> "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe" Microsoft (R) Visual C# Compiler version 4.6.1590.0

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

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

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 .

I've used Install-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform on both project.

我的问题是,为什么第二个项目不使用roslyn编译器,是否有一种方法可以强制它在站点内使用roslyn编译器?

My question is why is the second project not using roslyn complier and is there a way to force it to use the roslyn complier within the site?

我也尝试过 Microsoft.Net.Compilers nuget程序包.

I've also tried Microsoft.Net.Compilers nuget package.

推荐答案

在将以下内容添加到web.config中后,它现在可以工作

Got it working now after adding the following to the 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>

这篇关于Asp.net MVC剃刀视图-CS1525:无效的表达式术语“."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆