diff --git a/build.ps1 b/build.ps1 index 20229cd3..7e32916f 100644 --- a/build.ps1 +++ b/build.ps1 @@ -7,7 +7,7 @@ param( $architecture = 'current', [switch]$Clippy, [switch]$SkipBuild, - [ValidateSet('msix','msixbundle','tgz','zip')] + [ValidateSet('msix','msix-private','msixbundle','tgz','zip')] $packageType, [switch]$Test, [switch]$GetPackageVersion, @@ -424,7 +424,7 @@ if ($packageType -eq 'msixbundle') { $msixPath = Join-Path $PSScriptRoot 'bin' 'msix' & $makeappx bundle /d $msixPath /p "$PSScriptRoot\bin\$packageName.msixbundle" return -} elseif ($packageType -eq 'msix') { +} elseif ($packageType -eq 'msix' -or $packageType -eq 'msix-private') { if (!$IsWindows) { throw "MSIX is only supported on Windows" } @@ -433,6 +433,8 @@ if ($packageType -eq 'msixbundle') { throw 'MSIX requires a specific architecture' } + $isPrivate = $packageType -eq 'msix-private' + $makeappx = Find-MakeAppx $makepri = Get-Item (Join-Path $makeappx.Directory "makepri.exe") -ErrorAction Stop $displayName = "DesiredStateConfiguration" @@ -440,14 +442,25 @@ if ($packageType -eq 'msixbundle') { $productName = "DesiredStateConfiguration" if ($isPreview) { Write-Verbose -Verbose "Preview version detected" - $productName += "-Preview" + if ($isPrivate) { + $productName += "-Private" + } + else { + $productName += "-Preview" + } # save preview number $previewNumber = $productVersion -replace '.*?-[a-z]+\.([0-9]+)', '$1' # remove label from version $productVersion = $productVersion.Split('-')[0] # replace revision number with preview number $productVersion = $productVersion -replace '(\d+)$', "$previewNumber.0" - $displayName += "-Preview" + + if ($isPrivate) { + $displayName += "-Private" + } + else { + $displayName += "-Preview" + } } Write-Verbose -Verbose "Product version is $productVersion" $arch = if ($architecture -eq 'aarch64-pc-windows-msvc') { 'arm64' } else { 'x64' } @@ -519,7 +532,7 @@ if ($packageType -eq 'msixbundle') { throw "Failed to create msix package" } - Write-Host -ForegroundColor Green "`nMSIX package is created at $packageName.msix" + Write-Host -ForegroundColor Green "`nMSIX package is created at $packageName" } elseif ($packageType -eq 'zip') { $zipTarget = Join-Path $PSScriptRoot 'bin' $architecture 'zip' if (Test-Path $zipTarget) { diff --git a/dsc/src/main.rs b/dsc/src/main.rs index 655c952c..d516c727 100644 --- a/dsc/src/main.rs +++ b/dsc/src/main.rs @@ -26,6 +26,9 @@ fn main() { #[cfg(debug_assertions)] check_debug(); + #[cfg(windows)] + check_store(); + if ctrlc::set_handler(ctrlc_handler).is_err() { error!("Error: Failed to set Ctrl-C handler"); } @@ -156,3 +159,38 @@ fn check_debug() { } } } + +// Check if the dsc binary parent process is WinStore.App or Exploerer.exe +#[cfg(windows)] +fn check_store() { + let message = r" +DSC.exe is a command-line tool and cannot be run directly from the Windows Store or Explorer. +Visit https://aka.ms/dscv3-docs for more information on how to use DSC.exe. + +Press any key to close this window +"; + let sys = System::new_with_specifics(RefreshKind::new().with_processes(ProcessRefreshKind::new())); + // get current process + let Ok(current_pid) = get_current_pid() else { + return; + }; + + // get parent process + let Some(current_process) = sys.process(current_pid) else { + return; + }; + let Some(parent_process_pid) = current_process.parent() else { + return; + }; + let Some(parent_process) = sys.process(parent_process_pid) else { + return; + }; + + // MS Store runs app using `sihost.exe` + if parent_process.name().to_lowercase() == "sihost.exe" || parent_process.name().to_lowercase() == "explorer.exe"{ + eprintln!("{message}"); + // wait for keypress + let _ = io::stdin().read(&mut [0u8]).unwrap(); + exit(util::EXIT_INVALID_ARGS); + } +}