MVC4安装后,MVC3停止工作

5

可能是重复的问题:
安装MVC 4 Beta时出现并行安装错误

我正在开发一个MVC3应用程序。 我想开始开发一个MVC4应用程序。 但是,在安装MVC 4后(非beta版本),MVC 3应用程序停止工作,出现一些dll冲突错误。 其中一种错误是这样的:

The type 'System.Web.Helpers.Json' exists in both 'c:\Windows\Microsoft.NET\assembly\GAC_MSIL    \System.Web.Helpers\v4.0_2.0.0.0__31bf3856ad364e35\System.Web.Helpers.dll' and 'c:\Windows    \Microsoft.NET\assembly\GAC_MSIL\System.Web.Helpers    \v4.0_1.0.0.0__31bf3856ad364e35\System.Web.Helpers.dll' `at      System.Web.Compilation.AssemblyBuilder.Compile()
   at System.Web.Compilation.BuildProvidersCompiler.PerformBuild()
   at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)
   at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean    noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean    ensureIsUpToDate)
   at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context,    VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile,    Boolean throwIfNotFound, Boolean ensureIsUpToDate)
   at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath,    HttpContext context, Boolean allowCrossApp, Boolean throwIfNotFound)
   at System.Web.Compilation.BuildManager.GetObjectFactory(String virtualPath, Boolean throwIfNotFound)
   at System.Web.Mvc.BuildManagerWrapper.System.Web.Mvc.IBuildManager.FileExists(String virtualPath)
   at System.Web.Mvc.BuildManagerViewEngine.FileExists(ControllerContext controllerContext, String   virtualPath)
   at System.Web.Mvc.VirtualPathProviderViewEngine.GetPathFromGeneralName(ControllerContext controllerContext, List`1 locations, String name, String controllerName, String areaName, String cacheKey, String[]& searchedLocations)
   at System.Web.Mvc.VirtualPathProviderViewEngine.GetPath(ControllerContext controllerContext, String[] locations, String[] areaLocations, String locationsPropertyName, String name, String controllerName, String cacheKeyPrefix, Boolean useCache, String[]& searchedLocations)
   at System.Web.Mvc.VirtualPathProviderViewEngine.FindView(ControllerContext controllerContext, String viewName, String masterName, Boolean useCache)
   at System.Web.Mvc.ViewEngineCollection.<>c__DisplayClassc.<FindView>b__b(IViewEngine e)
   at System.Web.Mvc.ViewEngineCollection.Find(Func`2 lookup, Boolean trackSearchedPaths)
   at System.Web.Mvc.ViewEngineCollection.Find(Func`2 cacheLocator, Func`2 locator)
   at System.Web.Mvc.ViewEngineCollection.FindView(ControllerContext controllerContext, String viewName, String masterName)
   at System.Web.Mvc.ViewResult.FindView(ControllerContext context)
   at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1c.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1c.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)`

这个问题应该如何解决?

我应该遵循这个吗?https://dev59.com/bGox5IYBdhLWcg3wDgEz - amesh
1个回答

14

我在这里找到了解决方案:链接

安装ASP.NET MVC 4会导致ASP.NET MVC 3 RTM应用程序崩溃。使用RTM版本(而不是ASP.NET MVC 3工具更新版本)创建的ASP.NET MVC 3应用程序需要进行以下更改才能与ASP.NET MVC 4并存。如果不进行这些更新就构建项目,会导致编译错误。 需要进行的更新:

在根Web.config文件中,添加一个新的webPages:Version条目,其键为1.0.0.0,值为空。

<appSettings>
<add key="webpages:Version" value="1.0.0.0"/>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>

在解决方案资源管理器中,右键单击项目名称,然后选择“取消加载项目”。然后再次右键单击名称,选择“编辑 ProjectName.csproj”。 找到以下程序集引用:

<Reference Include="System.Web.WebPages"/> 
<Reference Include="System.Web.Helpers" />

将它们替换为以下内容:

<Reference Include="System.Web.WebPages, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL "/> 
<Reference Include="System.Web.Helpers, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />

保存更改,关闭正在编辑的项目(.csproj)文件,然后右键单击该项目并选择重新加载。

(你也可以在文本编辑器中手动编辑MVC项目文件。右键单击.csproj文件,使用任何文本编辑器打开并仔细编辑XML)


谢谢!在我的情况下,我只需要替换.csproj文件中的**<Reference Include="System.Web.Helpers" />**这一行,然后重新编译,就可以正常工作了!非常感谢。 - MarioAraya

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接