Skip to content

Commit 8a8bfa7

Browse files
authored
Install dsc v3 package if not found when processing dsc v3 configuration file (microsoft#5437)
Validated by removing the "install dsc v3" step in pipeline and e2e tests work.
1 parent 565344c commit 8a8bfa7

File tree

5 files changed

+47
-10
lines changed

5 files changed

+47
-10
lines changed

.github/actions/spelling/patterns.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ GetRestAPIBaseUri\(".*"\) == L".*"
3535
# Sample store product id for App Installer
3636
9nblggh4nns1
3737
9NVTPZWRC6KQ
38+
9PCX3HX4HZ0Z
3839

3940
# Automatically suggested patterns
4041

azure-pipelines.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -371,17 +371,8 @@ jobs:
371371
displayName: Clean up Sysinternals PsTools
372372
condition: succeededOrFailed()
373373
374-
# Install DSC v3 until the DSC v3 processor handles that on its own
375-
- powershell: |
376-
$installResult = Install-WinGetPackage -Id Microsoft.DSC.Preview -Source winget -InstallerType Msix -Version 3.1.1
377-
$installResult | Format-List
378-
if ($installResult.ExtendedErrorCode) { throw $installResult.ExtendedErrorCode }
379-
displayName: Install DSC v3
380-
condition: succeededOrFailed()
381-
382374
# Install required DSC modules until export all command can handle auto acquisition
383375
- pwsh: |
384-
Install-Module -Name Microsoft.WinGet.DSC -Force
385376
Install-Module -Name Microsoft.Windows.Developer -AllowPrerelease -Force
386377
displayName: Install Required DSC Modules for Tests
387378
condition: succeededOrFailed()

src/AppInstallerCLICore/Resources.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ namespace AppInstaller::CLI::Resource
9898
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationInDesiredState);
9999
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationInform);
100100
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationInitializing);
101+
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationInstallDscPackage);
102+
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationInstallDscPackageFailed);
101103
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationLocal);
102104
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationModuleNameOnly);
103105
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationModulePath);

src/AppInstallerCLICore/Workflows/ConfigurationFlow.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "ImportExportFlow.h"
66
#include "PromptFlow.h"
77
#include "TableOutput.h"
8+
#include "MSStoreInstallerHandler.h"
89
#include "Public/ConfigurationSetProcessorFactoryRemoting.h"
910
#include "ConfigurationCommon.h"
1011
#include "ConfigurationWingetDscModuleUnitValidation.h"
@@ -187,6 +188,41 @@ namespace AppInstaller::CLI::Workflow
187188
{
188189
factoryMap.Insert(ConfigurationRemoting::ToHString(ConfigurationRemoting::PropertyName::DscExecutablePath), Utility::ConvertToUTF16(context.Args.GetArg(Args::Type::ConfigurationProcessorPath)));
189190
}
191+
else
192+
{
193+
// Make sure DSC executable path can be found. Otherwise, we'll install the DSC v3 package.
194+
winrt::hstring foundExecutablePath = factoryMap.Lookup(ConfigurationRemoting::ToHString(ConfigurationRemoting::PropertyName::FoundDscExecutablePath));
195+
if (foundExecutablePath.empty())
196+
{
197+
AICLI_LOG(Config, Info, << "dsc.exe not found and not provided. Installing dsc package from store.");
198+
context.Reporter.Info() << Resource::String::ConfigurationInstallDscPackage;
199+
200+
auto installDscContextPtr = context.CreateSubContext();
201+
Execution::Context& installDscContext = *installDscContextPtr;
202+
auto previousThreadGlobals = installDscContext.SetForCurrentThread();
203+
204+
Manifest::ManifestInstaller dscInstaller;
205+
// TEMP: Until DSCv3 support is not experimental, allow the preview build to be installed automatically.
206+
// #ifndef AICLI_DISABLE_TEST_HOOKS
207+
dscInstaller.ProductId = "9PCX3HX4HZ0Z";
208+
// #else
209+
// dscInstaller.ProductId = "9NVTPZWRC6KQ";
210+
// #endif
211+
installDscContext.Add<Execution::Data::Installer>(std::move(dscInstaller));
212+
installDscContext.Args.AddArg(Execution::Args::Type::InstallScope, Manifest::ScopeToString(Manifest::ScopeEnum::User));
213+
installDscContext.Args.AddArg(Execution::Args::Type::Silent);
214+
installDscContext.Args.AddArg(Execution::Args::Type::Force);
215+
216+
installDscContext << MSStoreInstall;
217+
218+
if (installDscContext.IsTerminated())
219+
{
220+
AICLI_LOG(Config, Error, << "Failed to install dsc v3 package and could not find dsc.exe, it must be provided by the user.");
221+
context.Reporter.Error() << Resource::String::ConfigurationInstallDscPackageFailed;
222+
THROW_WIN32(ERROR_FILE_NOT_FOUND);
223+
}
224+
}
225+
}
190226

191227
if (Logging::Log().IsEnabled(Logging::Channel::Config, Logging::Level::Verbose))
192228
{

src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3348,4 +3348,11 @@ Please specify one of them using the --source option to proceed.</value>
33483348
<data name="OutputDirectoryArgumentDescription" xml:space="preserve">
33493349
<value>Directory where the results are to be written</value>
33503350
</data>
3351-
</root>
3351+
<data name="ConfigurationInstallDscPackage" xml:space="preserve">
3352+
<value>Desired State Configuration package not found on the system. Installing the package...</value>
3353+
</data>
3354+
<data name="ConfigurationInstallDscPackageFailed" xml:space="preserve">
3355+
<value>Failed to install Desired State Configuration package. Install the package manually or provide the path to dsc.exe through --processor-path argument.</value>
3356+
<comment>{Locked="dsc.exe","--processor-path"}</comment>
3357+
</data>
3358+
</root>

0 commit comments

Comments
 (0)