ChocolateyHelper
public static class ChocolateyHelper
1. Methods
1.1. EnsureChocolatey(ISystemHost)
public static string EnsureChocolatey(ISystemHost host)
| Name | Type | Description |
|---|---|---|
host |
ISystemHost |
Returns: string
1.2. EnsureLatestNETSetup(ISystemHost)
Ensures NETSetup is the latest version via Chocolatey. Compares pre/post versions via choco list -r; restarts only when version changed. Skips with a visible INFO log when the running binary is a dev build outside the choco tree.
public static void EnsureLatestNETSetup(ISystemHost host)
| Name | Type | Description |
|---|---|---|
host |
ISystemHost |
1.3. GetInstalledPackages(ISystemHost)
Lists installed Chocolatey packages by parsing choco list output. Each line is "packageName version".
public static List<string> GetInstalledPackages(ISystemHost host)
| Name | Type | Description |
|---|---|---|
host |
ISystemHost |
Returns: List<string>
1.4. Install(ISystemHost, string, string)
public static bool Install(ISystemHost host, string software, out string result)
| Name | Type | Description |
|---|---|---|
host |
ISystemHost |
|
software |
string |
|
result |
string |
Returns: bool
1.5. Install(ISystemHost, string, string, string)
Installs a specific version of a Chocolatey package.
public static bool Install(ISystemHost host, string software, string version, out string result)
| Name | Type | Description |
|---|---|---|
host |
ISystemHost |
The system host. |
software |
string |
The package name to install. |
version |
string |
The specific version to install. |
result |
string |
The command output. |
Returns: bool — True if the install succeeded (exit code 0), false otherwise.
1.6. InstallVersioned(ISystemHost, string, string, string)
Same as NETSetup.Helpers.ChocolateyHelper.Install(ISystemHost,System.String,System.String,System.String@) but returns a tri-state outcome so callers can distinguish a fresh install from a no-op.
public static ChocolateyHelper.InstallOutcome InstallVersioned(ISystemHost host, string software, string version, out string result)
| Name | Type | Description |
|---|---|---|
host |
ISystemHost |
|
software |
string |
|
version |
string |
|
result |
string |
Returns: ChocolateyHelper.InstallOutcome
1.7. ParseInstalledPackagesList(string)
Parses the raw stdout of choco list into a list of installed package names. Public for unit testing — pure function.
public static List<string> ParseInstalledPackagesList(string output)
| Name | Type | Description |
|---|---|---|
output |
string |
Returns: List<string>
1.8. RepairBrokenDependencies(ISystemHost)
Detects and repairs broken Chocolatey dependency constraints in the lib folder. A broken dependency (e.g. notepadplusplus.install 8.6.4 vs notepadplusplus 8.9.2) blocks ALL package installs, even unrelated ones. This method runs a dry-run install to detect the issue, then upgrades the conflicting packages to resolve it.
public static void RepairBrokenDependencies(ISystemHost host)
| Name | Type | Description |
|---|---|---|
host |
ISystemHost |
1.9. Uninstall(ISystemHost, string, string)
public static bool Uninstall(ISystemHost host, string software, out string result)
| Name | Type | Description |
|---|---|---|
host |
ISystemHost |
|
software |
string |
|
result |
string |
Returns: bool
1.10. Upgrade(ISystemHost, string, string)
Upgrades a single Chocolatey package. Returns true on success.
public static bool Upgrade(ISystemHost host, string packageName, out string result)
| Name | Type | Description |
|---|---|---|
host |
ISystemHost |
|
packageName |
string |
|
result |
string |
Returns: bool
1.11. UpgradeAll(ISystemHost, IEnumerable<string>)
Upgrades all installed Chocolatey packages one by one, logging progress per package. Returns the number of failed packages (0 = all succeeded).
public static int UpgradeAll(ISystemHost host, IEnumerable<string> excludePackages = null)
| Name | Type | Description |
|---|---|---|
host |
ISystemHost |
|
excludePackages |
IEnumerable<string> |
Returns: int