Nuke.Cola
Loading...
Searching...
No Matches
WingetTasks.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Threading.Tasks;
5using Nuke.Common;
6using Nuke.Common.IO;
7using Nuke.Common.Tooling;
8using Nuke.Common.Tools.PowerShell;
9using static Nuke.Cola.Cola;
10
11namespace Nuke.Cola.Tooling;
12
13/// <summary>
14/// Microsofts official command line package manager for windows.
15/// </summary>
16public static class WingetTasks
17{
18 internal static void Setup()
19 {
20 if (EnvironmentInfo.Platform == PlatformFamily.Windows)
21 {
22 var ps = """
23 -Command
24 {
25 $progressPreference = 'silentlyContinue';
26 Write-Information "Downloading WinGet and its dependencies...";
27 Invoke-WebRequest -Uri https://aka.ms/getwinget -OutFile Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle;
28 Invoke-WebRequest -Uri https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx -OutFile Microsoft.VCLibs.x64.14.00.Desktop.appx;
29 Invoke-WebRequest -Uri https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.8.6/Microsoft.UI.Xaml.2.8.x64.appx -OutFile Microsoft.UI.Xaml.2.8.x64.appx;
30 Add-AppxPackage Microsoft.VCLibs.x64.14.00.Desktop.appx;
31 Add-AppxPackage Microsoft.UI.Xaml.2.8.x64.appx;
32 Add-AppxPackage Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle;
33 }
34 """.AsSingleLine();
35
36 PowerShellTasks.PowerShell(
37 $"{ps:nq}",
38 workingDirectory: EnvironmentInfo.SpecialFolder(SpecialFolders.UserProfile)
39 );
40
41 var settingsFile = EnvironmentInfo.SpecialFolder(SpecialFolders.LocalApplicationData)
42 /"Packages"/"Microsoft.DesktopAppInstaller_8wekyb3d8bbwe"/"LocalState"/"settings.json";
43
44 settingsFile.WriteAllText(
45 """
46 {
47 "interactivity": {
48 "disable": true
49 }
50 }
51 """
52 );
53 }
54 }
55
56 /// <summary>
57 /// Get Winget or an error if setup has failed (or if we're not running on Windows).
58 /// </summary>
59 public static ValueOrError<Tool> EnsureWinget => ToolCola.Use("winget", Setup);
60
61 /// <summary>
62 /// Get Winget. It throws an exception if setup has failed (or if we're not running on Windows).
63 /// </summary>
64 public static Tool Winget => EnsureWinget.Get();
65}
static ValueOrError< Tool > Use(string tool, Action? setup=null)
Get a tool which should be in PATH, and provide an optional way to set it up automatically if it wasn...
Microsofts official command line package manager for windows.
static ValueOrError< Tool > EnsureWinget
Get Winget or an error if setup has failed (or if we're not running on Windows).
static Tool Winget
Get Winget. It throws an exception if setup has failed (or if we're not running on Windows).