in src/PowerShell/PowerShellManager.cs [156:202]
internal void InvokeProfile(string profilePath)
{
Exception exception = null;
if (profilePath == null)
{
string noProfileMsg = string.Format(PowerShellWorkerStrings.FileNotFound, "profile.ps1", FunctionLoader.FunctionAppRootPath);
Logger.Log(isUserOnlyLog: false, LogLevel.Trace, noProfileMsg);
return;
}
var profileExecutionHadErrors = false;
try
{
var stopwatch = new Stopwatch();
stopwatch.Start();
// Import-Module on a .ps1 file will evaluate the script in the global scope.
_pwsh.AddCommand(Utils.ImportModuleCmdletInfo)
.AddParameter("Name", profilePath)
.AddCommand(Utils.TracePipelineObjectCmdlet)
.InvokeAndClearCommands();
profileExecutionHadErrors = _pwsh.HadErrors;
_pwsh.AddCommand(Utils.RemoveModuleCmdletInfo)
.AddParameter("FullyQualifiedName", profilePath)
.AddParameter("Force", Utils.BoxedTrue)
.AddParameter("ErrorAction", "SilentlyContinue")
.InvokeAndClearCommands();
Logger.Log(isUserOnlyLog: false, LogLevel.Trace, string.Format(PowerShellWorkerStrings.ProfileInvocationCompleted, stopwatch.ElapsedMilliseconds));
}
catch (Exception e)
{
exception = e;
throw;
}
finally
{
if (profileExecutionHadErrors || _pwsh.HadErrors)
{
string errorMsg = string.Format(PowerShellWorkerStrings.ErrorsWhileExecutingProfile, profilePath);
Logger.Log(isUserOnlyLog: true, LogLevel.Error, errorMsg, exception);
}
}
}