.net 为什么 System.Web.Mvc 没有在 Add References 中列出?

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

Why is System.Web.Mvc not listed in Add References?

.netvisual-studioassembly-references

提问by Timwi

Using C#, Visual Studio 2010.

使用 C#,Visual Studio 2010。

There is a namespace called System.Web.Mvcdocumented on MSDN. The documentation for all the types in that namespace says that they are in System.Web.Mvc.dll.

MSDN 上记录了一个名为System.Web.Mvc的命名空间。该命名空间中所有类型的文档都说它们在System.Web.Mvc.dll.

However, when I go to Add Reference, “.NET” tab, this assembly is missing from the list. Why?

但是,当我转到“添加引用”的“.NET”选项卡时,列表中缺少此程序集。为什么?

采纳答案by Timwi

The desired assembly has appeared in the list now.

所需的程序集现已出现在列表中。

I can only speculate what caused it to appear, but I suspect it is the fact that I went FileNewProjectASP.NET Web Application, which I had never done before. It is possible that this caused some sort of late initialisation to happen and the list to be populated with additional assemblies for Web development.

我只能推测导致它出现的原因,但我怀疑这是我转到FileNewProjectASP.NET Web Application的事实,这是我以前从未做过的。这可能会导致某些类型的延迟初始化发生,并且列表会被用于 Web 开发的附加程序集填充。

回答by jahu

In VS Express 2012 I couldn't find System.Web.Mvc in the "assemblies" tab, but after a bit of searching I found out that I need to look into "assemblies\extensions" tab rather than the default "assemblies\framework" tab.

在 VS Express 2012 中,我在“assemblies”选项卡中找不到 System.Web.Mvc,但经过一番搜索后我发现我需要查看“ assembly\extensions”选项卡而不是默认的“assemblies\framework” “ 标签。

回答by sandeep talabathula

Best way is to use NuGet package manager.

最好的方法是使用 NuGet 包管理器。

Just update the below MVC package and it should work.

只需更新下面的 MVC 包,它应该可以工作。

enter image description here

在此处输入图片说明

回答by sandeep talabathula

I had the same issue and wasn't able to locate the System.Web.MVC reference assembly.

我遇到了同样的问题,无法找到 System.Web.MVC 参考程序集。

Finally found out and it was located inside the following location.

终于找到了,它位于以下位置。

Note if your VS was installed in C: (Sometimes the MVC.dll is not in the default location which everybody talk about, i mean the "Reference Assemblies" folder located in the C: drive.)

请注意,如果您的 VS 安装在 C: 中:(有时 MVC.dll 不在每个人都谈论的默认位置,我的意思是位于 C: 驱动器中的“参考程序集”文件夹。)

if its not there, it should definitely be in here:

如果它不在那里,它肯定应该在这里:

\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 2\Assemblies\System.Web.Mvc.dll

\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 2\Assemblies\System.Web.Mvc.dll

So add the dll through navigating or the browse tab in the add reference menu.

所以通过导航或添加引用菜单中的浏览选项卡添加dll。

回答by fordareh

You can also add this from the Nuget Package Manager Console, something like:

您还可以从 Nuget 包管理器控制台添加它,例如:

Install-Package Microsoft.AspNet.Mvc -Version 4.0.20710.0 -ProjectName XXXXX

Microsoft.AspNet.Mvc has dependencies on:

Microsoft.AspNet.Mvc 依赖于:

  • 'Microsoft.AspNet.WebPages (≥ 2.0.20710.0 && < 2.1)'
  • 'Microsoft.Web.Infrastructure (≥ 1.0.0.0)'
  • 'Microsoft.AspNet.Razor (≥ 2.0.20710.0 && < 2.1)'
  • 'Microsoft.AspNet.WebPages (≥ 2.0.20710.0 && < 2.1)'
  • 'Microsoft.Web.Infrastructure (≥ 1.0.0.0)'
  • 'Microsoft.AspNet.Razor (≥ 2.0.20710.0 && < 2.1)'

...which seems like no biggie to me. In our case, this is a class library that exists solely to provide support for our Mvc apps. So, we figure it's a benign dependency at worst.

