{"id":5103,"date":"2007-11-27T23:08:00","date_gmt":"2007-11-27T23:08:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vbteam\/2007\/11\/27\/launching-external-tools-from-inside-visual-studio-jonathan-aneja\/"},"modified":"2024-07-05T14:37:38","modified_gmt":"2024-07-05T21:37:38","slug":"launching-external-tools-from-inside-visual-studio-jonathan-aneja","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/vbteam\/launching-external-tools-from-inside-visual-studio-jonathan-aneja\/","title":{"rendered":"Launching External Tools from inside Visual Studio (Jonathan Aneja)"},"content":{"rendered":"<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">Visual Studio has a small but extremely useful feature that allows you to hook external tools directly into the IDE\u2019s Tools menu.&nbsp; All you have to do is click Tools-&gt;External Tools\u2026 and then you can add your own custom menu items that will launch a specified program.<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">&nbsp;<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">On a typical day I\u2019ll probably fire up <\/font><a href=\"http:\/\/www.aisto.com\/roeder\/dotnet\/\"><font face=\"Calibri\" color=\"#800080\" size=\"3\">Reflector<\/font><\/a><font face=\"Calibri\" size=\"3\"> and\/or ildasm a few times, and I\u2019ve always found it annoying to have to leave the IDE to&nbsp;launch the program,&nbsp;then navigate to the folder where my .dll is.&nbsp; Adding them to the menu once&nbsp;simplifies things and saves a&nbsp;lot of time.<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">&nbsp;<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">Let\u2019s take a look at how we would do this for Reflector:<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font face=\"Calibri\" size=\"3\">1.<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">Click Tools-&gt;External Tools\u2026<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font face=\"Calibri\" size=\"3\">2.<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">Click Add<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font face=\"Calibri\" size=\"3\">3.<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">For Title enter \u201c&amp;Reflector\u201d<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font face=\"Calibri\" size=\"3\">4.<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">For Command just navigate to the path for Reflector.exe<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font face=\"Calibri\" size=\"3\">5.<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">For Arguments click the arrow on the right side and select &#8220;Target Path&#8221;<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">&nbsp;<\/font><\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" title=\"External Tools - Photo 1\" height=\"399\" alt=\"External Tools - Photo 1\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2007\/11\/ExternalTools1.jpg\" width=\"397\"><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">&nbsp;<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">Now when you click the new menu item it\u2019ll fire up Reflector with your current project in the list of assemblies.&nbsp; Same thing works for ildasm as well.&nbsp; $(TargetPath) represents the fully-qualified path to your project\u2019s output (i.e. your .exe or .dll file).&nbsp; If you want to preview what all the different variables (such as $(TargetName), $(BinDir), etc\u2026) will be for your project you can examine these in the Build Events dialog:<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font face=\"Calibri\" size=\"3\">1.<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">Double-click \u201cMy Project\u201d<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font face=\"Calibri\" size=\"3\">2.<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">Click on the Compile tab<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font face=\"Calibri\" size=\"3\">3.<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">Click on Build Events in the bottom-right corner<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font face=\"Calibri\" size=\"3\">4.<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">Click Edit Pre-build<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font face=\"Calibri\" size=\"3\">5.<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">Click Macros &gt;&gt;<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font face=\"Calibri\" size=\"3\">6.<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">Resize the window and grid and you can now see the value of each variable<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">&nbsp;<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">Where this can come in really handy is if you want to test your application using different user credentials.&nbsp; This is especially important when accessing a database using Windows Authentication.&nbsp; What if the permissions are set incorrectly on a stored procedure?&nbsp; How do you verify that your application\u2019s authorization logic is doing the right thing based on the user\u2019s permission level?&nbsp; Just because the application works for you in VS doesn\u2019t mean it\u2019ll work in production&nbsp;under a normal user\u2019s credentials.<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">&nbsp;<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">One way to do this type of testing is by using runas.exe and passing in a sample user with the \/user switch.&nbsp; We use $(TargetPath) again to launch our actual .exe, and now when we click the menu item we\u2019ll be prompted for the user\u2019s password. After that your application is now running under that user\u2019s credentials, and you can verify that everything works as expected.<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">&nbsp;<\/font><\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" title=\"External Tools - Photo 2\" height=\"399\" alt=\"External Tools - Photo 2\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2007\/11\/ExternalTools2.jpg\" width=\"397\"><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">&nbsp;<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">You\u2019ll either want to make one of these commands for each user-access level (i.e. \u201cLimited User\u201d, \u201cManager\u201d, \u201cAdministrator\u201d etc\u2026), or alternatively just have one command and select \u201cPrompt for arguments\u201d to type in the user ID each time.<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">&nbsp;<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">Other situations that might be useful include launching a VS command prompt (vcvarsall.bat)&nbsp;or invoking a batch file that backs up your project. &nbsp;If you find yourself constantly leaving the IDE to run a certain tool, it\u2019s probably a good candidate to add to the menu.&nbsp; Best of all, this functionality works in Visual Studio 2003, 2005, and also the recently-released <\/font><a href=\"http:\/\/msdn2.microsoft.com\/en-us\/vstudio\/products\/aa700831.aspx\"><font face=\"Calibri\" color=\"#800080\" size=\"3\">2008<\/font><\/a><font face=\"Calibri\" size=\"3\">.<\/font><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Visual Studio has a small but extremely useful feature that allows you to hook external tools directly into the IDE\u2019s Tools menu.&nbsp; All you have to do is click Tools-&gt;External Tools\u2026 and then you can add your own custom menu items that will launch a specified program. &nbsp; On a typical day I\u2019ll probably fire [&hellip;]<\/p>\n","protected":false},"author":260,"featured_media":8818,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[192,195],"tags":[74,83,117,165,166],"class_list":["post-5103","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-featured","category-visual-basic","tag-ide","tag-jonathan-aneja","tag-orcas","tag-vb2005","tag-vb2008"],"acf":[],"blog_post_summary":"<p>Visual Studio has a small but extremely useful feature that allows you to hook external tools directly into the IDE\u2019s Tools menu.&nbsp; All you have to do is click Tools-&gt;External Tools\u2026 and then you can add your own custom menu items that will launch a specified program. &nbsp; On a typical day I\u2019ll probably fire [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts\/5103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/users\/260"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/comments?post=5103"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts\/5103\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/media\/8818"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/media?parent=5103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/categories?post=5103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/tags?post=5103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}