Reputation: 105
how are dependencies managed in C# ? For example in java there is maven (pom.xml), and in JS there is npm (package.json), and in C# there is nuget... but what is the alternative of pom.xml in C# ?
Is that maybe .csproj file ?
Upvotes: 1
Views: 378
Reputation: 142923
As a complement for answer by @sommmen - there is a recent addition to package management in .NET - central package management which allows to centrally manage package versions in C# solutions via Directory.Packages.props
file.
Upvotes: 1
Reputation: 7648
The package manager for .NET C# is nuget,
See: https://learn.microsoft.com/en-us/nuget/what-is-nuget
.NET used to have a package.json file containing the packages for a project, but nowadays the packages are defined right in to the .csproj file. For example:
<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.Hangfire" Version="6.0.2" />
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="6.0.2" />
<PackageReference Include="AspNetCore.HealthChecks.System" Version="6.0.5" />
<PackageReference Include="AspNetCore.HealthChecks.Uris" Version="6.0.3" />
<PackageReference Include="AutoMapper" Version="12.0.0" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.0" />
<PackageReference Include="Hangfire.AspNetCore" Version="1.7.32" />
<PackageReference Include="Hangfire.Console" Version="1.4.2" />
<PackageReference Include="Hangfire.SqlServer" Version="1.7.32" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.11" />
</ItemGroup>
Packages can be managed right in visual studio by the nuget package manager:
Same can be done for the whole solution:
From the command line you can work with nuget.exe, or dotnet.exe;
nuget install Flurl -Version 3.0.6
dotnet add package Flurl --version 3.0.6
There are also the nuget package manager console intergrated into visual studio:
You can select a default project from the dropdown, and then call Install-Package
.
Generally most library repositories on github have either a link to the package on nuget.org or have a snippet to directly install the package via the nuget package manager console.
For example a random library flurl :
Upvotes: 7