Adding references and nuget packages to projects is a common thing in development. I have already written a blog on how to add/reomve nuget packages in vs code.
How to - Add reference to another project
Let’s see how to add and remove project references using command line in Visual Studio Code. The command is :
1
dotnet add [PROJECT] reference [-f|--framework] <PROJECT_REFERENCES> [-h|--help]
For example :
1
dotnet add reference ..\ReferenceCheckLibrary\ReferenceCheckLibrary.csproj
Now the csproj file of the project would look like this :
1
2
3
4
5
6
7
8
9
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\ReferenceCheckLibrary\ReferenceCheckLibrary.csproj" />
</ItemGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
</Project>
How to - Remove existing reference from a project
The command is :
1
dotnet remove [PROJECT] reference [-f|--framework] <PROJECT_REFERENCES> [-h|--help]
For example :
1
dotnet remove reference ..\ReferenceCheckLibrary\ReferenceCheckLibrary.csproj
This would reflect in the csproj file of the project. It would look like :
1
2
3
4
5
6
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
</Project>
How to - List all the existing reference of a project
The command is :
1
dotnet list [<PROJECT>] reference [-h|--help]
For example :
1
dotnet list reference
This command would output :
1
2
3
Project reference(s)
--------------------
..\ReferenceCheckLibrary\ReferenceCheckLibrary.csproj
References : Microsoft Docs