Hello,
I'm writing C# code and executing it using InstallUtilLib. dll from custom
action during an installation process. It works fine.
I've written some code to add an item (component) to Visual Studio .NET 2003
toolbox and I've got some serious problems with it.
Problem looks like this:
1) My code works if Visual Studio is already opened when my code executes.
2) My code works fine when executed outside of an installation project.
3) If my code is executed from an installation project and Visual Studio is
not opened, then ToolBox item is not added. I've added a "MessageBox " during
the process and I can confirm that devenv.exe *is* executed.
Here is a function used to get access to Visual Studio's process:
bool OpenVisualStudi oHandle(out EnvDTE.DTE dteObject)
{
// sprobuj uzyskac dostep do wczesniej otwartego okna Visual Studio .NET 2003
try
{
dteObject = (EnvDTE.DTE)
System.Runtime. InteropServices .Marshal.GetAct iveObject("Visu alStudio.DTE.7. 1");
}
catch
{
dteObject = null;
}
if (dteObject != null) return false;
// nie ma otwartego okna z Visual Studiem - otworz nowe
dteObject = (EnvDTE.DTE)
Microsoft.Visua lBasic.Interact ion.CreateObjec t("VisualStudio .DTE.7.1", "");
return true;
}
And here is the code:
void CreateComponent InVisualStudioT oolBox()
{
EnvDTE.DTE dteObject;
bool dteObjectCreate d = OpenVisualStudi oHandle(out dteObject);
if (dteObject == null) return;
try
{
EnvDTE.Window ToolBoxWnd =
dteObject.Windo ws.Item(EnvDTE. Constants.vsWin dowKindToolbox) ;
EnvDTE.ToolBoxT ab tlbTab = GetToolBoxTabBy Name(ToolBoxWnd , "Components ");
if (tlbTab != null)
{
// pokaz okno ToolBox (mozna dokonywac zmian tylko, jesli okno jest
widoczne)
ToolBoxWnd.Visi ble = true;
// wybierz zakladke "Components "
tlbTab.Activate ();
EnvDTE.ToolBoxI tems tlbItems = tlbTab.ToolBoxI tems;
// dopisz siebie do toolboxa
string DllFullPath =
System.Reflecti on.Assembly.Get ExecutingAssemb ly().Location;
tlbItems.Add("C odeCityReaderPo rt", DllFullPath,
EnvDTE.vsToolBo xItemFormat.vsT oolBoxItemForma tDotNETComponen t);
}
}
finally
{
// zamknij Visual Studio, jesli na poczatku je otworzyles
if (dteObjectCreat ed)
{
dteObject.Quit( );
}
}
}
--
SÅ‚awomir Piotrowski / Telsat GP
Rejestracja Czasu Pracy i Kontrola Dostępu
http://www.ewidencja-czasu-pracy.pl