Project Iteration (bug or missing feature?)

Apr 13, 2011 at 4:31 PM

Given a solution with a projects and Solution Folders, when I use the "projects:" drive provider and execute the following

 

>cd projects:
>get-childitem -r

 

StudioShell starts iterating through all the solution folders, projects and their contents, including all the CodeModel children.  Not only does this take some time but its not what I want to do.  

I am trying to take a newly added project, iterate through all the other projects in the file and perform some Reference manipulation on it, either delete a reference or add a reference.  When our solutions have > 100 Projects in them doing this manually is quite a pain and being able to use powershell to automate this would be very helpful.

Here is an example of what I am trying to do using psudocode because I can't/don't know how right now.

 

>$newProj = (get-project -name MyNewProject)
>get-childitem -r -filter IsProjectFile | % { if $_ -ne $newProj) { $_.AddReference($newProj) }}

 

Is this something that can be added/changed?

Thanks

-mark

Coordinator
Apr 15, 2011 at 8:31 PM

Hey Mark;

Apologies for the delay, I've been swamped.

So, if I understand you correctly, you want to add (or remove) a project reference to a group of projects?  You are correct that recursively searching under the projects: drive will take a long time, since the recursion dives into the code model and project properties as well.

This is some sample code for adding references between projects; relatively untested, but I do this kind of thing all the time.

> $newProject = new-project -name MyNewProject;
> cd projects:
> dir | where { 
    #skip the new project and miscellaneous files collection
     $_.Name -ne $newProject.Name -and $_.Name -notmatch "misc"
} | foreach {
     pushd $_.PSPath;
     # add a reference to the new project
     if( test-path ./References ) {
new-item -path ./References -type project -name $newProject.Name; }
popd; }

Also, I just noted that the examples for the new-item documentation for the references node are wrong - they're actually copies of the breakpoint examples.  I'll add a ticket to make sure this gets fixed.

If you still have trouble, follow up in this discussion.

Thanks,

jim