commit 8a8bfa7a0e6d5b516b393355feffbb1f03c0bef3
parent 565344c92d7b4732cce026ca076bd973897bce60
Author: yao-msft <50888816+yao-msft@users.noreply.github.com>
Date: Wed, 7 May 2025 15:35:46 -0700
Install dsc v3 package if not found when processing dsc v3 configuration file (#5437)
Validated by removing the "install dsc v3" step in pipeline and e2e tests work.
Diffstat:
5 files changed, 47 insertions(+), 11 deletions(-)
diff --git a/.github/actions/spelling/patterns.txt b/.github/actions/spelling/patterns.txt
@@ -35,6 +35,7 @@ GetRestAPIBaseUri\(".*"\) == L".*"
# Sample store product id for App Installer
9nblggh4nns1
9NVTPZWRC6KQ
+9PCX3HX4HZ0Z
# Automatically suggested patterns
diff --git a/azure-pipelines.yml b/azure-pipelines.yml
@@ -371,17 +371,8 @@ jobs:
displayName: Clean up Sysinternals PsTools
condition: succeededOrFailed()
- # Install DSC v3 until the DSC v3 processor handles that on its own
- - powershell: |
- $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()
-
# Install required DSC modules until export all command can handle auto acquisition
- pwsh: |
- Install-Module -Name Microsoft.WinGet.DSC -Force
Install-Module -Name Microsoft.Windows.Developer -AllowPrerelease -Force
displayName: Install Required DSC Modules for Tests
condition: succeededOrFailed()
diff --git a/src/AppInstallerCLICore/Resources.h b/src/AppInstallerCLICore/Resources.h
@@ -98,6 +98,8 @@ namespace AppInstaller::CLI::Resource
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationInDesiredState);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationInform);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationInitializing);
+ WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationInstallDscPackage);
+ WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationInstallDscPackageFailed);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationLocal);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationModuleNameOnly);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationModulePath);
diff --git a/src/AppInstallerCLICore/Workflows/ConfigurationFlow.cpp b/src/AppInstallerCLICore/Workflows/ConfigurationFlow.cpp
@@ -5,6 +5,7 @@
#include "ImportExportFlow.h"
#include "PromptFlow.h"
#include "TableOutput.h"
+#include "MSStoreInstallerHandler.h"
#include "Public/ConfigurationSetProcessorFactoryRemoting.h"
#include "ConfigurationCommon.h"
#include "ConfigurationWingetDscModuleUnitValidation.h"
@@ -187,6 +188,41 @@ namespace AppInstaller::CLI::Workflow
{
factoryMap.Insert(ConfigurationRemoting::ToHString(ConfigurationRemoting::PropertyName::DscExecutablePath), Utility::ConvertToUTF16(context.Args.GetArg(Args::Type::ConfigurationProcessorPath)));
}
+ else
+ {
+ // Make sure DSC executable path can be found. Otherwise, we'll install the DSC v3 package.
+ winrt::hstring foundExecutablePath = factoryMap.Lookup(ConfigurationRemoting::ToHString(ConfigurationRemoting::PropertyName::FoundDscExecutablePath));
+ if (foundExecutablePath.empty())
+ {
+ AICLI_LOG(Config, Info, << "dsc.exe not found and not provided. Installing dsc package from store.");
+ context.Reporter.Info() << Resource::String::ConfigurationInstallDscPackage;
+
+ auto installDscContextPtr = context.CreateSubContext();
+ Execution::Context& installDscContext = *installDscContextPtr;
+ auto previousThreadGlobals = installDscContext.SetForCurrentThread();
+
+ Manifest::ManifestInstaller dscInstaller;
+// TEMP: Until DSCv3 support is not experimental, allow the preview build to be installed automatically.
+// #ifndef AICLI_DISABLE_TEST_HOOKS
+ dscInstaller.ProductId = "9PCX3HX4HZ0Z";
+// #else
+// dscInstaller.ProductId = "9NVTPZWRC6KQ";
+// #endif
+ installDscContext.Add<Execution::Data::Installer>(std::move(dscInstaller));
+ installDscContext.Args.AddArg(Execution::Args::Type::InstallScope, Manifest::ScopeToString(Manifest::ScopeEnum::User));
+ installDscContext.Args.AddArg(Execution::Args::Type::Silent);
+ installDscContext.Args.AddArg(Execution::Args::Type::Force);
+
+ installDscContext << MSStoreInstall;
+
+ if (installDscContext.IsTerminated())
+ {
+ AICLI_LOG(Config, Error, << "Failed to install dsc v3 package and could not find dsc.exe, it must be provided by the user.");
+ context.Reporter.Error() << Resource::String::ConfigurationInstallDscPackageFailed;
+ THROW_WIN32(ERROR_FILE_NOT_FOUND);
+ }
+ }
+ }
if (Logging::Log().IsEnabled(Logging::Channel::Config, Logging::Level::Verbose))
{
diff --git a/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw b/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw
@@ -3348,4 +3348,11 @@ Please specify one of them using the --source option to proceed.</value>
<data name="OutputDirectoryArgumentDescription" xml:space="preserve">
<value>Directory where the results are to be written</value>
</data>
-</root>-
\ No newline at end of file
+ <data name="ConfigurationInstallDscPackage" xml:space="preserve">
+ <value>Desired State Configuration package not found on the system. Installing the package...</value>
+ </data>
+ <data name="ConfigurationInstallDscPackageFailed" xml:space="preserve">
+ <value>Failed to install Desired State Configuration package. Install the package manually or provide the path to dsc.exe through --processor-path argument.</value>
+ <comment>{Locked="dsc.exe","--processor-path"}</comment>
+ </data>
+</root>