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
+33-1Lines changed: 33 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -115,7 +115,39 @@ Alternatively, if you want to keep low and moderate vulnerabilities as warnings,
115
115
> [!NOTE]
116
116
> MSBuild properties for message severity such as `NoWarn` and `TreatWarningsAsErrors` are not supported for packages.config projects.
117
117
118
-
## Ensure restore audited projects
118
+
## Running NuGet Audit in CI
119
+
120
+
### Separating Errors from Warnings with a Dedicated Auditing Pipeline
121
+
122
+
You can use MSBuild's conditional statements to configure a dedicated CI pipeline for running audits, without audit warnings being treated as errors in other pipelines or on local builds.
123
+
Depending on your CI system and team processes, you can have failed runs of the audit pipeline email the team, or you may have a dashboard where you can show a badge of the most recent run of the pipeline.
124
+
125
+
Like many things in programming, there are multiple ways to achieve the outcome.
126
+
One option is to treat NuGet Audit warnings as errors only in an audit pipeline.
Then in your pipeline, you run restore specifying the property used by the condition.
137
+
For example, using GitHub Actions syntax:
138
+
139
+
```yml
140
+
- name: Restore with NuGet Auditing
141
+
run: dotnet restore -p:AuditPipeline=true
142
+
```
143
+
144
+
The property name `AuditPipeline` is only an example, and you can customize it as you wish, as long as the name is the same in both the MSBuild condition and the command line.
145
+
MSBuild also uses environment variables when reading a property that has not yet been defined, so an environment variable is an alternative to the command line parameter.
146
+
147
+
By using conditions to selectively cause NuGet Audit warnings to fail a restore, you can have a dedicated pipeline to check packages for known vulnerabilities, while preventing new security advisories from blocking your bug fixes at inconvenient times.
148
+
Keeping NuGet Audit warnings enabled for local builds allows developers to get a non-blocking notification about new security advisories and can encourage upgrading package versions to fix the vulnerabilities more quickly than waiting for someone to check the audit pipeline status.
149
+
150
+
### Ensure restore audited projects
119
151
120
152
NuGet in MSBuild 17.13 and .NET 9.0.200 added output properties `RestoreProjectCount`, `RestoreSkippedCount` and `RestoreProjectsAuditedCount` on the restore task.
121
153
This can be used to enforce that audit ran during a restore.
0 commit comments