Insert a new GUID to Visual Studio 2013
Asked Answered
B

7

21

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?

Bonilla answered 9/10, 2013 at 21:13 Comment(0)
K
49

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

Karankaras answered 9/10, 2013 at 21:35 Comment(1)
Thanks, I knew that. But that's not what I am looking for. I want a VS 2013 Package (BTW these used to be known as 'add ins' in previous version of VS - but the VS2013 RC MSDN page says here add ins are 'deprecated').Bonilla
L
19

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.

Lase answered 16/4, 2014 at 3:12 Comment(0)
B
5

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

Bonilla answered 6/6, 2014 at 1:53 Comment(0)
S
3

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.

Sondra answered 24/10, 2013 at 10:13 Comment(0)
A
2

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
Aklog answered 7/10, 2016 at 8:50 Comment(0)
E
0

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;

Etesian answered 12/1, 2016 at 10:9 Comment(0)
F
0

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.
Feticide answered 6/7, 2022 at 17:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.