Question Can you access VS objects from a running app?

Mandmd2

New member
Joined
Feb 4, 2009
Messages
3
Location
wake forest, NC
Programming Experience
5-10
I want to write an app in VS2005 that I will only run in Visual Studio (never deploy) to be used as a development programmers tool in our shop.

I'd like to have a form with a button that will Add an Item to my solution in Visual Studio while the app is running; with the ability to name the item using a title on the form's text box.

The thing is, I don't want to end the app to do stuff in Visual Studio as I would like to do repetitive stuff from my form (i.e. add more than one item to the solution at User's discretion).


Has anyone ever attempted anything similar? Wondering if it's even possible... looking for clues.

Mark
 
Thank you JohnH.

I'm looking at using the VS extension library envDTE as it looks to provide just what I need.

I am having a problem with it however. It doesn't want to recognize my Add Item Template name: ActiveReports3, which exists at:

C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\ItemTemplates\VisualBasic\1033\ActiveReports3.zip, and
C:\Documents and Settings\mdesrosiers\My Documents\Visual Studio 2005\Templates\ItemTemplates\Visual Basic\ActiveReports3.zip on my PC
(I've even gone so far as to unzip them even tho I'm sure the .zip format is usable)

My code:

Imports EnvDTE

' save click event - saves a report to the default path
Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreate.Click

Dim DTE As EnvDTE.DTE
Dim ItemOp As ItemOperations

Try

'Get an instance of the currently running Visual Studio IDE and add a new item
DTE = System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.8.0")
ItemOp = DTE.ItemOperations
ItemOp.AddNewItem("ActiveReports3", Me.tbRptFileName.Text & ".vb") ' <==== DIES HERE (error below)

Catch ex As Exception
System.Windows.Forms.MessageBox.Show(Me, ex.Message, "Application Error in btnCreate_Click sub", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub

I'm getting the error message: Template ActiveReports3 is not valid for the selected project.

I really need to get it to work... Will let you know of my progress.

Thanks for your response.
Mark
 
Last edited:
FYI I use VB Express, so I can't work with VS extensibility, but perhaps others can.

Use formatting when you post, put code in code boxes and quotes in quote boxes etc, the forum posting editor is very easy to use, you can preview your post prior to submitting it to make sure it looks how you intended.
 
Way cool :) Thank you JohnH

VB.NET:
' save click event - saves a report to the default path
    Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
     Handles btnCreate.Click
 
        Dim DTE As EnvDTE.DTE
        Dim ItemOp As ItemOperations
 
        Try
            ' disable group once again when done
            Me.grpCreate.Enabled = False
            ' and enable the create button
            Me.btnNew.Enabled = True
 
            'Get an instance of the currently running Visual Studio IDE and add a new item
            DTE = System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.8.0")
            ItemOp = DTE.ItemOperations
            ItemOp.AddNewItem("ActiveReports3", Me.tbRptFileName.Text & ".vb") ' TODO: Fix <==== DIES HERE (error below)
 
        Catch ex As Exception
            System.Windows.Forms.MessageBox.Show(Me, ex.Message, "Application Error in btnCreate_Click sub", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub
 
Back
Top