简体   繁体   中英

Build solution programmatically with its solution configuration

I have a function to build a big solution (100+ projects)

public static bool BuildSolution()
{
    bool result = false;
    try
    {
        string solutionPath = @"C:\path\to\my\solution.sln";

        ProjectCollection pc = new ProjectCollection();

        Dictionary<string, string> GlobalProperty = new Dictionary<string, string>();
        GlobalProperty.Add("Configuration", "Debug");
        GlobalProperty.Add("Platform", "Any CPU");
        GlobalProperty.Add("OutputPath", @"bin\Debug\");

        BuildParameters bp = new BuildParameters(pc);
        BuildRequestData BuidlRequest = new BuildRequestData(solutionPath, GlobalProperty, "4.0", new string[] { "Build" },null);
        BuildResult buildResult = BuildManager.DefaultBuildManager.Build(bp, BuidlRequest);

        if (buildResult.OverallResult == BuildResultCode.Success)
        {
            result = true;
        }
    }
    catch (Exception e)
    {
        Console.WriteLine("Build Failed: " + e.ToString());
    }
    return result;          
}

Is there a way to use the solution configuration set within visual studio to prevent some project to be builded?

解决方案配置

changes made on this form does not affect the .sln file and so my function keep build everything

You can create a new solution configuration using the configuration manager. In this new configuration you can only select the projects you need to build.

And for building using this configuration, you can change your program as

GlobalProperty.Add("Configuration", "NewConfigurationName");

使用配置管理器进行新配置 Hope this is what you are looking for!!!

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