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 / IDE / March 2008

Tip: Looking for answers? Try searching our database.

Project-specific add-in?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bob Altman - 18 Mar 2008 23:16 GMT
Hi all,

I have a VS 2005 project (actually, a "solution" containing a bunch of
"projects") in which I want to implement some custom logic for setting assembly
versions.  Specifically, I define some constants in one of my assemblies that
identify the product version.  I want to use those constants to set the assembly
version on any assmblies that change during a release cycle.  So, if I look at
an assembly and see that its assembly (and file) version is 3.2.15.0, I know
that that assembly was modified in version "3.2 beta 15" of my product.

I can easily enough use the Macro IDE to implement this custom logic by wiring
up events that fire when I add, remove, or save documents in a project.  That
macro responds to the events by using reflection to dig out the version info and
updates AssemblyInfo.vb if necessary.  But distributing that macro code to other
members of my team is seriously non-trivial.

I'm wondering if I a better option would be to write an add-in that implements
this behavior.  Then the other members of my team could presumably just install
my add-in.  I've never (yet) dug into what it takes to write an add-in or, for
that matter, what I can do with an add-in, but I gather that it's pretty much
the same claptrap as a macro, just wired into the IDE differently.

Can someone point me in the right direction here?  Am I on the right track?

TIA - Bob
Wen Yuan Wang [MSFT] - 19 Mar 2008 12:04 GMT
Hello Bob,

In my opinion, Add-in should be a good solution in your scenario. It's easy
for deployment. Your developer team can install it when they need to touch
your project. And they can disable it by "Tools|Add-in manager" if they
works on other projects. Moreover, it's easy for them to uninstall the
add-in if necessary.

As you see, add-in development is pretty much similar to macro. You can
register event handler in OnConnection() method. Then you can check
solution name, update AssemblyInfo.vb file in related event.
For example:

private DocumentEvents _appliationDocumentEvents;
private ProjectItemsEvents _applicationProjectItemEvents;

public void OnConnection(...)
{
_applicationObject = (DTE2)application;
_addInInstance = (AddIn)addInInst;
_appliationDocumentEvents =
_applicationObject.Events.get_DocumentEvents(null);
_applicationProjectItemEvents =
_applicationObject.Events.GetObject("ProjectItemsEvents") as
ProjectItemsEvents;

           _appliationDocumentEvents.DocumentSaved += new
_dispDocumentEvents_DocumentSavedEventHandler(Connect_DocumentSaved);
           _applicationProjectItemEvents.ItemAdded += new
_dispProjectItemsEvents_ItemAddedEventHandler(SolutionItemsEvents_ItemAdded)
;
          _applicationProjectItemEvents.ItemRemoved += new
_dispProjectItemsEvents_ItemRemovedEventHandler(_applicationProjectItemEvent
s_ItemRemoved);
}

Hope this helps. Please feel free to let us know if you have any more
concern. We are glad to assist you.
Have a great day,
Best regards,
Wen Yuan

Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Bob Altman - 19 Mar 2008 16:24 GMT
> In my opinion, Add-in should be a good solution in your scenario. It's
> easy
[quoted text clipped - 6 lines]
> register event handler in OnConnection() method. Then you can check
> solution name, update AssemblyInfo.vb file in related event.

Thanks Wen Yuan!  That's just the validation I was looking for.  The MSDN
documentation on this subject is pretty weak, but I've seen lots of good
articles over the years in MSDN magazine and CoDe magazine on the subject
(both of which have searchable archives online), so I shouldn't have any
problem coming up to speed on writing an add-in.

Bob
Peter Macej - 19 Mar 2008 17:45 GMT
Here is a list of some sites that may be of interest to you:
http://www.helixoft.com/blog/archives/28

I especially suggest this URL from the list:
http://www.mztools.com/resources_vsnet_addins.aspx
This is the most complete repository of add-in resources I'm aware of.

Signature

Peter Macej
Helixoft - http://www.helixoft.com
VSdocman - Commenter and generator of class documentation for C#, VB
.NET and ASP .NET code

Wen Yuan Wang [MSFT] - 20 Mar 2008 08:22 GMT
You are welcome, Bob.

