The Include attribute specifies the ID of the package to add to the project. The Version attribute specifies the version to get. Versions are specified as per NuGet version rules.
Use conditions to add a dependency that's available only in a specific target, as shown in the following example:
The dependency in the preceding example will only be valid if the build is happening for that given target. The $(TargetFramework) in the condition is an MSBuild property that's being set in the project. For most common .NET applications, you don't need to do this.
Add and remove dependencies
You can add and remove dependencies by editing your project file or through .NET CLI commands.
Edit the project file
To add a dependency, add a <PackageReference> item inside an <ItemGroup> element. You can add to an existing <ItemGroup> or create a new one.
Don't include inputs to the restore operation in the .targets or .props file of a referenced package. These inputs can include PackageReference items, ExcludeAssets attributes, the NuGet feeds to use, or other NuGet configuration. The .targets and .props files from packages aren't used until after NuGet restore is complete. Anything needed for restore needs to be in the project file or .targets file of the project itself, not a package dependency.
If you want to use ASP.NET APIs in a console application or class library, add a FrameworkReference item to your project file:
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Create a .NET project and learn to add packages and manage package dependencies in your project. Use the .NET Core CLI and NuGet registry to add libraries and tools to your C# applications through Visual Studio Code.