diff --git a/.github/actions/spelling/patterns.txt b/.github/actions/spelling/patterns.txt index 4c6a638721..529cbc6a5b 100644 --- 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 index 178d6c2d39..816a084e9a 100644 --- 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 index 76b0d6d235..4d01bf8705 100644 --- 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 index ccc2f73bfe..773edabde2 100644 --- 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(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 index 7f9032c7e9..c53c35b31a 100644 --- 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. Directory where the results are to be written - \ No newline at end of file + + Desired State Configuration package not found on the system. Installing the package... + + + Failed to install Desired State Configuration package. Install the package manually or provide the path to dsc.exe through --processor-path argument. + {Locked="dsc.exe","--processor-path"} + +