Not using AppAddIns and loading COM dlls

 

Q:

 

This is what I’d like to do and may you can help me with this.

 1.    Load a bare bones project that doesn’t have anything other than a simple blank class that I’d like to edit. 

2.    Not use AppAddIn’s at all(meaning no need to launch the myvbapp). 

3.    Load my COM dlls into the project.

 

 

 

A:

  

1.    Load a bare bones project that doesn’t have anything other than a simple blank class that I’d like to edit.

The CreateProjectFromTemplateOrOpenExisting shows this- see the code in bold below

            'create the a new project in the specified path based on the specified template

            Me.mProject = Me.mDTE.Solution.AddFromTemplate(templatePath, projectPath, _

           System.IO.Path.GetFileName(ProjectFilePath), True)

2.    Not use AppAddIns at all (meaning no need to launch the myvbapp). 

If you leave the DebugInfoExeName blank the host will not run but you will get a message like:

 

 

3.    Load our com dlls into the project.

 

The project template includes a proj file where you specify the references to be included with the project:

  <!-- This sections specifies references for the project. -->

  <ItemGroup>

    <Reference Include="Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0" />

    <Reference Include="ShapeAppCSharpProxy, Version=2.0.0.0, Culture=neutral, PublicKeyToken=3c3c0c46dd27dbcf, processorArchitecture=MSIL">

      <SpecificVersion>True</SpecificVersion>

    </Reference>

    <Reference Include="System" />

    <Reference Include="System.AddIn">

      <RequiredTargetFramework>3.5</RequiredTargetFramework>

    </Reference>

    <Reference Include="System.Data" />

    <Reference Include="System.Xml" />

    <Reference Include="System.Drawing" />

    <Reference Include="System.Windows.Forms" />

  </ItemGroup>

 

     Public Sub CreateProjectFromTemplateOrOpenExisting(ByVal TemplateName As String, ByVal ProjectFilePath As String)

 

        Dim lang As String = "VisualBasic"

 

        'determine the language - must have CSharp template to use this

        If ProjectFilePath.Contains(".csproj") Then

            lang = "CSharp"

        End If

 

        'IF the dte does not already exit, create it

        If Me.mDTE Is Nothing Then

            Me.ShowVSTAIDE(True)

        End If

 

        'create a solution in the DTE

        Dim sol As EnvDTE80.Solution2 = CType(mDTE.Solution, EnvDTE80.Solution2)

 

        'If the project exists

        If System.IO.File.Exists(ProjectFilePath) Then

 

            'open the file

            Me.mProject = mDTE.Solution.AddFromFile(ProjectFilePath, True)

            Me.mProjectPath = ProjectFilePath

 

        Else 'the project doesn't exist, create a new one

 

            'get the path to create the project in

            Dim projectPath As String = System.IO.Path.GetDirectoryName(ProjectFilePath)

 

            'select the template to use

            Dim templatePath As String = sol.GetProjectTemplate(TemplateName, lang)

 

            'IF the specified project isn't available throw an exception

            If templatePath = String.Empty Then

                Throw New System.IO.FileNotFoundException("Project template has not been registered.")

            End If

 

            'create the a new project in the specified path based on the specified template

            Me.mProject = Me.mDTE.Solution.AddFromTemplate(templatePath, projectPath, _

                                         System.IO.Path.GetFileName(ProjectFilePath), True)

            Me.mProjectPath = ProjectFilePath

        End If

    End Sub

 

 

 

 

 


Posted May 22 2009, 03:26 PM by BillL
Filed under: , , ,
Copyright Summit Software Company, 2008. All rights reserved.