Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / Extensibility / January 2006

Tip: Looking for answers? Try searching our database.

Default C# Add-In code vs. default Add-In VB.NET code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
None - 31 Dec 2005 17:14 GMT
I'm a C# programmer and I'm reading "Writing Add-ins for Visual Studio
.NET" (which is written in VB.NET).  I don't know VB.NET, but I can
generally read through VB.NET code and understand it, but I'm more
comfortable in C#.

First off, I generated a default VS.NET Add-In using the VB.NET Add-In
Wizard as well as another VS.NET Add-In using the C# Add-In Wizard and I
noticed some discrepancies:

1) Why does the default VB.NET Add-In code have:

<Assembly: ComVisible(True)>
<Assembly: CLSCompliant(True)>

...in the assembly, but not the C# version?  When I compile the C#
version with:
    [assembly: CLSCompliant(true)]
...in AssemblyInfo.cs, I get several errors about several extensibility
classes being non-CLS compliant (so how does the VB.NET version compile?).

2) Why does the default VB.NET Add-In have:
    Dim applicationObject As EnvDTE.DTE
yet the C# version is:
    _DTE applicationObject; (_DTE is actually EnvDTE._DTE)

3) What's the difference between EnvDTE.DTE and EnvDTE._DTE?

4) Why the discrepancy?  Why does VB.NET use EnvDTE.DTE and C# uses
EnvDTE._DTE?

Next, in my C# project, I changed applicationObject from a _DTE to
EnvDTE.DTE (to match the VB.NET code).

5) Using EnvDTE.DTE applicationObject in the C# version (as opposed to
_DTE applicationObject), why does the VB.NET version have:
    applicationObject.CommandBars.Item["Tools"]
...yet in C#, applicationObject.CommandBars does not have a member Item?
 Aren't they both using the same DLL (and are both a EnvDTE.DTE)?  If
so, how can a DLL have conditional code (#ifdef VB.NET -> expose Items
method???)

6) In a lot of the code from "Writing Add-ins for Visual Studio .NET",
there is a function called MsgBox().  The VS online help says it's in
the Microsoft.VisualBasic namespace and is within the
Microsoft.VisualBasic.dll assembly.
    A) Why isn't that dll added to the VB project's reference section?
    B) I added Microsoft.VisualBasic.dll to my C# project, yet
Microsoft.VisualBasic.MsgBox() does not exist.  Again, is there
conditional code?

I opened Microsoft.VisualBasic.dll in Reflector but MsgBox doesn't
appear within the Microsoft.VisualBasic.dll, so where is MsgBox coming
from?  I know I can just use System.Windows.Forms.MessageBox.Show() in
its place but now I'm curious (and baffled) as to where MsgBox() is
coming from.

TIA,

anon
Carlos J. Quintero [VB MVP] - 02 Jan 2006 11:39 GMT
Hi,

> 1) Why does the default VB.NET Add-In code have:
>
> <Assembly: ComVisible(True)>

VS.NET 2002/2003 add-in assemblies are required to be registered as COM
(ActiveX) components using COM Interop (regasm.exe, etc.), so they need to
have that attribute and value. This is no longer required for VS 2005
add-ins.

> <Assembly: CLSCompliant(True)>
>
[quoted text clipped - 3 lines]
> ...in AssemblyInfo.cs, I get several errors about several extensibility
> classes being non-CLS compliant (so how does the VB.NET version compile?).

This attribute is not important and you can ignore it. In VS 2005, even the
VB.NET version causes that non-CLS compliant errors.

> 2) Why does the default VB.NET Add-In have:
>
> Dim applicationObject As EnvDTE.DTE yet the C# version is:
> _DTE applicationObject; (_DTE is actually EnvDTE._DTE)
>
> 3) What's the difference between EnvDTE.DTE and EnvDTE._DTE?

This is answered in the book "Inside Microsoft Visual Studio .NET 2003" but
I don´t remember the answer and I don´t have it here, but I think that _DTE
is an interface and DTE is a class (surely implementing the _DTE interface).

> 4) Why the discrepancy?  Why does VB.NET use EnvDTE.DTE and C# uses
> EnvDTE._DTE?

All these discrepancies are because they seem to be written by different
persons, just my guess.

> 5) Using EnvDTE.DTE applicationObject in the C# version (as opposed to
> _DTE applicationObject), why does the VB.NET version have:
> applicationObject.CommandBars.Item["Tools"]

> ...yet in C#, applicationObject.CommandBars does not have a member Item?
> Aren't they both using the same DLL (and are both a EnvDTE.DTE)?  If so,
> how can a DLL have conditional code (#ifdef VB.NET -> expose Items
> method???)

"Item" is a default property (in VB.NET terms) or an indexer (in C# terms)
and therefore is omited in C# and optional in VB.NET. VB.NET also works if
you remove it.

> 6) In a lot of the code from "Writing Add-ins for Visual Studio .NET",
> there is a function called MsgBox().  The VS online help says it's in the
> Microsoft.VisualBasic namespace and is within the
> Microsoft.VisualBasic.dll assembly.
> A) Why isn't that dll added to the VB project's reference section?

VB.NET projects use a kind of hidden reference implicitly, in the same way
that the reference to mscorlib.

> B) I added Microsoft.VisualBasic.dll to my C# project, yet
> Microsoft.VisualBasic.MsgBox() does not exist.  Again, is there
[quoted text clipped - 3 lines]
> know I can just use System.Windows.Forms.MessageBox.Show() in its place
> but now I'm curious (and baffled) as to where MsgBox() is coming from.

MsgBox is defined in the assembly Microsoft.VisualBasic.dll, namespace
Microsoft.VisualBasic, module Interaction. Since the module name is not
required in VB.NET and the Microsoft.VisualBasic.dll assembly is
automatically added to VB.NET projects, MsgBox just works.

Signature

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio 2005, Visual Studio .NET,
VB6, VB5 and VBA
You can code, design and document much faster in VB.NET, C#, C++ or VJ#
Free resources for add-in developers:
http://www.mztools.com


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.