名称空间system.web

时间:2018-05-20 00:01:05

标签: c#

我正在使用Visual Studio 2017并收到此错误:

  

名称空间'System.Web'中不存在类型或命名空间名称'Mvc'(您是否缺少程序集引用?)

在这行代码上:

using System.Web.Mvc;

在这行代码中解析SelectListItem需要使用:

public static List<SelectListItem> VerificationMethod

我希望添加一个程序集引用可以轻松解决问题。

这是我试过的......

我尝试通过右键单击项目并选择Add -> Reference来添加程序集引用。 System.Web.Mvc不在添加的引用列表中。

其他一些SO帖子引用了包Microsoft.Aspnet.Mvc来解决此问题。那个包也没有。

我在nuget控制台上尝试了这个:

PM> Install-Package System.Web.mvc
Install-Package : Unable to find package 'System.Web.mvc'
At line:1 char:1
+ Install-Package System.Web.mvc
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand

我也试过这个:

PM> Install-Package Microsoft.aspnet.mvc
Package 'Microsoft.aspnet.mvc.5.2.6' already exists in project 'MySite'
Time Elapsed: 00:00:00.0549251
PM> 

我也试过这个:

update-package -reinstall Microsoft.AspNet.Mvc

得到了这个错误:

  

安装失败。回滚...
  项目'DataAccess'

中不存在包'EntityFramework 6.1.0'

2 个答案:

答案 0 :(得分:2)

以下是我们所做的工作......

删除了解决方案中packages文件夹中的所有文件和文件夹。

冉:

Update-Package -safe -reinstall -IgnoreDependencies
Install-Package Microsoft.AspNet.Mvc -Version 5.2.3.0

答案 1 :(得分:1)

请您尝试以下方法:

在DataAccess项目中&gt;参考文献&gt;右键单击system.web.mvc并删除。

从包管理器控制台将项目更改为DataAccess,请参阅图像

enter image description here

然后输入包管理器控制台:

Install-Package Microsoft.AspNet.Mvc -Version 5.2.3.0

[OP编辑] 这是我在尝试时得到的:

PM> Install-Package Microsoft.AspNet.Mvc -Version 5.2.3.0


Attempting to gather dependency information for package 'Microsoft.AspNet.Mvc.5.2.3' with respect to project 'DataAccess', targeting '.NETFramework,Version=v4.5'
Gathering dependency information took 2.37 sec
Attempting to resolve dependencies for package 'Microsoft.AspNet.Mvc.5.2.3' with DependencyBehavior 'Lowest'
One or more unresolved package dependency constraints detected in the existing packages.config file. All dependency constraints must be resolved to add or update packages. If these packages are being updated this message may be ignored, if not the following error(s) may be blocking the current package operation: 'Microsoft.AspNet.Identity.EntityFramework 2.2.1 constraint: Microsoft.AspNet.Identity.Core (>= 2.2.1)', 'Microsoft.AspNet.Identity.EntityFramework 2.2.1 constraint: EntityFramework (>= 6.1.0)'
Resolving dependency information took 0 ms
Resolving actions to install package 'Microsoft.AspNet.Mvc.5.2.3'
Resolved actions to install package 'Microsoft.AspNet.Mvc.5.2.3'
Found package 'Microsoft.AspNet.Mvc 5.2.3' in 'C:\ThePath\packages'.
Found package 'Microsoft.AspNet.Razor 3.2.3' in 'C:\ThePath\packages'.
Found package 'Microsoft.AspNet.WebPages 3.2.3' in 'C:\ThePath\packages'.
Found package 'Microsoft.Web.Infrastructure 1.0.0' in 'C:\ThePath\packages'.
Package 'Microsoft.AspNet.Razor.3.2.3' already exists in folder 'C:\THePath\packages'
Added package 'Microsoft.AspNet.Razor.3.2.3' to 'packages.config'
Successfully installed 'Microsoft.AspNet.Razor 3.2.3' to DataAccess
Package 'Microsoft.Web.Infrastructure.1.0.0' already exists in folder 'C:ThePath\packages'
Install failed. Rolling back...
Package 'Microsoft.Web.Infrastructure.1.0.0' does not exist in project 'DataAccess'
Removed package 'Microsoft.AspNet.Razor.3.2.3' from 'packages.config'
Executing nuget actions took 389.27 ms
Install-Package : Failed to add reference to 'Microsoft.Web.Infrastructure'.
  Reference unavailable.
At line:1 char:1
+ Install-Package Microsoft.AspNet.Mvc -Version 5.2.3.0
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand