2015年8月11日 星期二

Tips : Please use language version 6 or grater

 

Tool:Visual Studio 2015 Enterprise
OS:Windows 10
C# 6

.NET Framework 4.6、ASP.NET MVC 5

試著使用VS2015開啟MVC5專案,使用C# 6的新語法,結果出現如下錯誤:

Feature ‘xxxx’ is not available in C# 5. Please use language version 6 or grater

image

 


目前專案不認識新語法!!

  • 解法: 將網站的Target Framework 版本設為4.6

image

 

 

  • 使用Nuget安裝套件

Install-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform

 

  • 安裝完成會自動加入以下組態

<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>

 

這樣就可以認得C# 6新語法了!!

沒有留言:

總網頁瀏覽量