asp.net-mvc <add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29093832/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-07 23:24:50  来源:igfitidea点击:

<add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

asp.net-mvcasp.net-mvc-4

提问by Mona

I get the following error below after opening and compiling my MVC4 project in VS 2010.

在 VS 2010 中打开并编译我的 MVC4 项目后,出现以下错误。

CS1705: Assembly 'SDEM, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'System.Web.Mvc, Version=4.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

CS1705:程序集“SDEM,版本=1.0.0.0,文化=中性,PublicKeyToken=null”使用“System.Web.Mvc,版本=4.0.0.1,文化=中性,PublicKeyToken=31bf3856ad364e35”,其版本高于引用的程序集'System.Web.Mvc,版本=4.0.0.0,文化=中性,PublicKeyToken=31bf3856ad364e35'

In my web.config I have

在我的 web.config 我有

    <add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

Anyone have some clue what I should do to solve this version problem?

任何人都知道我应该怎么做才能解决这个版本问题?

回答by Sarim Javaid Khan

It shows that the assembly you referenced in the project has different version(4.0.0.1) as what you have in web.config(4.0.0.0).

它表明您在项目中引用的程序集具有与 web.config(4.0.0.0) 中不同的版本 (4.0.0.1)。

Please check that the referenced assembly for System.Web.Mvc is the same as written in the web.config.

请检查 System.Web.Mvc 引用的程序集是否与 web.config 中写入的程序集相同。

If not then add reference to the appropriate assembly. Right click References -> Add Reference -> ...

如果不是,则添加对适当程序集的引用。右键单击引用 -> 添加引用 -> ...

回答by shamim

Install Nuget Package Microsoft.AspNet.Mvcfor all the project referencing System.Web.Mvc dll

为所有引用 System.Web.Mvc dll 的项目安装 Nuget Package Microsoft.AspNet.Mvc

Example:Install-Package Microsoft.AspNet.Mvc

示例:安装包 Microsoft.AspNet.Mvc

回答by Jan Jurní?ek

Solution:

解决方案:

Don't refer Nuget package components directly from the cshtml code. Instead, write an adapter calling static HtmlHelper extension methods from your custom extension methods with the same signature.

不要直接从 cshtml 代码中引用 Nuget 包组件。相反,编写一个适配器,从具有相同签名的自定义扩展方法调用静态 HtmlHelper 扩展方法。

This approach has two advantages:

这种方法有两个优点:

  • First, it automatically suppresses CS1702.
  • Secondly and above all, when you change used NuGet package, the compiler will notify you of the necessary link fixes (consisting perhaps only in changing the using command at the beginning of the cs code), while if you use NuGet component references directly from the cshtml code, run-time issues will appear.
  • 首先,它会自动抑制 CS1702。
  • 其次,最重要的是,当您更改 used NuGet 包时,编译器会通知您必要的链接修复(可能仅包括更改 cs 代码开头的 using 命令),而如果您直接从cshtml 代码,会出现运行时问题。

I just verified this migrating from PagedList/PagedList.MVC to X.PagedList/X.PagedList.MVC.

我刚刚验证了从 PagedList/PagedList.MVC 到 X.PagedList/X.PagedList.MVC 的迁移。

namespace MyMvcExtensions
{
    public static class MyHelperExtensions
    {
    ...
        public static HtmlString PagedListGoToPageForm(this HtmlHelper html, IPagedList list, string formAction)
        {
            return X.PagedList.Mvc.HtmlHelper.PagedListGoToPageForm(html, list, formAction);
        }
        public static HtmlString PagedListGoToPageForm(this HtmlHelper html, IPagedList list, string formAction, string inputFieldName)
        {
            return X.PagedList.Mvc.HtmlHelper.PagedListGoToPageForm(html, list, formAction, inputFieldName);
        }
        public static HtmlString PagedListGoToPageForm(this HtmlHelper html, IPagedList list, string formAction, X.PagedList.Mvc.Common.GoToFormRenderOptions options)
        {
            return X.PagedList.Mvc.HtmlHelper.PagedListGoToPageForm(html, list, formAction, options);
        }
        public static HtmlString PagedListPager(this System.Web.Mvc.HtmlHelper html, IPagedList list, Func<int, string> generatePageUrl)
        {
            return X.PagedList.Mvc.HtmlHelper.PagedListPager(html, list, generatePageUrl);
        }
        public static HtmlString PagedListPager(this HtmlHelper html, IPagedList list, Func<int, string> generatePageUrl, X.PagedList.Mvc.Common.PagedListRenderOptionsBase options)
        {
            return X.PagedList.Mvc.HtmlHelper.PagedListPager(html, list, generatePageUrl, options);
        }
    }
}

In your cshtml code write @using MyMvcExtensions instead of @using X.PagedList.Mvc.

在您的 cshtml 代码中写入 @using MyMvcExtensions 而不是 @using X.PagedList.Mvc。

If you will migrate to hypothetical Y.PagedList.MVC, compiler will alert you must do changes in your MyHelperExtensions class.

如果您将迁移到假设的 Y.PagedList.MVC,编译器将提醒您必须在 MyHelperExtensions 类中进行更改。