Using the command dotnet add
of the . NET Core CLI
You can do this using the . NET Core CLI command dotnet add
, the option package
and the package name right after.
For example, to add the latest version of the Entity Framework.
$ dotnet add package EntityFramework
To specify a version, it is possible to use the argument --version
.
$ dotnet add package EntityFramework --version=6.0
To specify the project where the dependency should be added you need to use the file path csproj of the project shortly after the add
.
For example, to add the Entity Framework to the project ProjetoModels
$ dotnet add ProjetoModels.csproj package EntityFramework
This will check whether the version of the package is compatible with the project and, if compatible, will add the dependency on the project files and also download it using the command dotnet restore
.
Tip: to open a terminal inside VS Code, in the project folder use the key combination Ctrl+'
Manually add dependency to XML
It is also possible to add the reference manually in the project file. For this just open the file the .csproj, search for the section ItemGroup
and add an item PackageReference
.
For example, to add the Entity Framework version 6.2.0.
<ItemGroup>
<PackageReference Include="EntityFramework" Version="6.2.0" />
</ItemGroup>
After that, you need to run the command dotnet restore
for the files to be downloaded.
I liked the option, I didn’t know it.
– Jéf Bueno