Water Cooler v2
Water Cooler v2

Reputation: 33880

Where do I reference System.Web.Mvc.dll from?

In one of my class libraries, I wish to only make a single call to System.Web.Mvc.Server.MapPath(string path).

If I install the NuGet package Microsoft.AspNet.Mvc into that class library, I have to first install the Microsoft.AspNet.WebPages package as well, which may have further dependencies.

I just want the single DLL System.Web.Mvc.dll since the Server class is in there.

I tried referencing the DLL from the path:

C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Stack 5\Packages\Microsoft.AspNet.Mvc.5.2.3\lib\net45

but that DLL does not have the Server class in the System.Web.Mvc namespace.

And I do not see this DLL anywhere else on my machine.

Where can I reference this DLL from? It used to be so easy in the old days. And it stayed easy if you wanted to reference just MVC till 2010.

Upvotes: 1

Views: 3911

Answers (2)

NightOwl888
NightOwl888

Reputation: 56909

If I install the NuGet package Microsoft.AspNet.Mvc into that class library, I have to first install the Microsoft.AspNet.WebPages package as well, which may have further dependencies.

Yes, and that hasn't changed since 2010. But NuGet made it much easier by installing both the files to reference and adding the references to those files in your project and adding any dependent NuGet packages in one easy step.

Where can I reference this DLL from?

The files that are installed by NuGet are physically located under your root directory (the same place where your solution file is) in a directory named \packages.

But NuGet automatically adds the references to the files for you when you install the NuGet package, so there is no need to mess with them unless something goes wrong.

For example, to install Microsoft.AspNet.Mvc, you simply need to run the following command in the Package Manager Console.

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

Which will install version 5.2.3 of MVC along with all of its dependencies and reference those DLLs from your .csproj file as well.

Further reading: Using NuGet Part 1: NuGet Basics

Upvotes: 0

Esko
Esko

Reputation: 4207

There is no need to have System.Web.Mvc-assembly in your project to use Server.Mappath. All you need is reference to System.Web in your project and you can do

var path = System.Web.HttpContext.Current.Server.MapPath("default.aspx");

Upvotes: 1

Related Questions