I get the following error when I try to do an AddFile command from
within my addin:
Could not run the 'C:\Program Files\Microsoft Visual Studio .NET
2003\VC#\CSharpProjectItems\CSharpAddClassWiz.vsz
No Inner Exception -
I know its the code as I have been able to reproduce this on tow
different machines -
Anybody run into this before?
Here is what I'm trying to do :
This plugin prototype is fired after the user has opend a solution that
has a project called 'BakaraProject'
In this project I have a folder called 'Tada' and inside that -
another folder called 'ABCD'
I want to create a cs file using the AddFromTemplate function using the
CSharpAddClassWiz.vsz file
Any help is deeply appreciated - This things is on a deadline :(
Thanks in advance,
Phoenix_Always
ps:
Environment : VS 2003 (I know - I want to move to 2005 :)
Code snippets is as follows :
#region -- snip -- import list ---
using System;
using Microsoft.Office.Core;
using Extensibility;
using System.Runtime.InteropServices;
using EnvDTE;
using VSLangProj;
#endregion
#region -- snip -- exec command ---
public void Exec(string commandName, EnvDTE.vsCommandExecOption
executeOption, ref object varIn, ref object varOut, ref bool handled)
{
handled = false;
if(executeOption ==
EnvDTE.vsCommandExecOption.vsCommandExecOptionDoDefault)
{
if(commandName == "AddinFileAdditon.Connect.AddinFileAdditon")
{
AddFileToAProject();
handled = true;
return;
}
}
}
#endregion
#region -- snip -- Addfile to a project list ---
private void AddFileToAProject()
{
EnvDTE.Solution s = applicationObject.Solution;
EnvDTE.Project currentProject= null;
//This is a kluge - how do I get the project if its NOT the first
one?
for(int ProjectCount =1;ProjectCount<=s.Count;ProjectCount++)
{
currentProject= s.Item(ProjectCount);
if(currentProject.Name=="BakaraProject")
{
BakaraProject = (VSProject)s.Item(ProjectCount).Object;
EnvDTE.ProjectItems BakaraProjectItems =
BakaraProject.Project.ProjectItems;
EnvDTE.ProjectItem NewsItem = BakaraProjectItems.Item("Tada");
this.ABCD_FolderProjectItem = NewsItem.ProjectItems.Item("ABCD");
}
}
ProjectItem LinkFile =
GetProjectItem(ABCD_FolderProjectItem,"Link_MyOwn.cs");
if( LinkFile ==null)
{
try
{
string pathToTemplate =
System.IO.Path.Combine(this.BakaraProject.TemplatePath,"CSharpAddClassWiz.vsz");
LinkFile = ABCD_FolderProjectItem.ProjectItems.AddFromTemplate
(pathToTemplate ,"Link_MyOwn.cs");
ABCD_FolderProjectItem.ProjectItems.AddFromFile(LinkFile.Name);
}
catch(Exception e) {
string se = e.ToString();
se= string.Empty;
}
}
}
private VSProject BakaraProject = null;
private _DTE applicationObject;
private AddIn addInInstance;
private EnvDTE.ProjectItem ABCD_FolderProjectItem = null;
}
#endregion
Phoenix_Always - 20 Nov 2005 11:02 GMT
A quick update:
I can successfully add a cs file manually using the Project->Add Item
and creating the class. The problem happens
programatcally only. The ProgId is declared just above the class
defintion like so:
[GuidAttribute("9BF24471-1EF0-4B94-BF58-ABDD57F1FC41"),
ProgId("AddinFileAdditon.Connect")]
public class Connect : Object, Extensibility.IDTExtensibility2,
IDTCommandTarget
Will keep hunting -
Thanks,
Phoenix_Always