Skip to content

Commit 825fa20

Browse files
author
Steve Lee (POWERSHELL HE/HIM) (from Dev Box)
committed
Add prompt when dsc is run from MS Store and ability to build private msix for testing
1 parent f722880 commit 825fa20

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

build.ps1

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ param(
77
$architecture = 'current',
88
[switch]$Clippy,
99
[switch]$SkipBuild,
10-
[ValidateSet('msix','msixbundle','tgz','zip')]
10+
[ValidateSet('msix','msix-private','msixbundle','tgz','zip')]
1111
$packageType,
1212
[switch]$Test,
1313
[switch]$GetPackageVersion,
@@ -422,7 +422,7 @@ if ($packageType -eq 'msixbundle') {
422422
$msixPath = Join-Path $PSScriptRoot 'bin' 'msix'
423423
& $makeappx bundle /d $msixPath /p "$PSScriptRoot\bin\$packageName.msixbundle"
424424
return
425-
} elseif ($packageType -eq 'msix') {
425+
} elseif ($packageType -eq 'msix' -or $packageType -eq 'msix-private') {
426426
if (!$IsWindows) {
427427
throw "MSIX is only supported on Windows"
428428
}
@@ -431,21 +431,34 @@ if ($packageType -eq 'msixbundle') {
431431
throw 'MSIX requires a specific architecture'
432432
}
433433

434+
$isPrivate = $packageType -eq 'msix-private'
435+
434436
$makeappx = Find-MakeAppx
435437
$makepri = Get-Item (Join-Path $makeappx.Directory "makepri.exe") -ErrorAction Stop
436438
$displayName = "DesiredStateConfiguration"
437439
$isPreview = $productVersion -like '*-*'
438440
$productName = "DesiredStateConfiguration"
439441
if ($isPreview) {
440442
Write-Verbose -Verbose "Preview version detected"
441-
$productName += "-Preview"
443+
if ($isPrivate) {
444+
$productName += "-Private"
445+
}
446+
else {
447+
$productName += "-Preview"
448+
}
442449
# save preview number
443450
$previewNumber = $productVersion -replace '.*?-[a-z]+\.([0-9]+)', '$1'
444451
# remove label from version
445452
$productVersion = $productVersion.Split('-')[0]
446453
# replace revision number with preview number
447454
$productVersion = $productVersion -replace '(\d+)$', "$previewNumber.0"
448-
$displayName += "-Preview"
455+
456+
if ($isPrivate) {
457+
$displayName += "-Private"
458+
}
459+
else {
460+
$displayName += "-Preview"
461+
}
449462
}
450463
Write-Verbose -Verbose "Product version is $productVersion"
451464
$arch = if ($architecture -eq 'aarch64-pc-windows-msvc') { 'arm64' } else { 'x64' }
@@ -517,7 +530,7 @@ if ($packageType -eq 'msixbundle') {
517530
throw "Failed to create msix package"
518531
}
519532

520-
Write-Host -ForegroundColor Green "`nMSIX package is created at $packageName.msix"
533+
Write-Host -ForegroundColor Green "`nMSIX package is created at $packageName"
521534
} elseif ($packageType -eq 'zip') {
522535
$zipTarget = Join-Path $PSScriptRoot 'bin' $architecture 'zip'
523536
if (Test-Path $zipTarget) {

dsc/src/main.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ fn main() {
2626
#[cfg(debug_assertions)]
2727
check_debug();
2828

29+
#[cfg(windows)]
30+
check_store();
31+
2932
if ctrlc::set_handler(ctrlc_handler).is_err() {
3033
error!("Error: Failed to set Ctrl-C handler");
3134
}
@@ -156,3 +159,37 @@ fn check_debug() {
156159
}
157160
}
158161
}
162+
163+
// Check if the dsc binary parent process is WinStore.App or Exploerer.exe
164+
#[cfg(windows)]
165+
fn check_store() {
166+
let message = r"
167+
DSC.exe is a command-line tool and cannot be run directly from the Windows Store or Explorer.
168+
Visit https://aka.ms/dscv3-docs for more information on how to use DSC.exe.
169+
170+
Press any key to close this window
171+
";
172+
let sys = System::new_with_specifics(RefreshKind::new().with_processes(ProcessRefreshKind::new()));
173+
// get current process
174+
let Ok(current_pid) = get_current_pid() else {
175+
return;
176+
};
177+
178+
// get parent process
179+
let Some(current_process) = sys.process(current_pid) else {
180+
return;
181+
};
182+
let Some(parent_process_pid) = current_process.parent() else {
183+
return;
184+
};
185+
let Some(parent_process) = sys.process(parent_process_pid) else {
186+
return;
187+
};
188+
189+
if parent_process.name().to_lowercase() == "winstore.app.exe" || parent_process.name().to_lowercase() == "explorer.exe"{
190+
eprintln!("{message}");
191+
// wait for keypress
192+
let _ = io::stdin().read(&mut [0u8]).unwrap();
193+
exit(util::EXIT_INVALID_ARGS);
194+
}
195+
}

0 commit comments

Comments
 (0)