Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating a plain GUID in Visual Studio

Create GUID box

If I try using the "Create GUID" tool using "Tool" > "Create GUID", I get a box that has six different snippets which contains GUIDs. But it doesn't offer the option of providing only the GUID. Is there any way to do this?

I'm using Visual Studio Professional 2019, version 16.1.6, and .NET version 4.8.03761.

like image 976
Andrew Grimm Avatar asked Sep 12 '25 20:09

Andrew Grimm


2 Answers

Instead of installing a new extension (as mentioned in the other answers), you can just use a built-in tool in Visual Studio called "C# Interactive".

Here are the steps:

  1. On VS open the "C# Interactive" window (if not opened) by
    pressing Ctrl+Q and typing "C# Interactive"
  2. Type the following in the window and press enter:
    System.Guid.NewGuid().ToString()

And you'll get the result:

enter image description here

Note: In case you need it again, just hit Up Arrow button and the last command will reappear, so you don't need to type again.


P.S. Basically we just execute a C# code in the "C# Interactive" window.
You can modify the code there to whatever you want. For example, you can go further and generate a list of guids with by typing there a code like this:

> for (int i = 0; i < 100; i++)
{
    Console.WriteLine(Guid.NewGuid().ToString());
}
like image 155
Just Shadow Avatar answered Sep 14 '25 13:09

Just Shadow


The Create UID option is available by default in Professional and Enterprise versions. To have Create GUID functionality you can add the Create GUID tool yourself by following the below steps.

  1. Go to the Visual Studio menu and click on Tools then External Tools.

    Visual Studio Tools

  2. The below model will pop up.

    New Tool Popup Modal

    Title: Create GUID
    Command: Powershell.exe
    Arguments: [guid]::NewGuid()
    Use Output Window: Check/True 
    
  3. Click Apply then OK.

  4. Now again go to VS Menu -> Tools and you'll be able to see the Create GUID option in the Tools menu.

    Create GUID Option

  5. Click on Create GUID and check the output window.

    Generated GUID

like image 38
MMUNEEBALI Avatar answered Sep 14 '25 15:09

MMUNEEBALI