Udostępnij za pośrednictwem


How to: Start the IDE

There are two ways to start the Visual Studio Tools for Applications integrated development environment (IDE) from your host application:

  • Add code to the host application that starts the IDE from host application menu commands or from keyboard shortcuts such as ALT+F11.

  • Install a shortcut on the Start menu as part of your host application Setup program.

If you choose the first option, you can also add code to programmatically open a new or existing project for the add-in developer. Consider providing this added convenience in cases where you know which project template to instantiate or what existing project the add-in developer needs to open.

Starting from Inside the Host Application

To add references

  1. In Solution Explorer, right-click the project to which you intend to add the code to start the IDE, and then click Add Reference.

  2. In the Add Reference dialog box, click the .NET tab and add a reference to Microsoft.VisualStudio.Tools.Applications.DesignTime.v9.0.

  3. Click the COM tab and add references to the following assemblies:

    • DTEProvider 1.0 Type Library in the C:\Program Files\Common Files\Microsoft Shared\VSTA\9.0\x86 directory

    • Microsoft Development Environment 8.0

To start the Visual Studio Tools for Applications IDE

  1. In your project, locate the class that contains the IDE code, or add a new class to the project to contain the code.

  2. Add the following using statements to the top of the code file.

    using VSTADTEProvider.Interop;
    using EnvDTE;
    
  3. Declare an instance of the DTE object.

    private DTE vstaDTE;
    
  4. Add the following code to create a DTE object and start the IDE. Replace HostID with the host ID of the host application. You can find this identifier in the registry under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VSTAHostConfig\ on computers that have a 32-bit operating system, and under HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VSTAHostConfig\ on computers that have a 64-bit operating system.

    You must register the host application for the host ID entry to be present. For more information, see How to: Register the Host Application.

    private void startIDE()
    {
        IDTEProvider dteProvider = new VSTADTEProviderClass();
        string HostID = "HostID";
        UInt32 TimeOut = 10000;
        vstaDTE = dteProvider.GetDTE(HostID,TimeOut);
        vstaDTE.MainWindow.Visible = true;
    }
    

To start the Visual Studio IDE

  1. In your project, locate the class that contains the IDE code, or add a new class to the project to contain the code.

  2. Add the following using statements to the top of the code file.

    using VSTADTEProvider.Interop;
    using EnvDTE;
    
  3. Declare an instance of the DTE object.

    private DTE vstaDTE;
    
  4. Add the following code to create a DTE object and start the IDE. Replace HostID with the host ID of the host application. You can find this identifier in the registry under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VSTAHostConfig\ on computers that have a 32-bit operating system, and under HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VSTAHostConfig\ on computers that have a 64-bit operating system.

    You must register the host application for the host ID entry to be present. For more information, see How to: Register the Host Application.

    private void startIDE()
    {
        IDTEProvider2 dteProvider = new VSTADTEProviderClass();
        string HostID = "HostID";
        UInt32 TimeOut = 10000;
        vstaDTE = dteProvider.GetVSDTE(HostID,TimeOut);
        vstaDTE.MainWindow.Visible = true;
    }
    

To create a new project

  • Use the DTE object that you use to start the IDE to return a _Solution instance. Call the AddFromTemplate method of the _Solution instance to open a new project. Set projectTemplatePath to the full path of the project template you want to instantiate. Set targetProjectDirectory to the directory path where you intend to create the new project. Set targetProjectFilename to the name of the project file to create.

    private void openProjectTemplate()
    {
        string projectTemplatePath = "Project Template Path";
        string targetProjectDirectory = "Target Project Directory";
        string targetProjectFilename = "Target Project Filename";
        this.vstaDTE.Solution.AddFromTemplate(projectTemplatePath,
            targetProjectDirectory, targetProjectFilename, true);
    }
    

To open an existing project

  • Use the DTE object that you use to start the IDE to return a _Solution instance. Call the AddFromFile method of the _Solution instance to open an existing project. Set projectFilePath to the directory location of the project to open.

    private void openExistingProject()
    {
        string projectFilePath = "Project File Path";
        this.vstaDTE.Solution.AddFromFile(projectFilePath, true);
    }
    

Starting from the Start Menu

To start the IDE using a shortcut

  • Use the following command to start the IDE. You can run this command from the Command Prompt window, or you can use it to enable add-in developers to start the IDE from the Start menu or from a shortcut icon. For information about how to create shortcut icons during deployment, see How to: Add and Remove Shortcuts in the File System Editor.

    You can find the value of hostID in the registry under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VSTAHostConfig\ on 32-bit platforms, and under HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VSTAHostConfig on 64-bit platforms. You must register the host for this entry to be present. For more information, see How to: Register the Host Application.

    %ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\vsta.exe /hostid hostID
    

    Note

    Vsta.exe might not be installed to %ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE. This might be the case if the user had previously installed Visual Studio 2008 to a different location.

    To guarantee that the shortcut points to the correct location, find the location of vsta.exe on the computer during installation. You can then generate a shortcut using that path. You can find the correct location of vsta.exe by reading the InstallDir value from the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VSTA\9.0 registry key on 32-bit platforms, and from the HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VSTAHostConfig key on 64-bit platforms.

See Also

Tasks

How to: Exit the IDE

How to: Enable Non-Destructive Debugging for Add-Ins

Walkthrough: Incorporating the IDE for a Managed Object Model

Concepts

Incorporating the Integrated Development Environment

Configuring the IDE

Integrating Help into the IDE

Add-In Debugging

Deploying the IDE and Runtime

Creating Project Templates (Visual Studio Tools for Applications)

Other Resources

Visual Studio Tools for Applications 2.0