Reputation: 81510
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.
Upvotes: 22
Views: 20789
Reputation: 11871
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:
System.Guid.NewGuid().ToString()
And you'll get the result:
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());
}
Upvotes: 36
Reputation: 11
Adding my version of the External Tool solution. This version is based on @MMUNEEBALI solution but extends it by copying the GUID to the clipboard.
Upvotes: 1
Reputation: 628
Install this extension: Insert Guid by Mads Kristensen (works with Visual Studio 2017, 2019, 2022).
And you will have a new entry in the Edit menu (with the shortcut Ctrl + K, Ctrl + Space):
That will insert a GUID exactly in the point you are in the code.
Upvotes: 2
Reputation: 8270
Go to Tools > External Tools
Title: Create &GUID
Visual Studio 2022
Command: C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\guidgen.exe
Initial Directory: C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools
Visual Studio 2019
Command: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\guidgen.exe
Initial Directory: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools
It is possible that your directories may be different. Just search for "guidgen.exe" if you have issues finding it.
Now you can go Tools > Create Guid and see:
Upvotes: 2
Reputation: 161
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.
Go to the Visual Studio menu and click on Tools then External Tools.
The below model will pop up.
Title: Create GUID
Command: Powershell.exe
Arguments: [guid]::NewGuid()
Use Output Window: Check/True
Click Apply then OK.
Now again go to VS Menu -> Tools and you'll be able to see the Create GUID option in the Tools menu.
Click on Create GUID and check the output window.
Upvotes: 16
Reputation: 27890
You can use the following command (language C#) for my Visual Commander extension to insert a plain GUID:
public class C : VisualCommanderExt.ICommand
{
public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
{
EnvDTE.TextSelection ts = DTE.ActiveDocument.Selection as EnvDTE.TextSelection;
ts.Text = System.Guid.NewGuid().ToString();
}
}
Upvotes: 2