简体   繁体   English

如何在VS2012的解决方案文件中创建可执行文件?

[英]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. 我尝试过此代码,其中proj\\chancher2.sln是我要构建的另一个解决方案文件的路径。

   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. 当我单击按钮时,没有任何错误,但是当我转到Debug文件夹时,找不到编译的可执行文件。 Also when I go to D:\\Output folder. 另外,当我转到D:\\ Output文件夹时。 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. 您可能需要查看BuildResult.OveralResult才能看到。 It will indicate with a simple "Failed/Success" enum whether or not the build was successful as indicated in this MSDN article . 它将用一个简单的“失败/成功”枚举来指示生成是否成功,如本MSDN文章所述

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). 我没有以这种方式使用MSBuild的经验,但是从MSDN的快速浏览看来,BuildResult会告诉您要了解有关失败原因的信息(如果确实失败了)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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