Make classes visible in the VSTA template.

Q:

Is there any way to make appaddin.vb or any class invisible in the vsta template?

 

A:

It’s a little tricky to do this, but I got a template together.  The only code file which is displayed is an empty class (MainCodeClass) and is in the file AppAddIn.vb (VSTA is particular about the naming scheme but not the content of the file).  The content of the old AppAddIn.vb file is moved to the  SupportingClassFile.vb file which is hidden under “My Project” and because of the added attributes is not visible to intellesense.  In the AppAddIn.OnStartup a new instance of the MainCodeClass is created. 

 

With this scheme, please keep in mind that “Me” no longer refers to the host application and the AppAddIn type is hidden from intellesence.  I made a simple add-in from this template and verified that it loads into the host, although it cannot interact with it unless you tinker with the old AppAddIn file.  One suggestion is to make the constructor of the MainCodeClass file take in an Application object which the AppAddIn.OnStartup method can pass to it. 

 

Here are the changes I made:

<!--[if !supportLists]-->1)      <!--[endif]-->Move the contents of the AppAddIn.vb file to a new file SupportingCodeFile.vb

 

<!--[if !supportLists]-->2)      <!--[endif]-->Move the contents of the main code file, in this case an empty class, to the AppAddIn.vb file

 

<!--[if !supportLists]-->3)      <!--[endif]-->In the SupportingCodeFile add attributes to the AppAddIn class to hide it from Intellesense

'ADD THESE ATTRIBUTES TO HIDE THE CLASS FROM INTELESENSE

<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _

 Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Never)> _

Partial Class AppAddIn

 

<!--[if !supportLists]-->4)      <!--[endif]-->Add the SupportingCodeFile to the vstemplate and vbproj files under “My Project”

Vstemplate file:

      <!--Old AppAddIn file under My Project-->

      <ProjectItem

          ReplaceParameters="true"

          TargetFileName="My Project\SupportingCodeFile.vb">SupportingCodeFile.vb</ProjectItem>

 

Vbproj file:

      <!--Old AppAddIn file now under My Project-->

      <Compile

            Include="My Project\SupportingCodeFile.vb">       

        <SubType>Code</SubType>

      </Compile>

 

Without ShowAll:

 

 

 

 

 

 

With ShowAll:

 

 

 

 

 


Posted May 22 2009, 11:36 AM by BillL
Copyright Summit Software Company, 2008. All rights reserved.