...这对我来说似乎没什么大不了的。在我们的例子中,这是一个类库,仅用于为我们的 Mvc 应用程序提供支持。所以,我们认为它在最坏的情况下是一种良性依赖。

I definitely prefer this to pointing to an assembly on the file system or in the GAC, since updating the package in the future will likely be a lot less painful than experiences I've had with the GAC and file system assembly references in the past.

我绝对更喜欢指向文件系统或 GAC 中的程序集,因为将来更新包可能比我过去使用 GAC 和文件系统程序集引用的经历要少得多。

回答by Alican

I have had the same problem and here is the funny reason: My guess is that you expect System.Web.Mvcto be located under System.Webin the list. But the list is not alphabetical.

我遇到了同样的问题,这是一个有趣的原因:我的猜测是您希望System.Web.Mvc位于System.Web列表中。但该列表不是按字母顺序排列的。

First sort the list and then look near the System.Web.

首先对列表进行排序,然后在System.Web.

回答by Iman

Check these step:

检查这些步骤:

  1. Check MVC is installed properly.
  2. Check the project's property and see what is the project Target Framework. If the target framework is not set to .Net Framework 4, set it.
  1. 检查 MVC 安装是否正确。
  2. 检查项目的属性,看看项目目标框架是什么。如果目标框架未设置为 .Net Framework 4,请设置它。

Note: if target framework is set to .Net Framework 4 Client Profile, it will not list MVC reference on references list. You can find different between .Net Framework 4 and .Net Framework 4 Client Profile here.

注意:如果目标框架设置为 .Net Framework 4 Client Profile,则不会在参考列表中列出 MVC 参考。您可以在此处找到 .Net Framework 4 和 .Net Framework 4 Client Profile 之间的不同之处。

The .NET Framework 4 Client Profile is a subset of the .NET Framework 4 that is optimized for client applications. It provides functionality for most client applications, including Windows Presentation Foundation (WPF), Windows Forms, Windows Communication Foundation (WCF), and ClickOnce features. This enables faster deployment and a smaller install package for applications that target the .NET Framework 4 Client Profile.

.NET Framework 4 Client Profile 是 .NET Framework 4 的一个子集,它针对客户端应用程序进行了优化。它为大多数客户端应用程序提供功能,包括 Windows Presentation Foundation (WPF)、Windows Forms、Windows Communication Foundation (WCF) 和 ClickOnce 功能。这为面向 .NET Framework 4 Client Profile 的应用程序提供了更快的部署和更小的安装包。

回答by eglasius

"OK, adding that XML to the Web.config works, but it doesn't answer the question"

“好的,将 XML 添加到 Web.config 可以工作,但它没有回答问题”

It should be there. By default the add references list seems to be ordered, but its not the case. Hit the name header and look again.

它应该在那里。默认情况下,添加引用列表似乎是有序的,但事实并非如此。点击名称标题并再次查看。

回答by zety

I solved this problem by searching "mvc". The System.Web.Mvc appeared in search results, despite it is not contained in the list.

我通过搜索“mvc”解决了这个问题。System.Web.Mvc 出现在搜索结果中,尽管它未包含在列表中。

回答by Prof Von Lemongargle

This has changed for Visual Studio 2012 (I know the original question says VS2010, but the title will still hit on searches).

这在 Visual Studio 2012 中发生了变化(我知道最初的问题是 VS2010,但标题仍然会出现在搜索中)。

When you create a VS2012 MVC project, the system.web.mvc is placed in the packages folder which is peer to the solution. This will be referenced in the web project by default and you can find the exact path there).

当您创建 VS2012 MVC 项目时,system.web.mvc 被放置在与解决方案对等的包文件夹中。默认情况下,这将在 web 项目中引用,您可以在那里找到确切的路径)。

If you want to reference this in a secondary project (say a supporting .dll with filters or other attributes), then you can reference it from there.

如果您想在辅助项目中引用它(比如带有过滤器或其他属性的支持 .dll),那么您可以从那里引用它。