Exercise - Manage dependency updates in your .NET project
Dependencies that you use in your apps can be updated often and might contain new features, bug fixes, and critical security updates. The app that you created is small, and has only a single dependency. Updating it should be straightforward. To take advantage of the latest features, see if you can update the app.
Upgrade app dependencies
In the DotNetDependencies.csproj file, look at the
dependencies. It should look like this code:<ItemGroup> <PackageReference Include="Humanizer" Version="2.7.9" /> </ItemGroup>To see installed dependencies, run this command:
dotnet list packageThe command should output the requested version and the final resolved (installed) version.
Top-level Package Requested Resolved > Humanizer 2.7.9 2.7.9To see what dependencies are outdated, run this command:
dotnet list package --outdatedThe output should look something like the following output. You might get different values in the
Latestcolumn.Project `DotNetDependencies` has the following updates to its packages [net8.0]: Top-level Package Requested Resolved Latest > Humanizer 2.7.9 2.7.9 2.11.10By default, this command checks for the latest stable version. To check for prerelease packages, append
--include-prereleaseto the previous command:dotnet list package --outdated --include-prereleaseYou can, with some level of confidence, update to the
Latestversion. Doing so ensures the dependencies get the latest features and patches in that major version. To install the latest version, run the following command:dotnet add package HumanizerYou should get output similar to the following example:
info : PackageReference for package 'Humanizer' version '2.11.10' updated in file 'C:\Users\username\Desktop\DotNetDependencies\DotNetDependencies.csproj'.The output states that your project dependencies were updated.
If you want to upgrade to a specific version of the dependency, you can append the
--versionparameter and specify the specific version.dotnet add package Humanizer --version 2.11.10Lastly, you can also install the latest prerelease package by appending the
--prereleaseparameter.dotnet add package Humanizer --prereleaseYour results might be slightly different. The listed version should correspond to the latest available version of the package.
Congratulations. You upgraded the dependency in your app. Well done!