By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,218 Members | 1,195 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,218 IT Pros & Developers. It's quick & easy.

Visual Basic .Net IDE Add-In that adds a Web Reference or Normal Reference to Current Project

P: n/a
I already have a working Visual Basic .Net Add-in. It loads when the
IDE loads and there is a button to run it from the tools menu. It
also creates a tool window that can be docked anywhere on the screen.
It does a few things with web services, but my problem is that I need
the add-in to create a Web Reference to a project that is loaded in
the IDE. I found this code but I think it's only for Macros (I'm not
familiar with VB macros):

Imports EnvDTE
Imports System.Diagnostics
Imports VSLangProj

Public Module AddWebRefernceMacro
Sub AddWebReference()
Dim applicationObjectWeb As EnvDTE.DTE
' This example assumes that the first project in the
solution is
' either a Visual Basic or C# project.

Dim aVSProject As VSProject =
CType(applicationObjectWeb.Solution.Projects.Item( 0).Object,

If (aVSProject.WebReferencesFolder Is Nothing) Then
Dim newFolder As ProjectItem
newFolder = aVSProject.CreateWebReferencesFolder()
' The new project item is a folder.
newFolder =
' The new name of the folder appears in Solution
newFolder.Name = "Web References"
' The ProjectItems collection for the folder is not
End If

Catch ex As System.Exception
MsgBox("error adding web reference, message: " &
ex.Message, MsgBoxStyle.Critical, "error with adding web reference")

End Try

End Sub

End Module

Can this code be used in my VB.Net add-in code or does it have to be a
macro? I have tried using this code just as a macro and just in the
Add-In and I always get the same error: Object reference not set to an
instance of an object.

Thanks in advance.
Nov 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.