Skip to content

Commit bf048eb

Browse files
authored
Vulnerability InfoBar now has "How to fix with GitHub Copilot" link to NuGet's MCP Server docs (#6959)
1 parent 7838443 commit bf048eb

20 files changed

Lines changed: 190 additions & 5 deletions

src/NuGet.Clients/NuGet.PackageManagement.VisualStudio/Telemetry/HyperlinkType.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public enum HyperlinkType
1414
DeprecationAlternativeDetails,
1515
DeprecationAlternativePackageItem,
1616
VulnerabilityAdvisory,
17+
VulnerabilityAdvisoryGHCopilotDocs,
1718
OptionsBlocked,
1819
OwnerProfile,
1920
OwnerProfileDetailsPane

src/NuGet.Clients/NuGet.PackageManagement.VisualStudio/Telemetry/NavigatedTelemetryEvent.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,28 @@ public static NavigatedTelemetryEvent CreateWithPMUIConfigurePackageSourceMappin
7272
return navigatedTelemetryEvent;
7373
}
7474

75+
/// <summary>
76+
/// Navigating from the Vulnerability InfoBar to the Manage Packages dialog.
77+
/// </summary>
78+
public static NavigatedTelemetryEvent CreateWithVulnerabilityInfoBarManagePackages()
79+
{
80+
NavigatedTelemetryEvent navigatedTelemetryEvent = new(NavigationType.Button, NavigationOrigin.VulnerabilityInfoBar_ManagePackages);
81+
return navigatedTelemetryEvent;
82+
}
83+
84+
/// <summary>
85+
/// Navigating an External hyperlink from VS.
86+
/// </summary>
87+
/// <param name="hyperlinkType">Hyperlink origin</param>
88+
public static NavigatedTelemetryEvent CreateWithExternalLink(HyperlinkType hyperlinkType)
89+
{
90+
NavigatedTelemetryEvent navigatedTelemetryEvent = new(NavigationType.Hyperlink, NavigationOrigin.PMUI_ExternalLink);
91+
92+
navigatedTelemetryEvent[HyperLinkTypePropertyName] = hyperlinkType;
93+
94+
return navigatedTelemetryEvent;
95+
}
96+
7597
/// <summary>
7698
/// Navigating an External hyperlink from the PM UI.
7799
/// </summary>

src/NuGet.Clients/NuGet.PackageManagement.VisualStudio/Telemetry/NavigationOrigin.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public enum NavigationOrigin
1111
Options_PackageSourceMapping_RemoveAll,
1212
Options_LocalsCommand_ClearAll,
1313
PMUI_ExternalLink,
14-
PMUI_PackageSourceMapping_Configure
14+
PMUI_PackageSourceMapping_Configure,
15+
VulnerabilityInfoBar_ManagePackages
1516
}
1617
}

src/NuGet.Clients/NuGet.SolutionRestoreManager/Resources.Designer.cs

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/NuGet.Clients/NuGet.SolutionRestoreManager/Resources.resx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,7 @@ To prevent NuGet from restoring packages during build, open the Visual Studio Op
197197
<value>'{0}' items do not have the same value(s) across all target frameworks. Remove any condition from MSBuild files for '{0}' items.</value>
198198
<comment>{0} - MSBuild item type. For example, NuGetAuditSuppress</comment>
199199
</data>
200-
</root>
200+
<data name="InfoBar_HyperlinkGHCopilotDocs" xml:space="preserve">
201+
<value>How to fix with GitHub Copilot</value>
202+
</data>
203+
</root>

src/NuGet.Clients/NuGet.SolutionRestoreManager/VulnerablePackagesInfoBar.cs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
using Microsoft.VisualStudio.Imaging;
1212
using Microsoft.VisualStudio.Shell;
1313
using Microsoft.VisualStudio.Shell.Interop;
14+
using NuGet.Common;
1415
using NuGet.PackageManagement;
16+
using NuGet.PackageManagement.Telemetry;
1517
using NuGet.VisualStudio;
1618
using NuGet.VisualStudio.Telemetry;
1719

