Frank Monroe
Frank Monroe

Reputation: 1611

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?

Upvotes: 21

Views: 17140

Answers (7)

Anastasios Selmani
Anastasios Selmani

Reputation: 3699

One other tool that I came by was this extension. Works pretty good

"Insert new GUID" (Shift+Alt+G): Inserts a new GUID at the current position.
"Insert last GUID" (Ctrl+Shift+Alt+G): Re-inserts the last new GUID at the current position.

Upvotes: 0

Andrey Burykin
Andrey Burykin

Reputation: 728

Just use PowerShell from VS Package Manage Console:

  1. Switch to Package Manager Console (or you can open PowerShell cmd).
  2. Execute [guid]::NewGuid().

Result:

Guid                                
----                                
61dabfd8-9151-46f5-8d92-72306044d844

Upvotes: 2

Erfankam
Erfankam

Reputation: 387

I prefer to use this solution:

_TUCHAR *guidStr = 0x00;

GUID *pguid = 0x00;

pguid = new GUID;

CoCreateGuid(pguid);

// Convert the GUID to a string UuidToString(pguid, &guidStr);

delete pguid;

Upvotes: 0

Frank Monroe
Frank Monroe

Reputation: 1611

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

Upvotes: 5

Darren
Darren

Reputation: 9499

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.

Upvotes: 19

zeiddev
zeiddev

Reputation: 702

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.

Upvotes: 3

Igal Tabachnik
Igal Tabachnik

Reputation: 31548

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

Upvotes: 49

Related Questions