OSDotNet.005 teaches .NET developers to control external software dependencies rather than simply downloading packages and hoping a build remains stable. A NuGet package can depend on more packages, creating a dependency graph that affects reliability, licensing, and security. Building on OSDotNet.004 on SDK-style projects and MSBuild, the lesson covers PackageReference, central package versions, lock files, and vulnerability auditing with a small reproducible console application.
What direct and transitive dependencies mean
A direct dependency appears explicitly in a project’s PackageReference list. A transitive dependency arrives because one of the selected packages requires another. A single direct reference can introduce many transitive packages. NuGet evaluates compatible package versions and records the resolved graph in obj/project.assets.json, as described by Microsoft’s PackageReference documentation. Downloaded packages are normally cached outside the project in the user’s global NuGet package directory.
A project file defines what software it needs, while a restore resolves the complete set. Readers unfamiliar with the command-line toolchain can review OSC#.001 on installing and using the .NET SDK, then return to the dependency exercise.
Create a small practice project
Use a supported .NET SDK and a disposable folder. The example targets net10.0 and deliberately uses the genuine Newtonsoft.Json 13.0.4 package from NuGet.org. The chosen version is a documented example, not a recommendation to freeze every application on the same release. Evaluate current supported versions and advisories before production deployment.
dotnet new console --framework net10.0 -n PackageLab
cd PackageLab
Create a file named Directory.Packages.props alongside the generated project file. Central Package Management places versions in one repository-level location, letting multiple projects reference a common package without repeating the version in every .csproj. NuGet uses the closest applicable Directory.Packages.props file in the directory hierarchy by default.
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Newtonsoft.Json" Version="13.0.4" />
</ItemGroup>
</Project>
Replace the generated PackageLab.csproj contents with the following lab configuration. The package reference has no Version attribute; the central file supplies the declared version. The lock-file setting asks restore to record the resulting dependency closure. Microsoft’s Central Package Management reference explains the arrangement. A package version directly on the reference can trigger NuGet error NU1008 when central management is enabled.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" />
</ItemGroup>
</Project>
Lock the resolved dependency graph
Run dotnet restore. A successful restore creates packages.lock.json, which records the full resolved package graph, including dependency versions and content hashes. Commit the lock file for an executable application when reproducibility matters. In CI, dotnet restore --locked-mode rejects dependency changes that would require changing the committed lock file. Central Package Management aligns declared package versions across projects; a lock file constrains what a particular restore may resolve. The two features solve different problems.
dotnet restore
dotnet restore --locked-mode
dotnet package list --include-transitive
dotnet package list --include-transitive --vulnerable
The official lock-file documentation advises committing application lock files but cautions that a library’s lock file does not govern the final dependency closure of an application consuming that library. If a package version changes intentionally, regenerate and review the lock-file diff before returning to locked mode.
Check package health and trace dependencies
With a recent .NET SDK, dotnet package list --include-transitive --vulnerable reports known vulnerable packages from configured advisory sources. The command does not establish that a package is harmless, since new advisories may emerge after an audit. When an unexpected package appears, dotnet nuget why Newtonsoft.Json can reveal the dependency path. Microsoft documents the commands in its package list reference and dependency explanation reference. Avoid blindly upgrading production dependencies without compatibility tests.
A minimal runtime check
Replace Program.cs with a short JSON serialization test. The program imports its dependency and formats a small object, allowing an engineer to confirm that restore, compilation, and runtime assembly loading all succeed together.
using Newtonsoft.Json;
var record = new { lesson = "OSDotNet.005", packages = 1 };
Console.WriteLine(JsonConvert.SerializeObject(record));
dotnet run
Expected output, not a locally verified execution: {"lesson":"OSDotNet.005","packages":1}. Repeat the practice with a deliberately changed central version in a separate development branch and observe how locked restore behaves. Do not test changes against production build infrastructure without an approved maintenance window.
Where dependency security can fail
Checking packages involves more than a version string. Validate author reputation, repository activity, licensing, package source and advisories before adoption. NuGet’s auditing guidance explains vulnerability signals, while package source mapping can restrict which feeds supply package identifiers. An audit warning deserves investigation, but indiscriminately suppressing warnings defeats the purpose. Changes to dependencies also deserve regression tests and a rollback path.
Dependencies ultimately affect compiled applications and the runtime environment. OSDotNet.003 on assemblies and CIL explains their compiled representation, while OSDotNet.002 on the CLR explains managed execution. A secure process requires all three layers: controlled source dependencies, verified build outputs, and supported runtime environments.
Takeaway: Central package versions simplify maintenance, dependency lock files make application restores more predictable, and vulnerability audits reveal known package risks. Keep the package graph reviewable, update deliberately, and test the finished application rather than treating any single command as proof of security.
Editor’s Note: The lesson follows the verified OSDotNet.004 curriculum and uses Microsoft Learn, NuGet.org and official .NET educational videos as technical references. The central package example was statically reviewed and both XML samples parsed successfully, but the local authoring environment lacks the .NET SDK, so restore, compilation and execution were not performed. Expected output is a prediction. Video identities were confirmed from public listings; iframe playback and mobile rendering remain unverified. The original featured cover is a 1200 × 630 fine-art oil painting with the BitcoinVersus.tech wordmark.

BitcoinVersus.Tech is volunteer-run and publishes independent technical education. An optional 5,000-satoshi donation supports research. Scan the original QR with a compatible Bitcoin wallet, or use a wallet capable of importing a saved QR image. Independently verify recipient 3C9o19EH5HSiwEPyCTmEKzxhNCbo2X6TTb and the amount before sending. Bitcoin transfers are generally irreversible.
We volunteer daily to ensure the credibility of information on BitcoinVersus.Tech is Verifiably True. The lesson is educational and informational, not authorization to modify production systems, a security certification, financial advice or investment advice.

Leave a Reply