Easy way to add large numbers of existing source files to project?

A

Adam Clauss

I have a folder containing many subfolders (and subfolders and....) all containing various .cs files. Is there any "easy" way to
get them all added to the solution. Preferable would be that the folders are actually created in the Solution Explorer so that I
can find things easily.

Its easy to select multiple files out of a single folder, but not recursively into subfolders.

Any ideas?
 
C

clintonG

Isn't that what macros are supposed to help get done? Have you tried?

--
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software Development
Wauwatosa, Milwaukee County, Wisconsin USA
NET csgallagher@ REMOVETHISTEXT metromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/


Adam Clauss said:
I have a folder containing many subfolders (and subfolders and....)
all containing various .cs files. Is there any "easy" way to
get them all added to the solution. Preferable would be that the
folders are actually created in the Solution Explorer so that I
 
A

Adam Clauss

Perhaps, but I was wondering if there was some way, already built-in maybe, that would save me the time as I've never done a macro
for VS.
 
C

clintonG

The easy way *is* with a macro. There's probably a macro that
somebody has built already and there's lots of samples that can
be modified.

Google: "visual studio"+"macro"

If its only for one solution it may not be timely to do so but
otherwise you can look at it as an oppontunity to finally learn
how to do something useful like recursing a directory of files.
I've got to take on this task myself someday so try to understand
I'm not talking down to you.

You might also consider backing up the .sln file and using C# and
the framework to modify the .sln file directly but you'll still have to
recurse the directories and subdirectories. Study this snippet of
a .sln file and note that once the project is created all of the CLIDs
are identical throughout the entire .sln file. All you'd have to do is
write
a template and fill in the blanks using values from your recurser.

Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "315C11",
"http://localhost/70315QUE/315C11/315C11.csproj
", " {2F7BB741-BEA0-4243-937E-8C69FBF71649}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject

Isn't being a real software developer exciting? :)

--
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software Development
Wauwatosa, Milwaukee County, Wisconsin USA
NET csgallagher@ REMOVETHISTEXT metromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/




Adam Clauss said:
Perhaps, but I was wondering if there was some way, already built-in
maybe, that would save me the time as I've never done a macro
message news:%[email protected]...
 
A

Adam Clauss

No... heh the macro wasn't the easy way. And I cannot believe I did not think about this. Just... drag the folder in. Duh...

Before I figured out the dragging method, I did start looking at a macro, and it looks like there is one
(ProjectItem.AddFromDirectory()).

I also may have discovered a bug in VS. In both using that Macro and dragging the folders into the project from explorer, if I only
drug the root folder, and drug it so that it would be a top level folder in the project structure - nothign except the top folder
itself got added!

All of the files got copied over into the solution directory, as I expected - but none of them were actually in the project. The
top folder got created in the project, but it was empty.
 
C

clintonG

I want to share that dumb feeling not discussing drag and drop
(almost) but I wasn't all that surprised to learn the dragged folder
remained empty.

The snippet I showed was pulled from a .sln file. If dragging were to
resolve this issue the contents of the .sln file would have to be
modified
including the reference to what I may have mistakenly referred to as
a CLSID Key [1].

What happened running the ProjectItem.AddFromDirectory macro?

--
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software Development
Wauwatosa, Milwaukee County, Wisconsin USA
NET csgallagher@ REMOVETHISTEXT metromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/

[1]
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/htm/reg_6vjt.asp



Adam Clauss said:
No... heh the macro wasn't the easy way. And I cannot believe I did
not think about this. Just... drag the folder in. Duh...
Before I figured out the dragging method, I did start looking at a
macro, and it looks like there is one
(ProjectItem.AddFromDirectory()).

I also may have discovered a bug in VS. In both using that Macro and
dragging the folders into the project from explorer, if I only
drug the root folder, and drug it so that it would be a top level
folder in the project structure - nothign except the top folder
itself got added!

All of the files got copied over into the solution directory, as I
expected - but none of them were actually in the project. The
top folder got created in the project, but it was empty.
message news:%[email protected]...
 
A

Adam Clauss

Sorry - I forgot to mention what happened with the macro. It depended on how I ran it - just like it depended on how I dragged it
in.

If I ran it such that:
myproject.ProjectItems.AddFromDirectory(rootFolder)

Then it would do the exact same thing - copy all the actual files over and create and empty root folder in the project.

If I instead created the root folder manually in the project, and then ran it as:
myproject.ProjectItems("rootfolder").ProjectItems.AddFromDirectory(rootFolder)

then it worked fine. Notice - I added the SAME root folder. So I would get an 'extra' folder layer of the root.
Ex:

Root
| ----Root
| ----Sub1
| ----Sub2
.... etc.

To get it to work via drag and drop, I created the root folder manually, and then selected all the subfolders (rather than the root
folder) and dragged them into the project (under the folder I manually created). This bypassed having the extra layer problem, but
still is kind of odd that I had to create the first level manually.
--
Adam Clauss
(e-mail address removed)
clintonG said:
I want to share that dumb feeling not discussing drag and drop
(almost) but I wasn't all that surprised to learn the dragged folder
remained empty.

The snippet I showed was pulled from a .sln file. If dragging were to
resolve this issue the contents of the .sln file would have to be
modified
including the reference to what I may have mistakenly referred to as
a CLSID Key [1].

What happened running the ProjectItem.AddFromDirectory macro?

--
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software Development
Wauwatosa, Milwaukee County, Wisconsin USA
NET csgallagher@ REMOVETHISTEXT metromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/

[1]
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/htm/reg_6vjt.asp



