Visual Studio Development Bookmark and Share   
 index > Visual Studio Guidance Automation Toolkit > Programatically moving Projects within a Solution
 

Programatically moving Projects within a Solution

Currently in my GAT Guidance Package, I have a solution template that includes several projects. Currently, the projects all unfold into project folders at the root of the soution folder, and appear under the root of the solution file in the VS solution explorer:

..\SolutionFolder\MySolution.sln

..\SolutionFolder\Project1\Project1.csproj

..\SolutionFolder\Project2\Project2.csproj

What I'd like to have happen is that when the solution unfolds, I'd like to have the projects in my solution divdided into solution folders. However, I do NOT wnat this to be reflected in the file system, and therefore do not use the <SolutionFolder> element in my solution .vstemplate file.

The approach that I am workin with right now is:

1. I have an Action called "CreateSolutionFolderAction", which I use to programatically create the solution folder(s) I need.

2. I have another action called "MoveProjectAction", which takes a SourceProject (and EnvDTE.Project) and a DestinationFolder (an EnvDTE80.SolutionFolder).

The problem is that I cannot figure out how to move the project in the MoveProjectAction.Execute() method. I have tried using:

string projectFile = sourceProject.FullName;

mySolution.Remove(sourceProject); //mySolution is an EnvDTE80.Solution2

destinationFolder.AddFromFile(projectFile);

This works, but has the undesiredable side-effects of destroying the references that are "by project", and changing the solution startup project.

Is there another way to move projects around within a solution that I am not aware of?

Dave803796  Thursday, May 24, 2007 2:20 PM

Hi Dave,

Unfortunately there is no clean or easy way to do this. One would be the one you're using but previously you would have to iterate through the list of references and save them in order to be able to re-add them later.

An alternative that should keep the project references is to: cut the project from the source folder and paste it into the target folder, you would need to control the currently selected item in the solution explorer, make it over a Project, execute the Cut command, then move to the target folder and execute the Paste command. It's really ugly I know but it will work and will save the references.

HTH,

-Victor.

vga  Friday, June 01, 2007 4:31 PM

Hi Dave,

Unfortunately there is no clean or easy way to do this. One would be the one you're using but previously you would have to iterate through the list of references and save them in order to be able to re-add them later.

An alternative that should keep the project references is to: cut the project from the source folder and paste it into the target folder, you would need to control the currently selected item in the solution explorer, make it over a Project, execute the Cut command, then move to the target folder and execute the Paste command. It's really ugly I know but it will work and will save the references.

HTH,

-Victor.

vga  Friday, June 01, 2007 4:31 PM

You can use google to search for other answers

Custom Search

More Threads

• Dec '06 WSSF fails to install after installing Feb 07 GAX and GAT
• How do i create New Guidance Package from existing one?
• VSTS 2008 - installed GAX but GAT fails: C# Language is not installed
• How to invoke GAT Recipes from XAML conetxt menu
• Recipe framework error after deployment - serviceProvider is null
• Newbie Problem
• Will GAT/GAX be avalible for VS 2008?
• Not able to create a new Guidance Package project
• Remove Extra Lines using TextTemplateAction
• Pull project from sourcesafe on unfold