2015年9月8日 星期二

CS1617錯誤

 

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

.NET Framework 4.6、ASP.NET MVC 5

ASP.MVC專案發生 CS1617錯誤 :

CS1617: Invalid option '6' for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default

 

使用Visual Studio 2015 建立一個 ASP.NET Web Application (.NET Framework 4.6)範本專案:

image

image

因為某些測試的理由,切換.NET Framework版本為 4.5

image

再執行網站,就發生以下錯誤 :

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1617: Invalid option '6' for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default

image

檢查了一下設定,目前確實已經切換回.NET Framework 4.6版了

image

尋找許久,終於發現,因為切換回.NET Framework 4.5,所以Visual Studio自動將組態檔案 system.codedom 區段換掉 :

<system.codedom>
   <compilers>
     <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701">
       <providerOption name="CompilerVersion" value="v4.0"/>
     </compiler>
     <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+">
         <providerOption name="CompilerVersion" value="v4.0"/>
     </compiler>
   </compilers>
</system.codedom>

但切回.NET Framework 4.6版時,並不會幫你切回來,所以要手動修改,還原回來:

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

沒有留言:

總瀏覽量