Adam Clauss said:
No... heh the macro wasn't the easy way. And I cannot believe I did
not think about this. Just... drag the folder in. Duh...
Before I figured out the dragging method, I did start looking at a
macro, and it looks like there is one
(ProjectItem.AddFromDirectory()).

I also may have discovered a bug in VS. In both using that Macro and
dragging the folders into the project from explorer, if I only
drug the root folder, and drug it so that it would be a top level
folder in the project structure - nothign except the top folder
itself got added!

All of the files got copied over into the solution directory, as I
expected - but none of them were actually in the project. The
top folder got created in the project, but it was empty.
message news:%[email protected]...
 
C

clintonG

Wel at least working through and documenting here will help
others achieve the same success. Good job.


--
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software Development
Wauwatosa, Milwaukee County, Wisconsin USA
NET csgallagher@ REMOVETHISTEXT metromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/



Adam Clauss said:
Sorry - I forgot to mention what happened with the macro. It depended
on how I ran it - just like it depended on how I dragged it
in.

If I ran it such that:
myproject.ProjectItems.AddFromDirectory(rootFolder)

Then it would do the exact same thing - copy all the actual files over
and create and empty root folder in the project.
If I instead created the root folder manually in the project, and then ran it as:
myproject.ProjectItems("rootfolder").ProjectItems.AddFromDirectory(rootF
older)

then it worked fine. Notice - I added the SAME root folder. So I
would get an 'extra' folder layer of the root.
Ex:

Root
| ----Root
| ----Sub1
| ----Sub2
... etc.

To get it to work via drag and drop, I created the root folder
manually, and then selected all the subfolders (rather than the root
folder) and dragged them into the project (under the folder I manually
created). This bypassed having the extra layer problem, but
still is kind of odd that I had to create the first level manually.
message news:[email protected]...
I want to share that dumb feeling not discussing drag and drop
(almost) but I wasn't all that surprised to learn the dragged folder
remained empty.

The snippet I showed was pulled from a .sln file. If dragging were to
resolve this issue the contents of the .sln file would have to be
modified
including the reference to what I may have mistakenly referred to as
a CLSID Key [1].

What happened running the ProjectItem.AddFromDirectory macro?

--
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software Development
Wauwatosa, Milwaukee County, Wisconsin USA
NET csgallagher@ REMOVETHISTEXT metromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/

[1]
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/htm/reg_6vjt.asp



Adam Clauss said:
No... heh the macro wasn't the easy way. And I cannot believe I
did
not think about this. Just... drag the folder in. Duh...
Before I figured out the dragging method, I did start looking at a
macro, and it looks like there is one
(ProjectItem.AddFromDirectory()).

I also may have discovered a bug in VS. In both using that Macro
and
dragging the folders into the project from explorer, if I only
drug the root folder, and drug it so that it would be a top level
folder in the project structure - nothign except the top folder
itself got added!

All of the files got copied over into the solution directory, as I
expected - but none of them were actually in the project. The
top folder got created in the project, but it was empty.
in
message news:%[email protected]...
The easy way *is* with a macro. There's probably a macro that
somebody has built already and there's lots of samples that can
be modified.

Google: "visual studio"+"macro"

If its only for one solution it may not be timely to do so but
otherwise you can look at it as an oppontunity to finally learn
how to do something useful like recursing a directory of files.
I've got to take on this task myself someday so try to understand
I'm not talking down to you.

You might also consider backing up the .sln file and using C# and
the framework to modify the .sln file directly but you'll still
have
to
recurse the directories and subdirectories. Study this snippet of
a .sln file and note that once the project is created all of the CLIDs
are identical throughout the entire .sln file. All you'd have to
do
is
write
a template and fill in the blanks using values from your recurser.

Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "315C11",
"http://localhost/70315QUE/315C11/315C11.csproj
", " {2F7BB741-BEA0-4243-937E-8C69FBF71649}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject

Isn't being a real software developer exciting? :)

--
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software Development
Wauwatosa, Milwaukee County, Wisconsin USA
NET csgallagher@ REMOVETHISTEXT metromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/




Perhaps, but I was wondering if there was some way, already built-in
maybe, that would save me the time as I've never done a macro
for VS.
wrote
in
message Isn't that what macros are supposed to help get done? Have you
tried?

--
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software
Development
Wauwatosa, Milwaukee County, Wisconsin USA
NET csgallagher@ REMOVETHISTEXT metromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/


I have a folder containing many subfolders (and subfolders
and....)
all containing various .cs files. Is there any "easy" way to
get them all added to the solution. Preferable would be
that
the
folders are actually created in the Solution Explorer so that I
can find things easily.

Its easy to select multiple files out of a single folder,
but
not
recursively into subfolders.

Any ideas?
 
A

Adrian Vinca [MSFT]

You could use the button "Show All Files" from the Solution Explorer pane
this way:

Step 1: First of all copy your files into the project's folder (having the
folder structure you want).
Step 2: Click on a project in the Solution Explorer. Click on the "Show All
Files" button from the Solution Explorer pane. This will cause that all the
files will be displayed in the Solution Explorer pane (including the
folders)
Step 3: You can multi-select the files you want to include; right click on
the selection and select from the context menu "Include In Project". Be
careful not to include the "bin" or "obj" folders.

You will have to execute these steps for each project from your solution.

Hope this is is helpful.

Regards,
Adrian Vinca [MSFT], Developer Division
--------------------------------------------------------------------
This reply is provided "AS IS", without warranty (express or implied).

Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.

I have a folder containing many subfolders (and subfolders and....) all
containing various .cs files. Is there any "easy" way to
get them all added to the solution. Preferable would be that the folders
are actually created in the Solution Explorer so that I
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top