Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert a new GUID to Visual Studio 2013

How to create GUIDs in Visual Studio 2013? I had an add in that worked well in VS2012 but it does not work in VS2013. I found this Create GUID in VS2012 and this How to convert VS2012 add ins to VS2013 Packages but could not make it work (add ins are not my forte - I simply edit SQL scripts). Is there an easy way to get back this functionality?

like image 649
Frank Monroe Avatar asked Oct 09 '13 21:10

Frank Monroe


4 Answers

If you're using ReSharper (highly recommended), you can create new GUIDs everywhere by typing nguid and pressing Tab.

like image 66
Igal Tabachnik Avatar answered Oct 28 '22 17:10

Igal Tabachnik


Actually, uou can just use guidgen.exe which should get installed with VS.

Using menu TOOLS -> External Tools... add:

%Installation Path%\Microsoft Visual Studio 12.0\Common7\Tools\guidgen.exe

e.g.

C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\guidgen.exe

Give the title of ‘Create GUID’ and it is there just as it was in VS2010.

like image 23
Darren Avatar answered Oct 28 '22 17:10

Darren


The best tool / add-in for this is: http://visualstudiogallery.msdn.microsoft.com/22795583-5cc9-4681-af8e-6084f3441655

like image 35
Frank Monroe Avatar answered Oct 28 '22 15:10

Frank Monroe


I was also wondering how I should do this. I saw the following example: Inserting a Guid for VS 2012. For VS2013 you have to install the SDK. Once you have done that you will see the template project items for packages and also for addins when you go to add a new project.

Despite the documentation saying that addins were deprecated in VS2013 they do appear to work (I am using VS2013 Ulitmate v 12.0.21005.1 REL). You can follow the instructions in the previous article.

I also created a package which was relatively straight forward too. Using How to: Convert an Addin to a VS Package I was able to create the package.

As in the article I added the following using statements:

using EnvDTE;
using EnvDTE80;

I then changed the MenuItemCallback method to the following:

private void MenuItemCallback(object sender, EventArgs e)
        {
            DTE2 dte = (DTE2)GetService(typeof(DTE));

            if (dte.ActiveDocument != null)
            {
                TextSelection objSel = (EnvDTE.TextSelection)(dte.ActiveDocument.Selection);

                objSel.Insert(Guid.NewGuid().ToString());
            }
        }

After building the project I went to the bin\Debug folder and started the vsix file (GuidPackage.vsix in my case). This installed the package for use in the IDE.

I now have a menu item to insert guids into my code and am able to create a shortcut key stroke for it in the usual way.

like image 3
zeiddev Avatar answered Oct 28 '22 17:10

zeiddev