【茶包射手日記】ASP.NET MVC 4專案4.5 Framework轉4.0

記錄在Windows Server 2003 IIS6部署ASP.NET MVC 4專案的經驗。

部署第一步是複製檔案、設定Web Application、萬用字元應用程式對應等。(相關眉角可參考保哥的ASP.NET 4.0 安裝在 IIS6 最常遇到的四個問題)

第一枚茶包現身! 當初新增專案時一時不察,選了.NET Framework 4.5,web.config有兩行設定:

<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />

移到Windows 2003立即引爆。由於Windows 2003不支援.NET 4.5,只好乖乖地開Visual Studio將MVC專案降版為.NET 4.0。web.config內容被Visual Studio改成:

<compilation debug="true" targetFramework="4.0"/>
<httpRuntime/>

重新部署檔案,正期待看到網頁,另一枚茶包冒出來澆我一頭冷水:

[FileNotFoundException: Could not load file or assembly 'System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.]
   System.Web.Http.GlobalConfiguration..cctor() +0

[TypeInitializationException: The type initializer for 'System.Web.Http.GlobalConfiguration' threw an exception.]
   System.Web.Http.GlobalConfiguration.get_Configuration() +14
   MyWeb.Areas.HelpPage.HelpPageAreaRegistration.RegisterArea(AreaRegistrationContext context) +94
   System.Web.Mvc.AreaRegistration.CreateContextAndRegister(RouteCollection routes, Object state) +104
   System.Web.Mvc.AreaRegistration.RegisterAllAreas(RouteCollection routes, IBuildManager buildManager, Object state) +195
   System.Web.Mvc.AreaRegistration.RegisterAllAreas(Object state) +27
   MyWeb.WebApiApplication.Application_Start() +12

推測是Visual Studio的4.5到4.0轉換不夠完整所致,決定另開一個.NET 4.0 MVC4專案比對最直接有效。很快找到一項明顯差異:

.NET 4.5轉.NET 4.0的MVC4專案,System.Net.Http.dll的參照來源是:
C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies\System.Net.Http.dll

而原生.NET 4.0 MVC4專案,System.Net.Http.dll則來自NuGet:
..\packages\Microsoft.Net.Http.2.0.20710.0\lib\net40\System.Net.Http.dll

由於System.Net.Http在.NET 4.5才納入BCL,猜想就是造成在.NET 4.0無法運作的元凶。問題專案先移除System.Net.Http參照,重新取用NuGet提供的版本,重新編譯、發佈後bin目錄多了System.Net.Http.dll與System.Net.Http.WebRequest.dll兩個檔案,再試一次,問題排除!!

歡迎推文分享:
Published 12 September 2013 11:47 PM 由 Jeffrey
Views: 17,236



意見

# Kai said on 13 September, 2013 02:48 AM

第一個MVC專案剛寫好準備上線,也遇到Framework 4.5沒辦法裝到W2003問題。

早上看到這篇,原本很高興...

但下午測試後,卻發現之前從NuGet安裝的套件也會衝到,甚至有些套件如Enterprise Library 6,也不支援Framework 4.

唉...

# Jeffrey said on 13 September, 2013 03:28 AM

to Kai, 原來Enterprise Library 6已限定.NET 4.5+(筆記....),看來要在4.0跑只有降版一途~  

你的看法呢?

(必要的) 
(必要的) 
(選擇性的)
(必要的) 
(提醒: 因快取機制,您的留言幾分鐘後才會顯示在網站,請耐心稍候)

5 + 3 =

搜尋

Go

<September 2013>
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345
 
RSS
創用 CC 授權條款
【廣告】
twMVC
最新回應

Tags 分類檢視
關於作者

一個醉心技術又酷愛分享的Coding魔人,十年的IT職場生涯,寫過系統、管過專案, 也帶過團隊,最後還是無怨無悔地選擇了技術鑽研這條路,近年來則以做一個"有為的中年人"自許。

文章典藏
其他功能

這個部落格


Syndication