locked
VSIX Connect file type with custom window RRS feed

  • Question

  • Hi,

    Can somebody please tell me how to connect an Custom Tool Window with an File extension?

    I want to makean UI, which generates some Code. 

    Therefore I want to use a SingleFile-Generator for the Class generation Logic.

    Is there some good example or a tutorial?

    Thanks in Advance.


    Sunday, November 5, 2017 11:26 AM

All replies

  • Hi IIIusion-Cloud,

    Welcome to the MSDN forum.

    Refer to your description, your issue is about the VS extension development. Since our forum is to discuss the VS IDE, I will help you move this thread to the appropriate forum to get a better support, thank you for your understanding.

    Best regards,

    Sara


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Monday, November 6, 2017 1:37 AM
  • Hi Illusion-Cloud,

    The following Thread provide 4 steps to generate Code from a Visual Studio Extension For your reference.

    For creating a new File from a Visual Studio Extension (ToolWindowPane)

    Firstly use the GetService method:

    // Get an instance of the currently running Visual Studio IDE
    DTE dte = (DTE)GetService(typeof(DTE));

    Secondly, ensure that a Solution is currently open, if no solution is open the File generation will not work:

    string solutionDir = System.IO.Path.GetDirectoryName(dte.Solution.FullName);

    Thirdly, generate the new file from the DTE object:

    dte.ItemOperations.NewFile(@"General\Visual C# Class", "ObjectOne", EnvDTE.Constants.vsViewKindTextView);

    After creating the new file use the following code to access the text of that file and replace it with your generated text:

    TextSelection txtSel = (TextSelection)dte.ActiveDocument.Selection;
    TextDocument txtDoc = (TextDocument)dte.ActiveDocument.Object("");
    
    txtSel.SelectAll();
    txtSel.Delete();
    txtSel.Insert("Hello World");

    https://stackoverflow.com/questions/10126846/generate-code-from-a-visual-studio-extension

    Best regards,

    Zhanglong Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, November 23, 2017 6:53 AM