How to automatically add a huge set of .vcproj files to the solution?

浪子不回头ぞ 提交于 2019-12-24 11:01:03

问题


I have a huge set of .vcproj files (~200) stored in different locations. I have a list of these files with full paths. How can i automatically add them to the solution file(.sln) ?

UPD: I'm looking for existing tool/method.


回答1:


Here's how I'd do it:

  1. Create and save a blank solution to insert the vcproj files into (File->New Project->Other Project Types->Visual Studio Solutions->Blank Solution)

  2. Create a VS macro which adds a project to a solution, saves the solution, and exits. Try the following:

    Public Sub AddProjectAndExit(Optional ByVal vcprojPath As String = "")
        If Not String.IsNullOrEmpty(vcProjPath) Then
            DTE.ExecuteCommand("File.AddExistingProject", vcprojPath)
            DTE.ExecuteCommand("File.SaveAll")
            DTE.ExecuteCommand("File.Exit")
        End If
    End Sub
    
  3. Create a batch script which executes this macro from the Visual Studio command prompt, iterating over each of your .vcproj files. The command for a single execution would be:

    devenv.exe BlankSolution.sln /Command "Macros.MyMacros.Module1.AddProjectAndExit MyProject1.vcproj"
    

Hope that helps!




回答2:


The .vcproj & .sln files are ascii format, so you could write a macro/script/program to run through your list of projects and insert the proper info into the .sln file. The only additional info you'll need to get about the projects is the project GUID, which can be found in the .vcproj file (assuming your build configurations are the same for each project).




回答3:


Modify and existing vcwizard.

function CreateCustomProject(strProjectName, strProjectPath)
{
    try
    {
            //This will add the default project to the new solution

            prj = oTarget.AddFromTemplate(strProjTemplate, strProjectPath, strProjectNameWithExt);


            //Create a loop here to loop through the project names
//you want to add to the new solution.
            var prjItem = oTarget.AddFromFile("C:\\YourProjectPath\\YourProject.vcproj", false);


        }
        return prj;
    }
    catch(e)
    {
        throw e;
    }
}


来源:https://stackoverflow.com/questions/747687/how-to-automatically-add-a-huge-set-of-vcproj-files-to-the-solution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!