Insert a new GUID to Visual Studio 2012

﹥>﹥吖頭↗ 提交于 2019-12-02 16:42:16

You could write a Visual Studio 2012 extension to accomplish this!
If you've never written an Add-in before, this is a simple one to get you started!

Here are the steps to create this type of add-in:

  1. Create a New Project in Visual Studio 2012
  2. Choose Templates -> Other Project Types -> Extensibility -> Visual Studio Add-in
  3. Name your project, click OK.
  4. Follow the Add-in wizard steps. When prompted, check the box for: "Yes, create a 'Tools' menu item." Optionally, I also check "My Add-in will never put up modal UI..."
  5. Finish the wizard and implement the follow code in Exec(...)

    public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
    {
        handled = false;
        if(executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
        {
            if (commandName == this.GetType().Namespace + ".Connect." + this.GetType().Namespace)
            {
                if (_applicationObject.ActiveDocument != null)
                {
                    TextSelection objSel = (EnvDTE.TextSelection)(_applicationObject.ActiveDocument.Selection);
    
                    objSel.Insert(Guid.NewGuid().ToString());
                }
    
                handled = true;
                return;
            }
        }
    }
    
  6. Build the project, and deploy AddInName.dll, AddInName.AddIn, and AddInName.xml to c:\users\username\documents\Visual Studio 2012\Addins. [If the Addins folder doesn't exist, create it]

  7. In Visual Studio 2012, under Tools -> Addin Manager, Check the box on the left next to AddInName.
  8. Restart Visual Studio 2012
  9. You should now see the AddInName listed under Tools. [probably with a Smiley face!]
  10. When you click on this, it should insert a new GUID at your cursor's location.
  11. Map this to a hotkey by navigating to Tools -> Options -> Environment -> Keyboard, search for AddInName, and bind a hotkey to it.

Voila! Hotkey GUID generation and a little bit of Visual Studio Add-in know how. :)

ReSharper allows you to insert a new guid by typing "nguid" and pressing tab.

Obviously this is a tad on the expensive side just for the ability to generate a Guid however ReSharper has many other useful features that might be worth considering.

My SCLAssist extension has this feature. You can bind the "Paste GUID" to a key mapping. SCLAssist is free.

Looks like they brought it back - in VS 2015 (I'm using the Community version) there is a Tools > Create GUID option.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!