Q:
I have hit a snag which I can't seem to resolve. This is related to the VSTA project templates generated by ProjGen.exe. One part of the solution generated by the tool is the description of the host item. It is represented by two files - the user portion (e.g. ThisAddin.cs or ThisAddin.vb) and internal portion that has some setup code (ThisAddin.Designer.cs/.vb). The problem is that the actual code is not generated by the tool, but rather is represented by a "blueprint" file (.xml) and underlined code is generated automatically by VSTA IDE when a new project is created.
The default generated code is Ok, but I need to add some customization to that code to set up some strong types to eliminate this from the user-side portion of the entry point class.
A:
Indeed, the .designer.cs file is generated by VSTA in design time with the XML as you deduced.
You can work around it by adding template code to the following #region in user code side, AppAddin.cs:
#region VSTA generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(AppAddIn_Startup);
this.Shutdown += new System.EventHandler(AppAddIn_Shutdown);
}
private StrongTypeAppObj Application;
private void AppAddIn_Startup(object sender, EventArgs e)
{
//hook up strong typed Application object
Application = GetHostOM() as StrongTypeAppObj;
}
private void AppAddIn_Shutdown(object sender, EventArgs e)
{
}
#endregion
Also, because the base class of the AddIn (entrypoint) class is defined in the proxy, you can easily add public strong-typed members to the hostitem class definitions in the proxy source [see below]. This will give the addIn author access to strong-typed members, ie: this.ExcelApp or ExcellApp. This approach would require the proxy assembly to also hold references to your program's interop assemblies (PIAs').
(added to proxy.cs for ShapeApp sample)
[global::System.AddIn.Pipeline.AddInBaseAttribute(ActivatableAs = new global::System.Type[] { typeof(Microsoft.VisualStudio.Tools.Applications.Runtime.IEntryPoint) })]
public partial class ApplicationEntryPoint : global::Microsoft.VisualStudio.Tools.Applications.Runtime.IExtendedEntryPoint
{
public Microsoft.Office.Interop.Excel.Application excelApp;
.
.
. public virtual Microsoft.Office.Interop.Excel.Application ExcelApp
{
get
{
if (excelApp == null)
{
excelApp = new Microsoft.Office.Interop.Excel.Application();
}
return excelApp;
}
}
Posted
Jun 03 2009, 01:59 PM
by
BillL