diff --git a/src/chocolatey.resources/chocolatey.resources.csproj b/src/chocolatey.resources/chocolatey.resources.csproj
index 15058e2d4f..be6e89404c 100644
--- a/src/chocolatey.resources/chocolatey.resources.csproj
+++ b/src/chocolatey.resources/chocolatey.resources.csproj
@@ -119,6 +119,9 @@
+
+
+
-
+
\ No newline at end of file
diff --git a/src/chocolatey.resources/helpers/chocolateyScriptRunner.ps1 b/src/chocolatey.resources/helpers/chocolateyScriptRunner.ps1
new file mode 100644
index 0000000000..14f69c8e88
--- /dev/null
+++ b/src/chocolatey.resources/helpers/chocolateyScriptRunner.ps1
@@ -0,0 +1,28 @@
+param(
+ [alias("ia","installArgs")][string] $installArguments = '',
+ [alias("o","override","overrideArguments","notSilent")]
+ [switch] $overrideArgs = $false,
+ [alias("x86")][switch] $forceX86 = $false,
+ [alias("params")][alias("parameters")][alias("pkgParams")][string]$packageParameters = '',
+ [string]$packageScript
+)
+
+Write-Debug "Running 'ChocolateyScriptRunner' for $($env:packageName) v$($env:packageVersion) with packageScript `'$packageScript`', packageFolder:`'$($env:packageFolder)`', installArguments: `'$installArguments`', packageParameters: `'$packageParameters`',"
+
+## Set the culture to invariant
+$currentThread = [System.Threading.Thread]::CurrentThread;
+$culture = [System.Globalization.CultureInfo]::InvariantCulture;
+$currentThread.CurrentCulture = $culture;
+$currentThread.CurrentUICulture = $culture;
+
+$RunNote = "DarkCyan"
+$Warning = "Magenta"
+$ErrorColor = "Red"
+$Note = "Green"
+
+$version = $env:packageVersion
+$packageName = $env:packageName
+$packageFolder = $env:packageFolder
+
+Write-Debug "Running `'$packageScript`'";
+& "$packageScript"
\ No newline at end of file
diff --git a/src/chocolatey/infrastructure.app/services/PowershellService.cs b/src/chocolatey/infrastructure.app/services/PowershellService.cs
index f8b4625ff8..364df4ac3a 100644
--- a/src/chocolatey/infrastructure.app/services/PowershellService.cs
+++ b/src/chocolatey/infrastructure.app/services/PowershellService.cs
@@ -89,22 +89,36 @@ public bool uninstall(ChocolateyConfiguration configuration, PackageResult packa
return run_action(configuration, packageResult, CommandNameType.uninstall);
}
- public string wrap_script_with_module(string script)
+ public string wrap_script_with_module(string script, ChocolateyConfiguration config)
{
var installerModules = _fileSystem.get_files(ApplicationParameters.InstallLocation, "chocolateyInstaller.psm1", SearchOption.AllDirectories);
var installerModule = installerModules.FirstOrDefault();
+ var scriptRunners = _fileSystem.get_files(ApplicationParameters.InstallLocation, "chocolateyScriptRunner.ps1", SearchOption.AllDirectories);
+ var scriptRunner = scriptRunners.FirstOrDefault();
// removed setting all errors to terminating. Will cause too
// many issues in existing packages, including upgrading
// Chocolatey from older POSH client due to log errors
//$ErrorActionPreference = 'Stop';
- return "[System.Threading.Thread]::CurrentThread.CurrentCulture = '';[System.Threading.Thread]::CurrentThread.CurrentUICulture = ''; & import-module -name '{0}';{2} & '{1}'"
+ return "[System.Threading.Thread]::CurrentThread.CurrentCulture = '';[System.Threading.Thread]::CurrentThread.CurrentUICulture = ''; & import-module -name '{0}';{2} & '{1}' {3}"
.format_with(
installerModule,
- script,
- string.IsNullOrWhiteSpace(_customImports) ? string.Empty : "& {0}".format_with(_customImports.EndsWith(";") ? _customImports : _customImports + ";")
+ scriptRunner,
+ string.IsNullOrWhiteSpace(_customImports) ? string.Empty : "& {0}".format_with(_customImports.EndsWith(";") ? _customImports : _customImports + ";"),
+ get_script_arguments(script,config)
);
}
+ private string get_script_arguments(string script, ChocolateyConfiguration config)
+ {
+ return "-packageScript '{0}' -installArguments '{1}' -forceX86 {2} -packageParameters '{3}' -overrideArgs {4}".format_with(
+ script,
+ config.InstallArguments,
+ config.ForceX86 ? "$true" : "$false",
+ config.PackageParameters,
+ config.OverrideArguments ? "$true" : "$false"
+ );
+ }
+
public bool run_action(ChocolateyConfiguration configuration, PackageResult packageResult, CommandNameType command)
{
var installerRun = false;
@@ -225,7 +239,7 @@ Skip is an advanced option and most likely will never be wanted.
{
installerRun = true;
var exitCode = PowershellExecutor.execute(
- wrap_script_with_module(chocoPowerShellScript),
+ wrap_script_with_module(chocoPowerShellScript, configuration),
_fileSystem,
configuration.CommandExecutionTimeoutSeconds,
(s, e) =>