Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

project.json in ASP.NET 5 and MVC6

When I looked at the tutorials of MVC6, I get confused the usage of project.json. By my understanding this file is used to specify the project dependencies.

Prior to ASP.NET 5, we use nuget to manage the dependencies. But from some limited MVC6 samples I have seen I don't see people mention package.config any more.

Please help me to understand:

  • Do we still use nuget to upgrade all depending components?
  • Or we have to modify the project.json manually?
like image 523
hardywang Avatar asked Jul 02 '15 20:07

hardywang


3 Answers

By my understanding [project.json] is used to specify the project dependencies.

Yes. One of the main functions of project.json is to manage server-side dependencies. (It also specifies other project specific settings.) See the project.json file for more info.

Prior to ASP.NET 5, we use nuget to manage the dependencies.

Yes again. And, ASP.NET 5 still uses NuGet to manage dependencies. The configuration differs though. Instead of using packages.config we use project.json > dependencies to list our project's NuGet packages (and other local dependencies.)

...from some limited MVC6 samples I have seen I don't see people mention package.config any more.

Yes again. Instead of package.config, ASP.NET 5 lists all dependencies, including NuGet packages, within project.json > dependencies. These dependencies can be NuGet packages, local assemblies, or local projects.

To expand on this, in Visual Studio, the References folder is a reflection of our project.json > dependencies section. What we add to the one will appear in the other. See server-side dependency management.

In some ways, you can think of the References folder as a GUI view of project.json > dependencies. For instance, here is a dependencies section from one of my projects alongside the References folder.

  • Note the one-to-one correspondence between what is listed in project.json and in the References folder (ignore the fx/ stuff that isn't in dependencies).
  • Note the the icons beside the items that References lists. These indicate whether the reference is a project, NuGet package (blue), or assembly.

Dependencies correspond to References

Do we still use nuget to upgrade all depending components?

Yes. We just use it differently. If we add a NuGet package to our project.json - either manually or via the GUI's package manager - then we will restore/update those using the NuGet feed.

Or [do] we have to modify the project.json manually?

No. You can modify project.json manually but there are two mains ways to add NuGet packages. Which you use is personal preference.

  1. Edit the project.json file manually.
  2. Use the Visual Studio GUI.
  3. Use the Visual Studio Code GUI.

Importantly, what you do to via the GUI will be reflected in the project.json file, and what you do to project.json > dependencies will be reflected in the GUI.

like image 73
Shaun Luttin Avatar answered Nov 02 '22 21:11

Shaun Luttin


Do we still use nuget to upgrade all depending components?

The short answer is yes.

We have to modify the project.json manually?

You could also do that.

You can really do anything you want:

  • You could use the nuget package manager UI.

  • You could use nuget CLI through the Package Manager Console.

  • Or, you could even add, remove, change dependencies by modifying the project.json which has a really nice auto-complete like in the Package Manager Console.

The only difference now is that there isn't any mention of the installed packages in the project file (previously *.csproj), so yo don't have to add the references manually like when we had the packages.config.

like image 33
Maximo Dominguez Avatar answered Nov 02 '22 20:11

Maximo Dominguez


Do we still use nuget to upgrade all depending components

No, you can just add them by your hand with the versions. Most of the IDEs and code editors has support for nuget dependency auto-complete inside project.json file.

More info on project.json file: https://github.com/aspnet/Home/wiki/Project.json-file (could be a little outdated).

More info on DNX dependencies: http://docs.asp.net/en/latest/dnx/overview.html?highlight=project#dependencies

like image 21
tugberk Avatar answered Nov 02 '22 19:11

tugberk