2012-10-15 114 views
1

我有一個使用System.Web.Mvc版本3和System.Web.WebPages版本1的類庫。安裝Visual Studio 2012(MVC版本4 )我在Visual Studio 2010中編譯該類庫的一個問題:安裝MVC 4後MVC 3 System.Web.WebPages程序集引用錯誤4

Assembly 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' uses 'System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' c:\Program Files\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies\System.Web.Mvc.dll 

在這個項目中,我不希望使用MVC 4呢。

+1

爲了減輕疼痛,使用nuget安裝mvc 4 :) – Aviatrix

回答

3

我在文本編輯器打開的.csproj文件,發現下面一行:

<Reference Include="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> 
    <SpecificVersion>False</SpecificVersion> 
    <HintPath>C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 3\Assemblies\System.Web.Mvc.dll</HintPath> 
</Reference> 

我注意到HintPath不存在我的機器上(Windows 7的32位),所以很明顯的Visual Studio自動採用最新版本(可能在GAC中)。我從項目引用中刪除了System.Web.Mvc,並通過瀏覽到正確的路徑再次添加它。 .csproj現在看起來像這樣:

<Reference Include="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> 
    <SpecificVersion>False</SpecificVersion> 
    <HintPath>..\..\..\..\..\..\..\..\Program Files\Microsoft ASP.NET\ASP.NET MVC 3\Assemblies\System.Web.Mvc.dll</HintPath> 
</Reference> 

還要確保Version參數設置爲3.0.0.0。

+0

我遇到了一個非常類似的問題。我的提示路徑是查看程序文件而不是程序文件(x86),即使在更新之後,該項目仍然試圖使用4.0版本,即使該參考文件明確地告訴它使用3.0。然後,我將SpecificVersion屬性設置爲True,並強制項目使用3.0。 –