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

后端 未结 14 2548
日久生厌
日久生厌 2020-12-12 23:25

Using C#, Visual Studio 2010.

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

相关标签:
14条回答
  • 2020-12-12 23:39

    I believe you'll find the MVC assembly is referenced in the web.config file, not in the project itself.

    Something like this:

    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </assemblies>
    </compilation>
    

    To respond to your comment;

    The best answer I can give is from here:

    The add element adds an assembly reference to use during compilation of a dynamic resource. ASP.NET automatically links this assembly to the resource when compiling each code module.

    0 讨论(0)
  • 2020-12-12 23:40

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

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

    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.

    0 讨论(0)
  • 2020-12-12 23:42

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

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

    Microsoft.AspNet.Mvc has dependencies on:

    • '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.

    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.

    0 讨论(0)
  • 2020-12-12 23:42

    it can be installed separated, and it's not included in framwork, choose tab list "extensions" and it exists there are and more other libs, all is ok not needed to used old libs etc, exists old 20 30 and 4001

    0 讨论(0)
  • 2020-12-12 23:44

    If you got this problem in Visual Studio 2017, chances are you're working with an MVC 4 project created in a previous version of VS with a reference hint path pointing to C:\Program Files (x86)\Microsoft ASP.NET. Visual Studio 2017 does not install this directory anymore.

    We usually solve this by installing a copy of Visual Studio 2015 alongside our 2017 instance, and that installs the necessary libraries in the above path. Then we update all the references in the affected projects and we're good to go.

    0 讨论(0)
  • 2020-12-12 23:52

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

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

    0 讨论(0)
提交回复
热议问题