简体   繁体   中英

How to create an executable out of a solution file in VS2012?

I have tried this code where proj\\chancher2.sln is the path to another solution file which I'm trying to build.

   private void button1_Click(object sender, EventArgs e)
    {

        try
        {

            string projectFileName = @"proj\chancher2.sln";

            ProjectCollection pc = new ProjectCollection();

            Dictionary<string, string> GlobalProperty = new Dictionary<string, string>();

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

            GlobalProperty.Add("Platform", "x86");

            //Here, we set the property

            GlobalProperty.Add("OutputPath", @"D:\Output");

            BuildRequestData BuidlRequest = new BuildRequestData(projectFileName, GlobalProperty, null, new string[] { "Build" }, null);

            BuildResult buildResult = BuildManager.DefaultBuildManager.Build(new BuildParameters(pc), BuidlRequest);

        }

        catch (Exception E) {
            MessageBox.Show(E.Message);
        }
    }

When I click on the button I don't get any error but when I go to the Debug folder I don't find the executable compiled. Also when I go to D:\\Output folder. Nothing is there.

Where is the executable file. Or Is there any errors in the code above ?

Any help would be highly appreciated

If your output directory remains empty after running a build then perhaps the build was not successful. You might want to look at BuildResult.OveralResult to see. It will indicate with a simple "Failed/Success" enum whether or not the build was successful as indicated in this MSDN article .

I do not have much experience in using MSBuild this way, but it seems from a quick glance at MSDN that BuildResult will tell you want you want to know in regards to why it failed (if it did indeed fail).

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