ASP.NET MVC 5 Ninject:Ninject.MVC3 / 5

时间:2015-01-22 21:25:21

标签: c# asp.net asp.net-mvc-5 nuget ninject

我想将Ninject添加到ASP.NET MVC 5项目中。

NinjectWebCommon.cs不在App_Start文件夹中。 在一个教程中,我读到Ninject.MVC3应该通过Nuget添加。

如果我进入'Manag NuGet Packages'并搜索'Ninject',我会得到以下信息:

NuGet Search: Ninject

我找到'Ninject.MVC5'。符号表示已安装此软件包。

但是当我去“已安装的包裹”时,我会看到以下内容:

Installed NuGet Ninject Packages

在这里我找不到这个包。

为什么这里没有列出包裹?

我应该安装'Ninject.MVC3',虽然似乎安装了'Ninject.MVC5'吗?


编辑:


我现在通过Package Manager控制台安装了NuGet包,如下所示:

Each package is licensed to you by its owner. Microsoft is not responsible for, nor does it grant any licenses to, third-party packages. Some packages may include dependencies which are governed by additional licenses. Follow the package source (feed) URL to determine any dependencies.

Package Manager Console Host Version 2.8.50926.663

Type 'get-help NuGet' to see all available NuGet commands.

PM> Install-Package Ninject.MVC5
Attempting to resolve dependency 'Ninject (≥ 3.2.0.0 && < 3.3.0.0)'.
Attempting to resolve dependency 'Ninject.Web.Common.WebHost (≥ 3.0.0.0)'.
Attempting to resolve dependency 'Ninject.Web.Common (≥ 3.2.0.0 && < 3.3.0.0)'.
Attempting to resolve dependency 'WebActivatorEx (≥ 2.0 && < 3.0)'.
Attempting to resolve dependency 'Microsoft.Web.Infrastructure (≥ 1.0.0.0)'.
'Ninject.MVC5 3.2.1.0' already installed.
Adding 'WebActivatorEx 2.0' to WebApplication.
Successfully added 'WebActivatorEx 2.0' to WebApplication.
Adding 'Ninject.Web.Common.WebHost 3.2.0.0' to WebApplication.
Successfully added 'Ninject.Web.Common.WebHost 3.2.0.0' to WebApplication.
Adding 'Ninject.MVC5 3.2.1.0' to WebApplication.
Successfully added 'Ninject.MVC5 3.2.1.0' to WebApplication.

它说已经安装了Ninject.MVC5,但无论如何都要将必要的文件添加到ASP.NET MVC项目中。

现在Package也在Installes Packages下:

enter image description here

这样我就可以继续在我的项目中使用Ninject。虽然,我仍然不明白这里发生了什么。为什么文件不在我的ASP.NET MVC项目中?为什么Visual Studio声明该软件包已安装,但为什么它不在已安装的软件包中?有这个原因还是软件错误?

3 个答案:

答案 0 :(得分:0)

转到package.config并删除&#39; ninject&#39;。之后通过包管理器控制台从NuGet包重新安装ninject。

答案 1 :(得分:0)

尝试安装包Ninject.MVC5或Ninject.MVC3。对于我的情况,它的MVC5。

答案 2 :(得分:0)

Install-Package Ninject -version 3.0.1.10 安装包Ninject.Web.Comon -version 3.0.0.7 安装包Ninject.MV3 -version 3.0.0.6