Merge pull request #39840 from neikeq/3.2-use-/restore-instead-of-/t-restore

[3.2] Mono/C#: Use /restore instead of /t:restore when building
This commit is contained in:
Rémi Verschelde 2020-06-26 08:08:40 +02:00 committed by GitHub
commit c8586d3837
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 31 deletions

View File

@ -142,9 +142,7 @@ def build_solution(env, solution_path, build_config, extra_msbuild_args=[]):
# Build solution # Build solution
targets = ["Restore", "Build"] msbuild_args += [solution_path, "/restore", "/t:Build", "/p:Configuration=" + build_config]
msbuild_args += [solution_path, "/t:%s" % ",".join(targets), "/p:Configuration=" + build_config]
msbuild_args += extra_msbuild_args msbuild_args += extra_msbuild_args
run_command(msbuild_path, msbuild_args, env_override=msbuild_env, name="msbuild") run_command(msbuild_path, msbuild_args, env_override=msbuild_env, name="msbuild")

View File

@ -47,19 +47,14 @@ namespace GodotTools.Build
private static bool PrintBuildOutput => private static bool PrintBuildOutput =>
(bool)EditorSettings.GetSetting("mono/builds/print_build_output"); (bool)EditorSettings.GetSetting("mono/builds/print_build_output");
private static Process LaunchBuild(string solution, IEnumerable<string> targets, string config, string loggerOutputDir, IEnumerable<string> customProperties = null) private static Process LaunchBuild(BuildInfo buildInfo)
{ {
(string msbuildPath, BuildTool buildTool) = MsBuildFinder.FindMsBuild(); (string msbuildPath, BuildTool buildTool) = MsBuildFinder.FindMsBuild();
if (msbuildPath == null) if (msbuildPath == null)
throw new FileNotFoundException("Cannot find the MSBuild executable."); throw new FileNotFoundException("Cannot find the MSBuild executable.");
var customPropertiesList = new List<string>(); string compilerArgs = BuildArguments(buildTool, buildInfo);
if (customProperties != null)
customPropertiesList.AddRange(customProperties);
string compilerArgs = BuildArguments(buildTool, solution, targets, config, loggerOutputDir, customPropertiesList);
var startInfo = new ProcessStartInfo(msbuildPath, compilerArgs); var startInfo = new ProcessStartInfo(msbuildPath, compilerArgs);
@ -100,19 +95,7 @@ namespace GodotTools.Build
public static int Build(BuildInfo buildInfo) public static int Build(BuildInfo buildInfo)
{ {
return Build(buildInfo.Solution, buildInfo.Targets, buildInfo.Configuration, using (var process = LaunchBuild(buildInfo))
buildInfo.LogsDirPath, buildInfo.CustomProperties);
}
public static Task<int> BuildAsync(BuildInfo buildInfo)
{
return BuildAsync(buildInfo.Solution, buildInfo.Targets, buildInfo.Configuration,
buildInfo.LogsDirPath, buildInfo.CustomProperties);
}
public static int Build(string solution, string[] targets, string config, string loggerOutputDir, IEnumerable<string> customProperties = null)
{
using (var process = LaunchBuild(solution, targets, config, loggerOutputDir, customProperties))
{ {
process.WaitForExit(); process.WaitForExit();
@ -120,9 +103,9 @@ namespace GodotTools.Build
} }
} }
public static async Task<int> BuildAsync(string solution, IEnumerable<string> targets, string config, string loggerOutputDir, IEnumerable<string> customProperties = null) public static async Task<int> BuildAsync(BuildInfo buildInfo)
{ {
using (var process = LaunchBuild(solution, targets, config, loggerOutputDir, customProperties)) using (var process = LaunchBuild(buildInfo))
{ {
await process.WaitForExitAsync(); await process.WaitForExitAsync();
@ -130,17 +113,18 @@ namespace GodotTools.Build
} }
} }
private static string BuildArguments(BuildTool buildTool, string solution, IEnumerable<string> targets, string config, string loggerOutputDir, IEnumerable<string> customProperties) private static string BuildArguments(BuildTool buildTool, BuildInfo buildInfo)
{ {
string arguments = string.Empty; string arguments = string.Empty;
if (buildTool == BuildTool.DotnetCli) if (buildTool == BuildTool.DotnetCli)
arguments += "msbuild "; // `dotnet msbuild` command arguments += "msbuild "; // `dotnet msbuild` command
arguments += $@"""{solution}"" /v:normal /t:{string.Join(",", targets)} ""/p:{"Configuration=" + config}"" " + arguments += $@"""{buildInfo.Solution}"" /t:{string.Join(",", buildInfo.Targets)} " +
$@"""/l:{typeof(GodotBuildLogger).FullName},{GodotBuildLogger.AssemblyPath};{loggerOutputDir}"""; $@"""/p:{"Configuration=" + buildInfo.Configuration}"" /v:normal " +
$@"""/l:{typeof(GodotBuildLogger).FullName},{GodotBuildLogger.AssemblyPath};{buildInfo.LogsDirPath}""";
foreach (string customProperty in customProperties) foreach (string customProperty in buildInfo.CustomProperties)
{ {
arguments += " /p:" + customProperty; arguments += " /p:" + customProperty;
} }

View File

@ -12,6 +12,7 @@ namespace GodotTools
public string Solution { get; } public string Solution { get; }
public string[] Targets { get; } public string[] Targets { get; }
public string Configuration { get; } public string Configuration { get; }
public bool Restore { get; }
public Array<string> CustomProperties { get; } = new Array<string>(); // TODO Use List once we have proper serialization public Array<string> CustomProperties { get; } = new Array<string>(); // TODO Use List once we have proper serialization
public string LogsDirPath => Path.Combine(GodotSharpDirs.BuildLogsDirs, $"{Solution.MD5Text()}_{Configuration}"); public string LogsDirPath => Path.Combine(GodotSharpDirs.BuildLogsDirs, $"{Solution.MD5Text()}_{Configuration}");
@ -39,11 +40,12 @@ namespace GodotTools
{ {
} }
public BuildInfo(string solution, string[] targets, string configuration) public BuildInfo(string solution, string[] targets, string configuration, bool restore)
{ {
Solution = solution; Solution = solution;
Targets = targets; Targets = targets;
Configuration = configuration; Configuration = configuration;
Restore = restore;
} }
} }
} }

View File

@ -175,7 +175,7 @@ namespace GodotTools
{ {
pr.Step("Building project solution", 0); pr.Step("Building project solution", 0);
var buildInfo = new BuildInfo(GodotSharpDirs.ProjectSlnPath, new[] {"Restore", "Build"}, config); var buildInfo = new BuildInfo(GodotSharpDirs.ProjectSlnPath, new[] {"Build"}, config, restore: true);
bool escapeNeedsDoubleBackslash = buildTool == BuildTool.MsBuildMono || buildTool == BuildTool.DotnetCli; bool escapeNeedsDoubleBackslash = buildTool == BuildTool.MsBuildMono || buildTool == BuildTool.DotnetCli;