Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Mvc不存在于命名空间system.web中_C# - Fatal编程技术网

C# Mvc不存在于命名空间system.web中

C# Mvc不存在于命名空间system.web中,c#,C#,我正在使用Visual Studio 2017,出现以下错误: 命名空间“System.Web”中不存在类型或命名空间名称“Mvc”(是否缺少程序集引用?) 在这一行代码中: using System.Web.Mvc; public static List<SelectListItem> VerificationMethod 解析此代码行上的SelectListItem时需要使用该选项: using System.Web.Mvc; public static List<S

我正在使用Visual Studio 2017,出现以下错误:

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

在这一行代码中:

using System.Web.Mvc;
public static List<SelectListItem> VerificationMethod
解析此代码行上的
SelectListItem
时需要使用该选项:

using System.Web.Mvc;
public static List<SelectListItem> VerificationMethod
我也试过:

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
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
我也试过:

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
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
得到了这个错误:

安装失败。正在回滚…
项目“DataAccess”中不存在包“EntityFramework 6.1.0”


请您尝试以下方法:

在DataAccess项目>参考>中右键单击system.web.mvc并删除

从PackageManager控制台将项目更改为DataAccess,请参见图

然后在package manager控制台中键入:

Install-Package Microsoft.AspNet.Mvc -Version 5.2.3.0
[按OP编辑] 这就是我尝试这个的时候得到的:

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
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

这就是我们所做的工作

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

跑步:


您是否可以尝试使用
更新包重新安装Microsoft.AspNet.Mvc
?您的项目目标是.NET 4.x还是.NET Core?这是什么类型的项目,ASP.NET还是ASP.NET Core?(这是一个稍微独立的问题,因为ASP.NET核心仍然可以针对桌面框架。)