-
Notifications
You must be signed in to change notification settings - Fork 30
Enable running Microsoft Store Developer CLI commands via a new 'store' subcommand. #214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
66137a5
Enable running Microsoft Store Developer CLI commands via a new 'stor…
azchohfi e474de1
PR Feedback.
azchohfi e0cd4de
Added docs.
azchohfi 1793946
Merge branch 'main' into alzollin/msstoreCommand
azchohfi 2381b87
Merge branch 'main' into alzollin/msstoreCommand
azchohfi f7ecd5b
Merge branch 'main' into alzollin/msstoreCommand
azchohfi 1e82b0d
Merge branch 'main' into alzollin/msstoreCommand
azchohfi 5d533bb
Merge branch 'main' into alzollin/msstoreCommand
azchohfi f37604e
Merge branch 'main' into alzollin/msstoreCommand
azchohfi c529e7f
Merge branch 'main' into alzollin/msstoreCommand
azchohfi 9f78814
Merge branch 'main' into alzollin/msstoreCommand
nmetulev 95e357d
Merge branch 'main' into alzollin/msstoreCommand
azchohfi 34bdc27
Merge branch 'main' into alzollin/msstoreCommand
azchohfi b9457a9
Merge branch 'main' into alzollin/msstoreCommand
azchohfi 497dc55
Refactor MSStoreCLI install to use GitHub zip download
azchohfi d17794b
Update copyright.
azchohfi 6cff29f
Addressed PR feedback.
azchohfi b7acb51
Merge branch 'main' into alzollin/msstoreCommand
nmetulev 415695e
Merge branch 'main' into alzollin/msstoreCommand
azchohfi 0f1a7fc
Merge branch 'main' into alzollin/msstoreCommand
nmetulev 2166e9c
Merge branch 'main' into alzollin/msstoreCommand
nmetulev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Microsoft.Extensions.Logging; | ||
| using System.CommandLine; | ||
| using System.CommandLine.Invocation; | ||
| using WinApp.Cli.Services; | ||
|
|
||
| namespace WinApp.Cli.Commands; | ||
|
|
||
| internal class MSStoreCommand : Command | ||
| { | ||
| public MSStoreCommand() : base("store", "Run a Microsoft Store Developer CLI command.") | ||
| { | ||
| this.TreatUnmatchedTokensAsErrors = false; | ||
| } | ||
|
|
||
| public class Handler(IMSStoreCLIService msStoreCLIService, ILogger<MSStoreCommand> logger) : AsynchronousCommandLineAction | ||
| { | ||
| public override async Task<int> InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken = default) | ||
| { | ||
| var args = parseResult.UnmatchedTokens.ToArray(); | ||
|
|
||
| var msstoreArgs = args.ToArray(); | ||
azchohfi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| try | ||
| { | ||
| // Ensure the build tool is available, installing BuildTools if necessary | ||
| await msStoreCLIService.EnsureMSStoreCLIAvailableAsync(cancellationToken: cancellationToken); | ||
|
|
||
| var processStartInfo = new System.Diagnostics.ProcessStartInfo | ||
| { | ||
| FileName = "msstore", | ||
| Arguments = string.Join(" ", msstoreArgs.Select(a => a.Contains(' ') ? $"\"{a}\"" : a)), | ||
| RedirectStandardInput = false, | ||
| RedirectStandardOutput = false, | ||
| RedirectStandardError = false, | ||
| UseShellExecute = false, | ||
| CreateNoWindow = false | ||
| }; | ||
|
|
||
| using var process = System.Diagnostics.Process.Start(processStartInfo); | ||
| if (process == null) | ||
| { | ||
| logger.LogError("Failed to start process for MSStoreCLI."); | ||
| return 1; | ||
| } | ||
|
|
||
azchohfi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| await process.WaitForExitAsync(cancellationToken); | ||
| return process.ExitCode; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| logger.LogError("Error executing MSStoreCLI: {ErrorMessage}", ex.Message); | ||
| return 1; | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace WinApp.Cli.Services; | ||
|
|
||
| internal interface IMSStoreCLIService | ||
| { | ||
| Task EnsureMSStoreCLIAvailableAsync(CancellationToken cancellationToken = default); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Microsoft.Extensions.Logging; | ||
| using System; | ||
| using System.Diagnostics; | ||
|
|
||
| namespace WinApp.Cli.Services; | ||
|
|
||
| internal class MSStoreCLIService(ILogger<MSStoreCLIService> logger) : IMSStoreCLIService | ||
| { | ||
| public async Task EnsureMSStoreCLIAvailableAsync(CancellationToken cancellationToken = default) | ||
| { | ||
| if (!IsMSStoreCLIInPath()) | ||
| { | ||
| // MSStoreCLI is not in the path, proceed to install it via winget | ||
| var confirm = Program.PromptYesNo("MSStoreCLI not installed - install MSStore Developer CLI with winget (user interaction may be required)? (y/N) "); | ||
| if (!confirm) | ||
| { | ||
| throw new InvalidOperationException("MSStoreCLI is required but not installed."); | ||
| } | ||
|
|
||
| var args = "install \"Microsoft Store Developer CLI\" --source msstore"; | ||
azchohfi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| logger.LogDebug("Running winget with arguments: {Args}", args); | ||
|
|
||
| ProcessStartInfo installProcessStartInfo = new() | ||
| { | ||
| FileName = "winget", | ||
| Arguments = "install \"Microsoft Store Developer CLI\" --source msstore", | ||
azchohfi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| RedirectStandardInput = false, | ||
| RedirectStandardOutput = false, | ||
| RedirectStandardError = false, | ||
| UseShellExecute = false, | ||
| CreateNoWindow = false | ||
| }; | ||
|
|
||
| using Process? installProcess = Process.Start(installProcessStartInfo) | ||
| ?? throw new InvalidOperationException("Failed to start process to install MSStoreCLI."); | ||
|
|
||
| await installProcess.WaitForExitAsync(cancellationToken); | ||
| const int NoApplicableUpgradeFound = -1978335189; | ||
| if (installProcess.ExitCode != 0 && installProcess.ExitCode != NoApplicableUpgradeFound) | ||
| { | ||
| throw new InvalidOperationException("Failed to install MSStoreCLI via winget."); | ||
| } | ||
|
|
||
| logger.LogInformation("MSStoreCLI installation completed."); | ||
| } | ||
| } | ||
|
|
||
| private bool IsMSStoreCLIInPath() | ||
| { | ||
| string? pathEnv = Environment.GetEnvironmentVariable("PATH"); | ||
| if (string.IsNullOrEmpty(pathEnv)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| string[] paths = pathEnv.Split(Path.PathSeparator); | ||
| var isAvailable = paths.Any(p => | ||
| { | ||
| string fullPath = Path.Combine(p, "MSStore.exe"); | ||
| return File.Exists(fullPath); | ||
| }); | ||
| if (isAvailable) | ||
| { | ||
| logger.LogDebug("MSStoreCLI is available in PATH."); | ||
| } | ||
| return isAvailable; | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.