【问题标题】:Mvc does not exist in the namespace system.web命名空间 system.web 中不存在 Mvc
【发布时间】:2018-10-30 00:41:51
【问题描述】:

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

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

在这行代码上:

using System.Web.Mvc;

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

public static List<SelectListItem> VerificationMethod

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

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

我尝试通过右键单击项目并选择Add -&gt; 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”

【问题讨论】:

  • 您可以尝试使用update-package -reinstall Microsoft.AspNet.Mvc 重新安装吗?
  • 您的项目是针对 .NET 4.x 还是 .NET Core?
  • 这是一个什么样的项目,ASP.NET 还是 ASP.NET Core? (这是一个稍微不同的问题,因为 ASP.NET Core 仍然可以针对桌面框架。)

标签: c#


【解决方案1】:

这就是我们所做的工作......

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

跑:

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

【讨论】:

    【解决方案2】:

    请您尝试以下方法:

    在 DataAccess Project> References > 右键单击​​ system.web.mvc 并删除。

    从包管理器控制台将项目更改为 DataAccess,查看图片

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

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-05
      • 1970-01-01
      • 2013-03-14
      • 1970-01-01
      • 2018-06-25
      • 1970-01-01
      相关资源
      最近更新 更多