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 / February 2006

Tip: Looking for answers? Try searching our database.

Excluding a file from a project

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
None - 23 Jan 2006 05:17 GMT
I'm creating an AddIn (using VS2005) and need to be able to exclude
files that exist in the solution and would appreciate some example code
demonstrating this or some suggestions on what to do.

Here's what I have so far:  A Project object (obtained from
DTE.Solution.Projects) has a project.ProjectItems.AddFromFile() method
but there isn't a project.ProjectItems.RemoveFile() method.  I've
searched the DTE, Solution, Project, and ProjectItem classes and if one
of these classes has the ability to remove a file, I've missed it.

I'd _MUCH_ prefer a programmatic way of excluding a file, but I'd settle
 using dte2.ExecuteCommand(), but I'm not getting the syntax with
ExecuteCommand() correct.  So far, I've tried:

// the full path to the source file
ExecuteCommand("Project.ExcludeFromProject", @"C:\MyPrj\MySource.cs");

// just the name of the source file
ExecuteCommand("Project.ExcludeFromProject", "MySource.cs");

// and "" and null
ExecuteCommand("Project.ExcludeFromProject", "");
ExecuteCommand("Project.ExcludeFromProject", null);

But all four throw a COMException
"Error HRESULT E_FAIL has been returned from a call to a COM component."

ErrorCode = -2147467259;

I looked up this error with errlook.exe and it reported that -2147467259
is "Unspecified error".  Cool.

So, if anyone has any experience with this or ant suggestions on what to
do, I'd appreciate it.

TIA.

-Jay
Carlos J. Quintero [VB MVP] - 23 Jan 2006 10:41 GMT
Hi Jay,

AFAIK, there is no way to exclude a file using an addin apart from using
DTE.ExecuteCommand("Project.ExcludeFromProject"). I have not tested it, but
first you should select the file in the Solution explorer (via
UIHierarchyItems) and the execute the command.

Also, maybe the VSIP SDK or VS 2005 SDK provides a service to do that, but I
am not familiar with this yet.

Signature

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com

> I'm creating an AddIn (using VS2005) and need to be able to exclude files
> that exist in the solution and would appreciate some example code
[quoted text clipped - 34 lines]
>
> -Jay
None - 28 Jan 2006 19:00 GMT
> Hi Jay,
>
[quoted text clipped - 5 lines]
> Also, maybe the VSIP SDK or VS 2005 SDK provides a service to do that, but I
> am not familiar with this yet.

Hmm, actually, the EnvDTE.ProjectItem class has a public Remove() method
and calling this method removes the item from the project.  I don't know
how I missed it because it's pretty obvious.  Is this method new to
VS2005?  I was working in VS2003.  Maybe it wasn't in VS2003's
definition of the EnvDTE.ProjectItem class.

Jay
Dustin Campbell - 30 Jan 2006 02:36 GMT
> Hmm, actually, the EnvDTE.ProjectItem class has a public Remove()
> method and calling this method removes the item from the project.  I
> don't know how I missed it because it's pretty obvious.  Is this
> method new to VS2005?  I was working in VS2003.  Maybe it wasn't in
> VS2003's definition of the EnvDTE.ProjectItem class.

Bringing up the Visual Studio 2003 help reveals that EnvDTE.ProjectItem.Remove()
does exist in 2003.

-----
Best Regards,
Dustin Campbell
Developer Express In
Carlos J. Quintero [VB MVP] - 01 Feb 2006 09:13 GMT
Hi Jay,

You are right, I'm sorry, I totally missed that method, maybe because I was
expecting a "Exclude" method, not a "Remove" method.

Signature

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com

> Hmm, actually, the EnvDTE.ProjectItem class has a public Remove() method
> and calling this method removes the item from the project.  I don't know
[quoted text clipped - 3 lines]
>
> Jay

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.