473,386 Members | 1,754 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

adding Visual Studio's ToolBox item by code

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 OpenVisualStudioHandle(out EnvDTE.DTE dteObject)
{
// sprobuj uzyskac dostep do wczesniej otwartego okna Visual Studio .NET 2003
try
{
dteObject = (EnvDTE.DTE)
System.Runtime.InteropServices.Marshal.GetActiveOb ject("VisualStudio.DTE.7.1");
}
catch
{
dteObject = null;
}
if (dteObject != null) return false;
// nie ma otwartego okna z Visual Studiem - otworz nowe
dteObject = (EnvDTE.DTE)
Microsoft.VisualBasic.Interaction.CreateObject("Vi sualStudio.DTE.7.1", "");
return true;
}


And here is the code:

void CreateComponentInVisualStudioToolBox()
{
EnvDTE.DTE dteObject;
bool dteObjectCreated = OpenVisualStudioHandle(out dteObject);
if (dteObject == null) return;
try
{
EnvDTE.Window ToolBoxWnd =
dteObject.Windows.Item(EnvDTE.Constants.vsWindowKi ndToolbox);
EnvDTE.ToolBoxTab tlbTab = GetToolBoxTabByName(ToolBoxWnd, "Components");
if (tlbTab != null)
{
// pokaz okno ToolBox (mozna dokonywac zmian tylko, jesli okno jest
widoczne)
ToolBoxWnd.Visible = true;
// wybierz zakladke "Components"
tlbTab.Activate();
EnvDTE.ToolBoxItems tlbItems = tlbTab.ToolBoxItems;
// dopisz siebie do toolboxa
string DllFullPath =
System.Reflection.Assembly.GetExecutingAssembly(). Location;
tlbItems.Add("CodeCityReaderPort", DllFullPath,
EnvDTE.vsToolBoxItemFormat.vsToolBoxItemFormatDotN ETComponent);
}
}
finally
{
// zamknij Visual Studio, jesli na poczatku je otworzyles
if (dteObjectCreated)
{
dteObject.Quit();
}
}
}
--
SÅ‚awomir Piotrowski / Telsat GP
Rejestracja Czasu Pracy i Kontrola Dostępu
http://www.ewidencja-czasu-pracy.pl

Nov 1 '05 #1
5 2418
Hi,
Welcome to MSDN Newsgroup!

Based on the current situation, please help me to confirm some information
on your side:
1.What about your program, VS.NET Add-In or something else?

2. >>" My code works fine when executed outside of an installation project."
In this scenario, whether or not the VS2003 IDE is opened? If not, I want
to confirm how you run this code.

If you have any questions or concerns, please feel free to let me know.
I'm looing forward to you. :)

Best Regards,

Terry Fei[MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 2 '05 #2
> Hi,
Welcome to MSDN Newsgroup!
Thank you for the reply, answers inline.
Based on the current situation, please help me to confirm some information
on your side:
1.What about your program, VS.NET Add-In or something else?
My program (in fact it's a class library) is a .NET component. It can be
used with or without visual designer. I want to add it to Visual Studio's
component tab in the ToolBox.
2. >>" My code works fine when executed outside of an installation project."
In this scenario, whether or not the VS2003 IDE is opened?
Well... I thought I've checked both ways, but now it looks like it works
only if Visual Studio .NET is opened when my code is executed.
If not, I want to confirm how you run this code.


In order to launch separately I compile it as a console application, define
Main function that creates an "Installer" object and directly executes
CreateComponentInVisualStudioToolBox.

In case it matters - I'm testing the code under Polish version of Windows XP
Pro with Service Pack 2 and all current patches installed. I'm using an
account with local admin privs.

--
SÅ‚awomir Piotrowski / Telsat GP
Rejestracja Czasu Pracy i Kontrola Dostępu
http://www.ewidencja-czasu-pracy.pl

Nov 4 '05 #3
Hi,

Based on your code, it will add items to an existed VS .Net Instance, so
it's necessary to make VS .NET opened for the code working. (This behavior
is as expected.)
If we want to add the items to the VS.NET 2003 IDE persistently after
installing once, the general convention is using a VS.NET add-in to achieve
the goal.

I browse some articles and hope it's helpful for you.
Title: Visual Studio .NET 2003 Automation Samples (including some add-in
samples)
URL:http://www.microsoft.com/downloads/d...FF9C915-30E5-4
30E-95B3-621DCCD25150&displaylang=en

Title: Deploying Controls to VS.NET Toolbox Programatically
URL: http://www.codeproject.com/dotnet/AddItemToToolBar.asp
If you have any questions or concerns, please feel free to let me know.
Thanks for your understanding.

Best Regards,

Terry Fei[MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 8 '05 #4
Hello,
I've changed my code to follow code from codeproject and it works fine now.
Thanks, Terry Fei.
--
SÅ‚awomir Piotrowski / Telsat GP
Rejestracja Czasu Pracy i Kontrola Dostępu
http://www.ewidencja-czasu-pracy.pl

Nov 9 '05 #5
Hi Slawomir,

I am glad to know that the problem is resolved now. It's really been a
pleasure working
with you.

Best Regards,

Terry Fei[MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 9 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Brett | last post by:
For some reason in my project, I am unable to add a new web user control in Visual Studio. Normally I would right somewhere in my web app and "Add Web User Control", but when I do this it creates...
1
by: Dale | last post by:
When I want to add item to toolbox, the IDE will hang. I don't know why. I checked the Event Log, I found two error messages. 1. Detection of product '{E05F0409-0E9A-48A1-AC04-E35E3033604A}',...
1
by: Javier Ros | last post by:
Hi guys!, I´m tring to install my own component in the Visual Studio .Net ToolBox, I have tried with this code: // Create a EnvDTE object. System.Type t =...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
5
by: Slawomir Piotrowski | last post by:
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...
4
by: Nadav Popplewell | last post by:
Hi everybody, I've install Visual studio Team Edition for Testers on my computers, And I can't seem to find how to show the toolbox. The documenation says there should be a 'Toolbox' menuitem...
3
by: Tin Gherdanarra | last post by:
A colleague gave me a project where there was a /designer/ window for database connectivity (drag&drop from the toolbox), but I can't find out how to get a /designer/ window in my own project....
1
by: Jedufa | last post by:
following of thread: "Adding namespaces to code behind automatically" Hello, I had quite the same problem and got further in the right direction with your suggestions, thanks. Nevertheless, I...
4
by: Steve B. | last post by:
Hi As we ship some controls with one of our application that targets web designers, we want to add items in the toolbox of the two products. With VS 2005, it is quite easy, but what about this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.