Getting Started with WinGet Configuration

Recently, Microsoft announced the availability of DevHome with the goal of becoming the one stop shop for all things developer. Two important concepts that are available in the first iteration is DevDrive and WinGet Configuration. Both DevDrive and WinGet Configuration are actually features of Windows, the aim of DevHome is to provide a convenient way to access them. In this post we’re going to take a closer look at WinGet Configuration, how you can use WinGet Configuration to setup your development environment and how you might use a WinGet Configuration file in your Git repository to help contributors setup their environment.

If you’re not familiar with WinGet let’s cover a few little basics, starting with making sure you have WinGet installed and up to date. Install App Installer from the Microsoft Store.

WinGet Commands

The list command will display all the applications installed. In addition to the application Name, it lists the Id, Version and the Source of the application.

If you want more information about an application you can use the show command.

Here we’re using the -q argument with the Id of the Microsoft Azure Cosmos Emulator. The -q argument can be used if you have the Id, Name or Moniker of the application you want to see more information about.

The uninstall command can be used to remove applications. Here we’re using the Id of the application, so we don’t need to use the –Id argument.

One of the useful things about the uninstall command is that you can remove some of the bloat-ware that Windows now ships with. A shout out to Simon Cropp’s WinDebloat tool that you can use to bulk remove a lot of the unnecessary applications that come with Winodws.

Lastly, the install command can be used to install applications from either the WinGet (winget) or Microsoft Store (msstore) source. The install command takes the Id of the application as a parameter. For WinGet you can search the GitHub repository for the manifest (yaml) file for the application you want to install and extract the PackageIdentifier. For applications in the Microsoft Store you can search for the application you want and extract the Id from the share Url, as shown by the bold text in the following url:

https://www.microsoft.com/store/productid/9NBLGGH4NNS1

WinGet Configuration

Using WinGet to install/uninstall individual applications is great but with recent changes to WinGet you can use a configuration file to specify a number of applications that you want to install. For example the following configuration file (typically named configuration.dsc.yaml) includes Python v3.12 and WSL

# yaml-language-server: $schema=https://aka.ms/configuration-dsc-schema/0.2
properties:
  configurationVersion: 0.2.0
  resources:
    - resource: Microsoft.WinGet.DSC/WinGetPackage
      directives:
        description: Python 3.12
        allowPrerelease: true
      settings:
        id: Python.Python.3.12
        source: winget
    - resource: Microsoft.WinGet.DSC/WinGetPackage
      directives:
        description:  WSL
        allowPrerelease: true
      settings:
        id: "9P9TQF7MRM4R"
        source: msstore  

A couple of things to note:

  • Python 3.12 is from a WinGet manifest, so the source property is set to ‘winget’
  • WSL is from the Microsoft Store, so the source property is set to ‘msstore’
  • The id property for WSL needs to have quotes around it, otherwise the application won’t be found

To run a configuration file, use the configure argument.

Removing Applications

In order to remove an application, you need to set the ensure property (under the settings property) to a value of absent.

# yaml-language-server: $schema=https://aka.ms/configuration-dsc-schema/0.2
properties:
  configurationVersion: 0.2.0
  resources:
    - resource: Microsoft.WinGet.DSC/WinGetPackage
      directives:
        description: Paint (Removal)
        allowPrerelease: true
      settings:
        id: "9PCFS5B6T72H"
        source: msstore
        ensure: absent

Dependencies

Some applications have prerequisites or dependencies that need to be installed before the application. In this case, the dependency resource need to be assigned an id and then the application needs to use the dependsOn property.

In the following example the WSL application from the Microsoft Store is assigned the id of wslStore. The Ubuntu resource is defined in winget and dependsOn the resource wslStore. This will ensure WSL is installed before Ubuntu.

# yaml-language-server: $schema=https://aka.ms/configuration-dsc-schema/0.2
properties:
  configurationVersion: 0.2.0
  resources:
    - resource: Microsoft.WinGet.DSC/WinGetPackage
      id: wslStore
      directives:
        description:  WSL
        allowPrerelease: true
      settings:
        id: "9P9TQF7MRM4R"
        source: msstore  
    - resource: Microsoft.WinGet.DSC/WinGetPackage
      dependsOn:
        - wslStore
      directives:
        description:  Ubuntu 22.04 LTS
        allowPrerelease: true
      settings:
        id: Canonical.Ubuntu.2204
        source: winget 

Note: In this scenario wsl install still needs to be run in order to set Ubuntu as the active distribution.

Developer Mode

There are some predefined resources, such as Microsoft.Windows.Developer, which can be used to set the Windows DeveloperMode

# yaml-language-server: $schema=https://aka.ms/configuration-dsc-schema/0.2
properties:
  resources:
  configurationVersion: 0.2.0
    - resource: Microsoft.Windows.Developer/DeveloperMode
      directives:
        description: Enable Developer Mode
        allowPrerelease: true
      settings:
        Ensure: Present

VS Components

Another resource that is useful is Microsoft.VisualStudio.DSC which can be used to configure VSComponents. The following configuration installs the VSComponents specified in the .vsconfig file that’s located in a folder relative to the configuration file (the ${WinGetConfigRoot} is a well known variable that’s set by WinGet to be the folder of the configuration file. The VSComponents resource is dependent on the vsPackage resource which is used to install Visual Studio.

# yaml-language-server: $schema=https://aka.ms/configuration-dsc-schema/0.2
properties:
  configurationVersion: 0.2.0
  resources:
    - resource: Microsoft.WinGet.DSC/WinGetPackage
      id: vsPackage
      directives:
        description: Install Visual Studio 2022 Professional
        allowPrerelease: true
      settings:
        id: Microsoft.VisualStudio.2022.Professional
        source: winget
    - resource: Microsoft.VisualStudio.DSC/VSComponents
      dependsOn:
        - vsPackage
      directives:
        description: Install required VS workloads from project .vsconfig file
        allowPrerelease: true
      settings:
        productId: Microsoft.VisualStudio.Product.Community
        channelId: VisualStudio.17.Release
        vsConfigFile: '${WinGetConfigRoot}\..\.vsconfig'

If you’re setting up a GitHub repository, you should consider adding a configuration file (configuration.dsc.yaml) in a .configuration folder, and to define an approporiate .vsconfig file in the root of the repository. This way, anyone who wants to contribute to the repository can easily setup their environment by first cloning the repository and then running the configuration file.

DevHome

So far we’ve been driving WinGet from the command line. However, recently released DevHome with the aim that it will become the dashboard for developers. One of the early features of DevHome is the ability to run a WinGet configuration file.

After installing DevHome from the Microsoft Store, click the Machine Configuration item in the left navigation view. This will prompt you to locate a configuration file to run. Selecting a file will display a summary of the configuration.

Agree to proceed and click the Agree to proceed and click the Set up as admin button. Once the configuration has been invoked, you’ll see a summary.

Summary

As you can see WinGet, and specifically the use of a configuration file, can be a useful tool for setting up and configuring your development environment. It’s worth keeping track of WinGet and the features Microsoft is progressively rolling out, to make Windows the most productive developer platform.

Leave a comment