Tip: You may face an issue that, after some time a Visual Studio .NET
add-in no longer receives events. This is because when the procedure exits
the variable is no longer used and it will be garbage collected.  To
resolve this issue, you must declare the solutionEvents variable at class
level, not at procedure level.

http://support.microsoft.com/kb/555430/en-us
[PRB: Visual Studio .NET events being disconnected from add-in.]

Have a great day. Feel free to let us know if you face any further issue.
We are glad to assist you.

Have a great day,
Best regards,
Wen Yuan

Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Bob Altman - 21 Mar 2008 19:16 GMT
As you will recall, my original question asked about how to extend the IDE for
just one particular solution.  It turns out that VS supports a thing called a
"solution add-in", in which VS stores info in the sln file that instructs the
IDE to load a particular add-in when that solution is opened.  This is
documented here:

http://msdn2.microsoft.com/en-us/library/ms165621(VS.80).aspx

There is just one minor problem... That help topic is misleading, incomplete,
and in some places just plain wrong.  I burned an MSDN tech support case and
worked out how to actually implement a solution add-in with the support
engineer.

I posted this same response over in the microsoft.public.dotnet.languages.vb NG
(since that's where I started a long thread on this subject).  Here, for the
entertainment and edification of anyone who might be interested, is how to wire
up a "solution add-in":

To begin, create a new Add-in project.  Make sure you tell the wizard not to
automatically load your add-in.

Now, in order to work, this add-in must be registered with COM.  This is because
this add-in is going to call the AddIns.Add method, which requires the target of
the method to be an add-in registered with COM.  The "easy" way to register your
assembly with COM is to check the "Register for COM interop" check box on the
Compile tab of the project properties.  However, this requires that you run with
admin privileges, because VS will try to fiddle with the registry every time you
build or clean your project.  We're going to set things up so that we can
manually register the assembly (with admin privileges) but otherwise we can
build and test without admin privileges.

In order to register your assembly with COM (via regasm) you need to strong-name
sign it.  The process to do this is well documented.

You also need to hard-code the assembly version so that the version number
registered with COM agrees with the version number you're actually deploying and
running.

In AssemblyInfo.vb (sorry C# folks, you need to translate this yourselves ;-)
 ' Hard-code the assembly version because
 ' we are going to strong-name sign the assembly
 <Assembly: AssemblyVersion("1.0.0.0")>

 ' Specify a TypeLib GUID to expose this assembly to COM
 <Assembly: GuidAttribute("your TypeLib GUID here")>

In Connect.vb, add the following lines before the class declaration:
 <ClassInterface(ClassInterfaceType.None)> _
 <Guid("your class GUID here")> _
 <ComVisible(True)> _

This magic provides the metadata that regasm uses to expose your class to COM.
(Note that the two GUID values above must be different!)  After you've built
your assembly, you need to run regasm as administrator.  Right-click on the
shortcut to the VS 2005 command prompt and select "Run As..." and run the
command prompt as administrator.  Then type in:

   regasm /codebase <path to your dll>

Now, in the OnConnection routine, we're going to add code that recognizes when
the user selects our add-in in the add-in manager.  When that happens then we're
going to persist the selection in the current solution (.sln file).  Thereafter,
whenever the user opens this solution, our add-in will automatically load and
run.

 Public Sub OnConnection(...) _
 Implements IDTExtensibility2.OnConnection
   _applicationObject = CType(application, DTE2)
   _addInInstance = CType(addInInst, AddIn)

   ' If the user enables this add-in via the Add-In Manager then
   ' add this add-in to the solution's set of "registered" add-ins
   If connectMode = ext_ConnectMode.ext_cm_AfterStartup Then
     With _addInInstance
       _applicationObject.Solution.AddIns.Add(
               .ProgID, .Description, .Name, .Connected)
     End With
   End If
 End Sub

(Note that you probably need to add error handling code.  For example, the user
may select the add-in without first loading a solution.)

Finally, despite what the documentation says, you need to retain the ".AddIn"
files so that your add-in shows up in the Add-In Manager.

Good luck...

Robert Altman
Wen Yuan Wang [MSFT] - 25 Mar 2008 07:30 GMT
Hello Robert,

Thanks for sharing solution with us.

Have a great day,
Best regards,
Wen Yuan

Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

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.