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 24, 2020
1 parent 3da37e1 commit e45776f
Showing 1 changed file with 23 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));

TryGetExecutableFileFullPath(actionConfig.Args["executable"], outputBasePath, out string executableFullPath);

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 = executableFullPath,
Arguments = args
});

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

return allSucceeded;
}

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

// 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.
resultExecutableFileName = executableFileName;
return false;
}
}
}

0 comments on commit e45776f

Please sign in to comment.