本文介绍了在C#可执行文件中构建.sln的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试用C#构建.sln.我有以下代码.
I'm trying to build a .sln in C#. I have the following code.
try
{
Console.WriteLine("Building Solution...\n");
string projectFileName = Directory.GetCurrentDirectory() + "\\build\\Solution.sln";
ProjectCollection pc = new ProjectCollection();
Dictionary<string, string> GlobalProperty = new Dictionary<string, string>();
GlobalProperty.Add("Configuration", "Release");
GlobalProperty.Add("Platform", "x86");
BuildRequestData BuidlRequest = new BuildRequestData(projectFileName, GlobalProperty, null, new string[] { "Build" }, null);
BuildResult buildResult = BuildManager.DefaultBuildManager.Build(new BuildParameters(pc), BuidlRequest);
catch (Exception e)
{
Console.Write("Error:" + e.Message);
Console.ReadLine();
}
Console.WriteLine("Completed Solution build...\nPress any key to continue...");
它没有发出错误,它确实显示了Completed Solution build...
,但是我在\bin\Release
中找不到可执行文件.我忘记了什么或如何检查?
It doesn't thow a error, it does show Completed Solution build...
but I can't find the executable in \bin\Release
. Am I forgetting something or how can I check it?
推荐答案
我设法使其正常运行,但解决方案并未因代码中的错误而构建.无论如何,这就是解决方案.
I managed to get it working, solution is not building to due errors in the code. Anyway this is the solution.
string projectFileName = Directory.GetCurrentDirectory() + "\\build\\Solution.sln";
ProjectCollection pc = new ProjectCollection();
Dictionary<string, string> GlobalProperty = new Dictionary<string, string>();
GlobalProperty.Add("Configuration", "Release");
GlobalProperty.Add("Platform", "Any CPU");
GlobalProperty.Add("OutputPath", Directory.GetCurrentDirectory() + "\\build\\\bin\\Release");
BuildParameters bp = new BuildParameters(pc);
bp.Loggers = new[] {
new FileLogger
{
Verbosity = LoggerVerbosity.Detailed,
ShowSummary = true,
SkipProjectStartedText = true
}
};
BuildManager.DefaultBuildManager.BeginBuild(bp);
BuildRequestData BuildRequest = new BuildRequestData(projectFileName, GlobalProperty, null, new string[] { "Build" }, null);
BuildSubmission BuildSubmission = BuildManager.DefaultBuildManager.PendBuildRequest(BuildRequest);
BuildSubmission.Execute();
BuildManager.DefaultBuildManager.EndBuild();
if (BuildSubmission.BuildResult.OverallResult == BuildResultCode.Failure)
{
throw new Exception();
}
}
这篇关于在C#可执行文件中构建.sln的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!