简体   繁体   中英

Add referenced projects into solution automatically

My situation:

  • I have a solution A with hundreds of projects,
  • Some of projects are class libraries and are referenced from other projects.

Now I want to create a new solution B which will consist of subset of projects of solution A . I start by adding the first pre-existing project into this new solution B . This project is referencing couple of class libraries from solution A . Therefore it is logical that these libraries cannot be found and I cannot build. Of course I could add all the referenced projects manually into the new solution B but that would take quite a long time, considering the total amount of projects that I need to add.

Is there some built in Visual Studio feature that can take care of this on my behalf? Ie I will be offered an opportunity to import all the referenced projects at once and the B.sln file will be updated automatically.

I also have a ReSharper extension but I couldn't find such feature in there as well.

EDIT:

Some more detail on what I am trying to achieve. A.sln has lots of application projects and literally hundreds of class libraries. I want to create a new B.sln for one particular application project from A.sln and only add the class libraries that it is referencing, directly or indirectly... But the dependencies can go up to 15 levels deep so manually removing projects from original A.sln to create B.sln is really not suitable for me as I would have to carefully consider each one of the projects that I would be manually removing from the original sln file, subsequently reviewing the csproj files to find whether the application I am interested in does not indirectly depends on them via one of its direct references.

Copy paste your current solution file and start with it. Open it in new Visual Studio Instance. Remove your projects one by one. Instead of adding new projects, removing unnecessary ones will be more easy for you. As far as I know there is no such feature in Visual Studio as you want.

Removing will be more easy since projects are already there. Do not use Visual Studio to remove project but open sln file in suitable programmers notepad. Your projects are added to sln file as below lines.

Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example.Integration.App1", "..\Example.Integration\Example.Integration.App1\Example.Integration.App1.csproj", "{E3977144-AFBA-451D-894C-1F89AA008041}"
EndProject

Removing such lines will be more easy if your projects has naming convention.

The best way to port references from an existing project that I've found is to generate a template for that project.

  1. On the File menu, click Export Template. The Export Template wizard opens.
  2. Choose project template and move through the wizard
  3. Click Finish. Your project is exported into a .zip file and placed in the specified output location, and, if selected, imported into Visual Studio.
  4. Now, when you setup a new project for solution B. You'll be able to choose the project template from A and all the file structure/references are preserved.

Ref: http://msdn.microsoft.com/en-us/library/vstudio/xkh1wxd8%28v=vs.100%29.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM