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

在公司Download / 執行網上教學的Sample Code 來測試時
久不久便會出現以下的錯
CS1617: Invalid option ‘6’ for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default
CS1617: Invalid option '6' for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default

這是因為Sample Code是用了Visual Studio 2015 來建立的 Default的 .Net Framework4.5.2 / 4.6
而公司是使用Visual Studio 2013.Net Framework是 4.5

所以Web.Config上有小小Mis-match
解決方便 十分簡單
我們只需要更改 compilerOptions=”/langversion:6 改變成 compilerOptions=”/langversion:5 便可以了

更改前

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

Original Web.config
更新後

 <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:5 /nowarn:1659;1699;1701">
 <providerOption name="CompilerVersion" value="v4.0"/>
 </compiler>
 <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>

Web.config for VS2013
CS1617 Issue Fixed
Hope you find it useful

Leave a Reply