C# MVC4 应用程序尝试引用较新版本的 System.Web.WebPages.Razor 的问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19499121/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Problems with an MVC4 application trying to reference a newer version of System.Web.WebPages.Razor
提问by wmelon
I've been working on a mvc4 web application for the last few months. Everything was working great until friday when I ran an update-package in nuget to make sure that I had the most recent versions of my libraries.
过去几个月我一直在研究 mvc4 Web 应用程序。直到星期五我在 nuget 中运行更新包以确保我拥有最新版本的库时,一切都运行良好。
Now when I try to view anything in the application it tells me that it get the error
Could not load file or assembly 'System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
现在,当我尝试查看应用程序中的任何内容时,它告诉我它收到错误
Could not load file or assembly 'System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
I've checked my web.config and my packages.config and nowhere am I referencing System.Web.WebPages.Razor, Version=3.0.0.0
我已经检查了我的 web.config 和我的packages.config,但我没有引用任何地方 System.Web.WebPages.Razor, Version=3.0.0.0
I've added a dependentAssembly block to my web.config with version 2.0.0.0
我在版本 2.0.0.0 的 web.config 中添加了一个dependentAssembly 块
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
and made sure that the web.config in my views directory also specifies v2.0.0.0
并确保我的视图目录中的 web.config 也指定了 v2.0.0.0
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
I've also made sure that the version referenced in my references is 2.0.0.0. I've tried removing it and readding it. I've tried making sure that the server has the most recent version of the .net framework installed.
我还确保我的参考资料中引用的版本是 2.0.0.0。我试过删除它并阅读它。我已尝试确保服务器安装了最新版本的 .net 框架。
I've tested this both on the server and locally and get the same error message.
我已经在服务器上和本地测试了这个并得到相同的错误消息。
Locally I see this in the error log LOG: Post-policy reference: System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
But i can't find any information on what is causing that.
在本地,我在错误日志中看到了这一点,LOG: Post-policy reference: System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
但我找不到有关导致该问题的原因的任何信息。
I'm developing it in Visual Studio 2012 premium.
我正在 Visual Studio 2012 premium 中开发它。
Anyone have any ideas?
谁有想法?
采纳答案by Chris Pratt
I've checked my web.config and my packages.config and nowhere am I referencing System.Web.WebPages.Razor, Version=3.0.0.0
我已经检查了我的 web.config 和我的 packages.config 并且没有任何地方引用 System.Web.WebPages.Razor, Version=3.0.0.0
That's your problem. I've ran into similar issues myself a few times. Though, it tends to happen mostly when dealing with multiple projects in one solution; I'm not sure if that applies in your case. Nevertheless, the issue boils down to the actual project reference having been "upgraded", but your web.config and packages.config notreferencing that upgraded package. If you go into your project references and view properties on the Razor reference, I'd bet dollars to dimes that it says 3.0.0.0 there. You can either remove the reference and re-add it by browsing into the bin directory of the lower versioned package or upgrade it completely.
那是你的问题。我自己也遇到过几次类似的问题。但是,在一个解决方案中处理多个项目时往往会发生这种情况。我不确定这是否适用于您的情况。尽管如此,问题归结为实际项目引用已被“升级”,但您的 web.config 和 packages.config未引用该升级包。如果你进入你的项目引用并查看 Razor 引用上的属性,我敢打赌它说 3.0.0.0 那里说 3.0.0.0。您可以通过浏览到较低版本包的 bin 目录删除引用并重新添加它,或者完全升级它。
Like I said, this usually occurs in multi-project solutions when you upgrade one project but not another. The easiest way to fix it is to manage nuget packages for the entire solution. You'll then probably see multiple listings for Razor where one is checked for one or more projects but not some and vice-versa. Remove the older version of Razor (uncheck the associated projects) for the the older version and apply. Then go back to the new version of Razor and apply it to all projects it's missing from.
就像我说的,当您升级一个项目而不是另一个项目时,这通常发生在多项目解决方案中。修复它的最简单方法是管理整个解决方案的 nuget 包。然后,您可能会看到 Razor 的多个列表,其中一个检查一个或多个项目,但不检查一些,反之亦然。为旧版本删除旧版本的 Razor(取消选中关联的项目)并应用。然后返回到新版本的 Razor 并将其应用到它缺失的所有项目。
回答by Boris
I had a same problem, my WCF service was not working. Solution was deleting System.Web.Mvc.dll from my BIN folder.
我遇到了同样的问题,我的 WCF 服务无法正常工作。解决方案是从我的 BIN 文件夹中删除 System.Web.Mvc.dll。
回答by rocktheartsm4l
For me all I had to do was change 'Specific Version' from False to True and it started working.
对我来说,我所要做的就是将“特定版本”从 False 更改为 True,然后它就开始工作了。
回答by Steven Chambers
I had the same problem, except that when going through the steps described in Chris Pratt's answer, System.Web.Websites.Razor was still showing version 2.0.0.0, even though I had just gone through the process of updating it to 3.0.0.0 through NuGet.
我遇到了同样的问题,除了在执行 Chris Pratt 的回答中描述的步骤时,System.Web.Websites.Razor 仍然显示版本 2.0.0.0,即使我刚刚完成了将其更新到 3.0.0.0 的过程通过 NuGet。
What ended up fixing it for me was uninstalling the MVC package with NuGet and installing it again (and thus reinstalling its dependancies: System.Web.Websites and System.Web.Razor)
最终为我修复的是使用 NuGet 卸载 MVC 包并再次安装它(从而重新安装其依赖项:System.Web.Websites 和 System.Web.Razor)
回答by Tech
Right click on the assembly (in References) and on its content menu select Properties to see its properties on Visual Studio's Properties tab. Under its look for a Copy Local property and ensure its set to True.
右键单击程序集(在“参考”中)并在其内容菜单上选择“属性”以在 Visual Studio 的“属性”选项卡上查看其属性。在其下查找 Copy Local 属性并确保将其设置为 True。