在 C# 可执行文件中构建 .sln
Building a .sln in C# executable
我正在尝试在 C# 中构建 .sln。我有以下代码。
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
中找不到可执行文件。我是不是忘记了什么或者我该如何检查?
我设法让它工作,由于代码中的错误,解决方案没有构建。无论如何,这就是解决方案。
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。我有以下代码。
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
中找不到可执行文件。我是不是忘记了什么或者我该如何检查?
我设法让它工作,由于代码中的错误,解决方案没有构建。无论如何,这就是解决方案。
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();
}
}