Skip to content

Commit

Permalink
issue dotnet#1663: fix path to the script in run script post action.
Browse files Browse the repository at this point in the history
  • Loading branch information
AR-May committed Sep 25, 2020
1 parent 3da37e1 commit 8daf4e0
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using System.IO;
using Microsoft.TemplateEngine.Abstractions;
using Microsoft.TemplateEngine.Utils;

Expand Down Expand Up @@ -27,14 +28,17 @@ public bool Process(IEngineEnvironmentSettings settings, IPostAction actionConfi
}

settings.Host.LogMessage(string.Format(LocalizableStrings.RunningCommand, actionConfig.Args["executable"] + " " + args));

string resolvedExecutablePath = ResolveExecutableFilePath(actionConfig.Args["executable"], outputBasePath);

System.Diagnostics.Process commandResult = System.Diagnostics.Process.Start(new ProcessStartInfo
{
RedirectStandardError = true,
RedirectStandardOutput = redirectStandardOutput,
UseShellExecute = false,
CreateNoWindow = false,
WorkingDirectory = outputBasePath,
FileName = actionConfig.Args["executable"],
FileName = resolvedExecutablePath,
Arguments = args
});

Expand All @@ -55,5 +59,21 @@ public bool Process(IEngineEnvironmentSettings settings, IPostAction actionConfi

return allSucceeded;
}

private static string ResolveExecutableFilePath(string executableFileName, string outputBasePath)
{
if (!string.IsNullOrEmpty(outputBasePath) && Directory.Exists(outputBasePath))
{
string executableCombinedFileName = Path.Combine(Path.GetFullPath(outputBasePath), executableFileName);
if (File.Exists(executableCombinedFileName))
{
return executableCombinedFileName;
}
}

// The executable has not been found in the template folder, thus do not use the full path to the file.
// The executable will be further searched in the directories from the PATH environment variable.
return executableFileName;
}
}
}

0 comments on commit 8daf4e0

Please sign in to comment.