Cshtml文件中的C#6.0功能的Resharper问题

Jon*_*yce 6 resharper visual-studio-2017

我刚刚在Windows 10(1703)上安装了一台带有VS2017 Pro(15.2)和Resharper(2017.1.2)的新PC.

我已经打开了一个现有的解决方案,Resharper突出了CSHTML文件中的大量问题.我看过的都是字符串插值和空条件运算符,消息是"C#6.0语言特性",好像这是一个错误.所有项目仍然编译并运行正常,字符串插值和空条件运算符不会突出显示为普通CS文件中的错误.

解决方案中的错误/警告 剃刀编辑

解决方案中的项目都设置为Framework 4.6.1,并且C#语言级别设置为Default.我已经设置了语言级CSharp60sln.DotSettings文件,而现在项目的所有显示的语言水平C# 6.0,但ReSharper的还是呻吟字符串插值误差.清除Resharper缓存没有帮助.

该解决方案在最近安装的另一台PC上运行,完全没有错误.唯一的区别是在另一台PC上它是一个全新的版本,而这个版本是新的C:\驱动器上的新操作系统,但代码是在第二个尚未更改的驱动器上.

我的views文件夹中的web.config如下所示:

<?xml version="1.0"?>

<configuration>
  <configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
  </configSections>

  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization"/>
        <add namespace="System.Web.Routing" />
        <add namespace="Az.Ems.Web" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

  <appSettings>
    <add key="webpages:Enabled" value="false" />
  </appSettings>

  <system.webServer>
    <handlers>
      <remove name="BlockViewHandler"/>
      <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
    </handlers>
  </system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)

主web.config的codedom部分看起来像这样

 <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /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.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
    </compilers>
  </system.codedom>
Run Code Online (Sandbox Code Playgroud)

cit*_*att 17

尝试将编译器标志设置为/langversion:6而不是default.ReSharper似乎试图将版本解析为数字,这将失败并将ReSharper保留在C#5.

<system.codedom>
  <compilers>
    <compiler language="c#;cs;csharp" 
              extension=".cs"
              type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.5.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.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
              warningLevel="4"
              compilerOptions="/langversion:6 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
  </compilers>
</system.codedom>
Run Code Online (Sandbox Code Playgroud)