2013年12月24日 星期二

讓 Web.config 支援 .Net 3.5 的 Compiler



在舊的 .Net  2.0專案升級成 3.5 後,總是會想要使用新的功能。但很奇怪的,是我程式開發的電腦上可以正常執行,但將程式放到上線區後,就會出現下面的錯誤訊息:

) expected




剛開始我還以為是上線區的 .Net Framework 沒更新,還停留在 .Net 2.0。雖然會有個念頭這是主機管理員忘了做設定所致,但卻沒忘記很多時候,其實是自己的問題。所以就開始根據有夠簡潔的 「) expected」訊息,去找尋線索。

還好在「Linq End of statement expected. 」這篇討論裡有提到,原來有可能是 Web.Config 檔沒有設定好的關係。因為原先上線區的 Web.Config 是承襲以前 .Net 2.0 時所留下來的。於是根據文章的建議,在 Web.config 裡的 <configuration>...</configuration> 區塊加上以下的設定,就可以正常執行了。
<!-- 宣告使用 .net 3.5 的 compiler -->
<system.codedom>
 <compilers>
   <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, 

Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
  <providerOption name="CompilerVersion" value="v3.5"/>
  <providerOption name="WarnAsError" value="false"/></compiler>
   <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.VisualBasic.VBCodeProvider, System, 

Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
  <providerOption name="CompilerVersion" value="v3.5"/>
  <providerOption name="OptionInfer" value="true"/>
  <providerOption name="WarnAsError" value="false"/></compiler>
   </compilers>
</system.codedom>


參考:
01:Linq End of statement expected.

沒有留言:

張貼留言