using NuGet.ProjectManagement; NuGetPackageManager _packageManager = new NuGetPackageManager(new PackageSourceProvider(), new Settings()); var project = new MSBuildProjectSystem(_projectFilePath, _msbuildDirectoryPath); if (project != null) { _packageManager.PackagesInstalled += (s, e) => Console.WriteLine("Package installed: {0}", e.PackageIdentity); await _packageManager.ClearDirectInstallAsync(project, CancellationToken.None); // clears any direct installs }In this example, we are using the ClearDirectInstall method to clear any direct installs from the project which we created using the MSBuildProjectSystem. We are also subscribing to the PackagesInstalled event to print the package name whenever a package is installed. This example can be found in the NuGet official documentation: https://docs.microsoft.com/en-us/nuget/reference/api-reference/nuspec/nuspec-reference#packaging-tools The package library being used in this example is the NuGet.ProjectManagement library.