2

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

shikata
  • 95
  • 1
  • 11
  • possible duplicate of [Getting the absolute path of the executable, using C#?](http://stackoverflow.com/questions/1658518/getting-the-absolute-path-of-the-executable-using-c) – Alex Jun 17 '13 at 07:05

1 Answers1

0

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).

rstat1
  • 158
  • 2
  • 14