winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 92daa5fe3b52c5886e590023b2472c00ea7099ef
parent 6ec90f29b13373ebbb944d6d9b49dd134139afbf
Author: JohnMcPMS <johnmcp@microsoft.com>
Date:   Mon, 24 Mar 2025 14:01:58 -0700

Support official DSC v3 release (#5313)

## Change
Install the specific, MSIX version from the winget-pkgs in the pipeline.
(Store installs don't work on Server 2022)
In the processor, find `dsc.exe` by the alias location. Support the
preview version for test builds (anything from winget-cli).
Diffstat:
M.github/actions/spelling/patterns.txt | 1+
Mazure-pipelines.yml | 6++++--
Msrc/Microsoft.Management.Configuration.Processor/DSCv3/Helpers/ProcessorSettings.cs | 41++++++++++++++++++++++-------------------
3 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/.github/actions/spelling/patterns.txt b/.github/actions/spelling/patterns.txt @@ -34,6 +34,7 @@ GetRestAPIBaseUri\(".*"\) == L".*" # Sample store product id for App Installer 9nblggh4nns1 +9NVTPZWRC6KQ # Automatically suggested patterns diff --git a/azure-pipelines.yml b/azure-pipelines.yml @@ -377,9 +377,11 @@ jobs: displayName: Clean up Sysinternals PsTools condition: succeededOrFailed() - # Install DSC v3 preview until the DSC v3 processor handles that on its own + # Install DSC v3 until the DSC v3 processor handles that on its own - powershell: | - Install-WinGetPackage -Id Microsoft.DSC.Preview -Source winget + $installResult = Install-WinGetPackage -Id Microsoft.DSC.Preview -Source winget -InstallerType Msix -Version 3.1.1 + $installResult | Format-List + if ($installResult.ExtendedErrorCode) { throw $installResult.ExtendedErrorCode } displayName: Install DSC v3 condition: succeededOrFailed() diff --git a/src/Microsoft.Management.Configuration.Processor/DSCv3/Helpers/ProcessorSettings.cs b/src/Microsoft.Management.Configuration.Processor/DSCv3/Helpers/ProcessorSettings.cs @@ -6,8 +6,8 @@ namespace Microsoft.Management.Configuration.Processor.DSCv3.Helpers { + using System; using System.IO; - using System.Linq; using System.Text; using Microsoft.Management.Configuration.Processor.DSCv3.Model; @@ -109,28 +109,18 @@ namespace Microsoft.Management.Configuration.Processor.DSCv3.Helpers /// <returns>The full path to the dsc.exe executable, or null if not found.</returns> public static string? FindDscExecutablePath() { - // To start, only attempt to find the package and launch it via the app execution fallback handler. - // In the future, discover it through %PATH% searching, but probably don't allow that from an elevated process. + // To start, only attempt to find the package and launch it via app execution alias. + // In the future, consider discovering it through %PATH% searching, but probably don't allow that from an elevated process. // That probably means creating another read property for finding the secure path. - Windows.Management.Deployment.PackageManager packageManager = new Windows.Management.Deployment.PackageManager(); - - // Until there is a non-preview of this package, use the preview version. - var packages = packageManager.FindPackagesForUser(null, "Microsoft.DesiredStateConfiguration-Preview_8wekyb3d8bbwe"); - - if (packages == null) - { - return null; - } - - string packageInstallLocation = packages.First().InstalledLocation.Path; - string result = Path.Combine(packageInstallLocation, DscExecutableFileName); - - if (!Path.Exists(result)) +#if !AICLI_DISABLE_TEST_HOOKS + string? result = GetDscExecutablePathForPackage("Microsoft.DesiredStateConfiguration-Preview_8wekyb3d8bbwe"); + if (result != null) { - return null; + return result; } +#endif - return result; + return GetDscExecutablePathForPackage("Microsoft.DesiredStateConfiguration_8wekyb3d8bbwe"); } /// <summary> @@ -166,5 +156,18 @@ namespace Microsoft.Management.Configuration.Processor.DSCv3.Helpers return sb.ToString(); } + + private static string? GetDscExecutablePathForPackage(string packageFamilyName) + { + string localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); + string result = Path.Combine(localAppData, "Microsoft\\WindowsApps", packageFamilyName, DscExecutableFileName); + + if (!Path.Exists(result)) + { + return null; + } + + return result; + } } }