@@ -21,19 +23,25 @@ namespace NuGet.SolutionRestoreManager
2123
[PartCreationPolicy(CreationPolicy.Shared)]
2224
public class VulnerablePackagesInfoBar : IVulnerabilitiesNotificationService, IVsInfoBarUIEvents
2325
{
26+
private const string LogEntrySource = "NuGet Package Manager";
27+
2428
private IAsyncServiceProvider _asyncServiceProvider = AsyncServiceProvider.GlobalProvider;
2529
internal IVsInfoBarUIElement? _infoBarUIElement;
2630
internal bool _infoBarVisible = false; // InfoBar is currently being displayed in the Solution Explorer
2731
internal bool _wasInfoBarClosed = false; // InfoBar was closed by the user, using the 'x'(close) in the InfoBar
2832
internal bool _wasInfoBarHidden = false; // InfoBar was hid, this is caused because there are no more vulnerabilities to address
2933
private uint? _eventCookie; // To hold the connection cookie
34+
private InfoBarHyperlink _hyperlinkPmui;
35+
private InfoBarHyperlink _hyperlinkGHCopilotDocs;
3036

3137
private Lazy<IPackageManagerLaunchService>? PackageManagerLaunchService { get; }
3238
private ISolutionManager? SolutionManager { get; }
3339

3440
[ImportingConstructor]
3541
public VulnerablePackagesInfoBar(ISolutionManager solutionManager, Lazy<IPackageManagerLaunchService> packageManagerLaunchService)
3642
{
43+
_hyperlinkPmui = new InfoBarHyperlink(Resources.InfoBar_HyperlinkMessage);
44+
_hyperlinkGHCopilotDocs = new InfoBarHyperlink(Resources.InfoBar_HyperlinkGHCopilotDocs, "https://aka.ms/nugetmcp/auditFix");
3745
SolutionManager = solutionManager;
3846
PackageManagerLaunchService = packageManagerLaunchService;
3947
SolutionManager.SolutionClosed += OnSolutionClosed;
@@ -155,15 +163,43 @@ public void OnClosed(IVsInfoBarUIElement infoBarUIElement)
155163
public void OnActionItemClicked(IVsInfoBarUIElement infoBarUIElement, IVsInfoBarActionItem actionItem)
156164
{
157165
ThreadHelper.ThrowIfNotOnUIThread();
158-
PackageManagerLaunchService?.Value.LaunchSolutionPackageManager();
166+
if (actionItem != null)
167+
{
168+
if (actionItem.ActionContext == _hyperlinkGHCopilotDocs.ActionContext)
169+
{
170+
LaunchGitHubCopilotDocs();
171+
}
172+
else
173+
{
174+
PackageManagerLaunchService?.Value.LaunchSolutionPackageManager();
175+
var evt = NavigatedTelemetryEvent.CreateWithVulnerabilityInfoBarManagePackages();
176+
TelemetryActivity.EmitTelemetryEvent(evt);
177+
}
178+
}
179+
}
180+
181+
private void LaunchGitHubCopilotDocs()
182+
{
183+
try
184+
{
185+
System.Diagnostics.Process.Start(_hyperlinkGHCopilotDocs.ActionContext);
186+
var evt = NavigatedTelemetryEvent.CreateWithExternalLink(HyperlinkType.VulnerabilityAdvisoryGHCopilotDocs);
187+
TelemetryActivity.EmitTelemetryEvent(evt);
188+
}
189+
catch (System.ComponentModel.Win32Exception ex)
190+
{
191+
ActivityLog.LogError(LogEntrySource, ex.ToString());
192+
}
159193
}
160194

161195
protected InfoBarModel GetInfoBarModel()
162196
{
163197
IEnumerable<IVsInfoBarTextSpan> textSpans = new IVsInfoBarTextSpan[]
164198
{
165199
new InfoBarTextSpan(Resources.InfoBar_TextMessage + " "),
166-
new InfoBarHyperlink(Resources.InfoBar_HyperlinkMessage)
200+
_hyperlinkPmui,
201+
new InfoBarTextSpan(" | "),
202+
_hyperlinkGHCopilotDocs
167203
};
168204

169205
return new InfoBarModel(

src/NuGet.Clients/NuGet.SolutionRestoreManager/xlf/Resources.cs.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
<target state="translated">Balíček {0} {1} nemá přesnou verzi, například [1.0.0]. S PackageDownload se povolují jenom přesné verze.</target>
2323
<note>0 - The package that does not have an exact version. Do not translate 'PackageDownload'. 1 - the version string that's not exact.</note>
2424
</trans-unit>
25+
<trans-unit id="InfoBar_HyperlinkGHCopilotDocs">
26+
<source>How to fix with GitHub Copilot</source>
27+
<target state="new">How to fix with GitHub Copilot</target>
28+
<note />
29+
</trans-unit>
2530
<trans-unit id="InfoBar_HyperlinkMessage">
2631
<source>Manage NuGet Packages</source>
2732
<target state="translated">Spravovat balíčky NuGet</target>

src/NuGet.Clients/NuGet.SolutionRestoreManager/xlf/Resources.de.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
<target state="translated">Das Paket "{0} {1}" weist keine genaue Version wie "[1.0.0]" auf. Nur exakte Versionen sind bei PackageDownload zulässig.</target>
2323
<note>0 - The package that does not have an exact version. Do not translate 'PackageDownload'. 1 - the version string that's not exact.</note>
2424
</trans-unit>
25+
<trans-unit id="InfoBar_HyperlinkGHCopilotDocs">
26+
<source>How to fix with GitHub Copilot</source>
27+
<target state="new">How to fix with GitHub Copilot</target>
28+
<note />
29+
</trans-unit>
2530
<trans-unit id="InfoBar_HyperlinkMessage">
2631
<source>Manage NuGet Packages</source>
2732
<target state="translated">NuGet-Pakete verwalten</target>

src/NuGet.Clients/NuGet.SolutionRestoreManager/xlf/Resources.es.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
<target state="translated">El paquete "{0} {1}" no tiene una versión exacta, como "[1.0.0]". Solo se permiten versiones exactas con PackageDownload.</target>
2323
<note>0 - The package that does not have an exact version. Do not translate 'PackageDownload'. 1 - the version string that's not exact.</note>
2424
</trans-unit>
25+
<trans-unit id="InfoBar_HyperlinkGHCopilotDocs">
26+
<source>How to fix with GitHub Copilot</source>
27+
<target state="new">How to fix with GitHub Copilot</target>
28+
<note />
29+
</trans-unit>
2530
<trans-unit id="InfoBar_HyperlinkMessage">
2631
<source>Manage NuGet Packages</source>
2732
<target state="translated">Administración de paquetes NuGet</target>

src/NuGet.Clients/NuGet.SolutionRestoreManager/xlf/Resources.fr.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
<target state="translated">Le paquet '{0}' {1} n’a pas de version exacte comme '[1.0.0]'. Seules les versions exactes sont autorisées avec PackageDownload.</target>
2323
<note>0 - The package that does not have an exact version. Do not translate 'PackageDownload'. 1 - the version string that's not exact.</note>
2424
</trans-unit>
25+
<trans-unit id="InfoBar_HyperlinkGHCopilotDocs">
26+
<source>How to fix with GitHub Copilot</source>
27+
<target state="new">How to fix with GitHub Copilot</target>
28+
<note />
29+
</trans-unit>
2530
<trans-unit id="InfoBar_HyperlinkMessage">
2631
<source>Manage NuGet Packages</source>
2732
<target state="translated">Gérer les packages NuGet</target>

0 commit comments

Comments
 (0)