Using the dotnet add
command of the .NET Core CLI
You can do this using the .NET Core CLI with the command dotnet add
, the package
option, and the package name shortly thereafter.
For example, to add the latest version of the Entity Framework.
MeuProjeto> dotnet add package EntityFramework
To specify a version, you can use the --version
argument.
MeuProjeto> dotnet add package EntityFramework --version=6.0
To specify the project where dependency is to be added, you must use the project's csproj file path shortly after add
.
For example, to add the Entity Framework to the project ProjetoModels
MeuProjeto> dotnet add ProjetoModels.csproj package EntityFramework
This will check if the package version is compatible with the project and, if it is compatible, will add the dependency in the project files and also download it using the dotnet restore
/ p>
Tip : To open a terminal within the VS Code, in the project folder use the key combination Ctrl + strong> '
Add the dependency manually in XML
You can also manually add the reference to the project file. To do this, just open the .csproj file, search for the ItemGroup
section and add a PackageReference
For example, to add the Entity Framework version 6.2.0 .
<ItemGroup>
<PackageReference Include="EntityFramework" Version="6.2.0" />
</ItemGroup>
After that, you have to run the dotnet restore
command to get the files downloaded.