16
votes

What is the purpose of *deps.json file in .NET Core? What is the reason to store references in such file and not in assembly manifest(as in standalone .NET Framework)?

Using Ildasm i checked that assembly manifest doesn't contain entries for these dependecies after dotnet build command.

But it has entries after dotnet publish command.

1
Yeah, you don't want to look too close, scary stuff that hopefully it is not going to last much longer. This used to live in project.json but isn't really gone yet. It is a side-effect of the way they tackled .NETCore v1, they broke up the framework assemblies in lots and lots of tiny ones. On the theory that it would be easier to port them to MacOS and the many Linux flavors and make changes while working on it. Plan is to go back to large ones, not sure when it is going to be executed.Hans Passant
@Hans_Passant Are there any differences with v3 of .NetCore, or does it still need these `.deps.json' files?intrepidis

1 Answers

15
votes

The .deps.json file contains metadata about the assemblies referenced by the built assembly and the locations to search for them as well as information about the compilation options used.

This information is read by the native component (corehost) that loads and configures the runtime. When a referenced assembly needs to be loaded, the host will use the information in this file (as well as any runtimeconfig.json/runtimeconfig.dev.json) to locate the correct assembly to load.

This information is used in other places as well. For example ASP.NET Core's Razor view compilation also uses it to pass the correct references and configuration to the generated code. And unit test hosts also need to use the information in this file when a unit test library is loaded into the test host. The managed API to read and write this file is available in the Microsoft.Extensions.DependencyModel NuGet package.