You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/concepts/Auditing-Packages.md
+29
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,7 @@ description: How to audit package dependencies for security vulnerabilities and
4
4
author: JonDouglas
5
5
ms.author: jodou
6
6
ms.topic: conceptual
7
+
ms.date: 02/11/2025
7
8
---
8
9
9
10
# Auditing package dependencies for security vulnerabilities
@@ -105,6 +106,34 @@ Alternatively, if you want to keep low and moderate vulnerabilities as warnings,
105
106
> [!NOTE]
106
107
> MSBuild properties for message severity such as `NoWarn` and `TreatWarningsAsErrors` are not supported for packages.config projects.
107
108
109
+
## Ensure restore audited projects
110
+
111
+
NuGet in MSBuild 17.13 and .NET 9.0.200 added output properties `RestoreProjectCount`, `RestoreSkippedCount` and `RestoreProjectsAuditedCount` on the restore task.
112
+
This can be used to enforce that audit ran during a restore.
113
+
Note that these output properties are not available with [static graph restore](../reference/msbuild-targets.md#restoring-with-msbuild-static-graph-evaluation).
114
+
115
+
Since MSBuild is a scripting language, this can be achieved a number of different ways, but also has the same restrictions as MSBuild has.
116
+
One example is to create a file *Directory.Solution.targets* in the same directory as your solution file, whose contents has a target similar to the following.
117
+
Note that *Directory.Build.props* is commonly used, but is imported by projects.
118
+
However, NuGet's restore target and task runs at the solution level, so needs to be in MSBuild's solution extensibility file, not the project/build file.
Text=""Restore did not audit every project in the solution. Expected: $(RestoreProjectCount) Found: $(RestoreProjectsAuditedCount)"" />
128
+
</Target>
129
+
</Project>
130
+
```
131
+
132
+
Depending on your use-case, you may wish to use condition `'$(RestoreProjectCount)' != '$([MSBuild::Add($(RestoreProjectsAuditedCount), $(RestoreSkippedCount))'` on the error message, to account for projects that restore skipped because they were already up to date.
133
+
Similarly, think about if you want this error to happen everywhere, or only in CI pipelines, and what environment variables are defined in your CI environment, and factor this into the target's condition.
134
+
Again, since MSBuild is a scripting language, you can use any of its capabilities to customize your repo however you want.
135
+
Viewing [MSBuild's metaproj](/visualstudio/msbuild/how-to-build-specific-targets-in-solutions-by-using-msbuild-exe#troubleshooting) and [binlogs](/visualstudio/msbuild/msbuild-command-line-reference#switches-for-loggers) are useful to develop and troubleshoot solution level targets.
136
+
108
137
## `dotnet list package --vulnerable`
109
138
110
139
Once a project is successfully restored, [`dotnet list package`](/dotnet/core/tools/dotnet-list-package) has a `--vulnerable` argument to filter the packages based on which packages have known vulnerabilities.
0 commit comments