{"id":56207,"date":"2013-07-25T00:00:00","date_gmt":"2013-07-25T07:00:00","guid":{"rendered":"http:\/\/devblogs.microsoft.com\/nuget\/invoke-manage-nuget-packages-dialog-programmatically"},"modified":"2013-07-25T00:00:00","modified_gmt":"2013-07-25T07:00:00","slug":"invoke-manage-nuget-packages-dialog-programmatically","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/invoke-manage-nuget-packages-dialog-programmatically\/","title":{"rendered":"Invoke the Manage NuGet Packages dialog programmatically"},"content":{"rendered":"<p>Recently I&#8217;ve been asked several times for how to invoke the Manage NuGet Packages dialog from VS components programmatically, and optionally auto-invoke the search when the dialog opens. Today I&#8217;d like to share the solution in this post.<\/p>\n<p>It&#8217;s actually very straightforward. The <strong>Manage NuGet Packages<\/strong> menu command is registered as a standard VS command, thus you can call <code>DTE.ExecuteCommand()<\/code> to invoke it. The trick is to know the command name, which is <strong>Project.ManageNuGetPackages<\/strong>. Here&#8217;s a code sample:<\/p>\n<pre><code>DTE dte = (DTE)GetService(typeof(SDTE)); \ndte.ExecuteCommand(\"Project.ManageNuGetPackages\");<\/code><\/pre>\n<p>Note that it will open the <em>project-level<\/em> dialog. To open the <em>solution-level<\/em> dialog instead, you replace the command name with <strong>Tools.ManageNuGetPackagesforSolution<\/strong>.<\/p>\n<p>The <code>ExecuteCommand()<\/code> method also accepts a second optional parameter of string type. If you pass a string value to it, the NuGet command handler will intepret it as a search query and will automatically issue a search request after it has opened the dialog.<\/p>\n<pre><code>DTE dte = (DTE)GetService(typeof(SDTE)); \ndte.ExecuteCommand(\"Project.ManageNuGetPackages\", \"jQuery\");<\/code><\/pre>\n<p>With the above code, assuming you have the Online tab selected the last time you closed it, you will see this:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/49\/2019\/05\/\/open-dialog-with-search.png\" alt=\"Dialog opened with search query \" \/><\/p>\n<p>If, for some reason, you don&#8217;t like to call through DTE, you can also invoke the command directly through the <code>OleMenuCommandService<\/code> service.<\/p>\n<pre><code>var nugetCommandGuid = Guid.Parse(\"25fd982b-8cae-4cbd-a440-e03ffccde106\"); \nvar nugetCommand = new CommandID(nugetCommandGuid, 0x100); \n\n\/\/ 0x100 is the command id for project-level dialog \nOleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; \nmcs.GlobalInvoke(nugetCommand, \"jQuery\");<\/code><\/pre>\n<p>Again, to open the solution-level dialog, you set the command id to 0x200. These constants are set in the <a title=\"PkgCmdID.cs\" href=\"https:\/\/nuget.codeplex.com\/SourceControl\/latest#src\/VsExtension\/PkgCmdID.cs\">NuGet source code<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently I&#8217;ve been asked several times for how to invoke the Manage NuGet Packages dialog from VS components programmatically, and optionally auto-invoke the search when the dialog opens. Today I&#8217;d like to share the solution in this post. It&#8217;s actually very straightforward. The Manage NuGet Packages menu command is registered as a standard VS command, [&hellip;]<\/p>\n","protected":false},"author":4268,"featured_media":58792,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[7874,646],"tags":[],"class_list":["post-56207","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-nuget","category-visual-studio"],"acf":[],"blog_post_summary":"<p>Recently I&#8217;ve been asked several times for how to invoke the Manage NuGet Packages dialog from VS components programmatically, and optionally auto-invoke the search when the dialog opens. Today I&#8217;d like to share the solution in this post. It&#8217;s actually very straightforward. The Manage NuGet Packages menu command is registered as a standard VS command, [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/56207","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/4268"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=56207"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/56207\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/58792"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=56207"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=56207"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=56207"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}