Swift on Windows Guide

First of all big thanks for bringing Swift to Windows.

Is there a step by step guide to building a Windows Desktop App using Swift for Windows? I have looked at search engines and most come up with how to write iOS software using Swift on Windows. Which is valid but I'm specifically looking to build a Windows App using Swift.

I'm aware of the compnerd's framework. But the question is how do I use it in Windows? Is there a step by step guide somewhere that I can follow along to get all the way to just writing Swift code and compiling an app?

Thanks for your consideration

1 Like

The Browser Company said they will publish a GUI library for Windows soon which wraps WinUI (they said WinIU 3 somewhere else). The application code looks good, see this video at 11:50. So I would maybe wait a little with a GUI on Windows (the package you mentioned was a little “too basic” a while ago, I do not know if this has changed much), but in the meantime you may become accustomed to the installation of Swift on Windows and how to use Visual Studio Code with the Swift extension by the Swift Server Group.

1 Like

Good to know! For a while I was going in circles thinking I must be doing something wrong (and I may well still be doing something wrong). I will work on getting Swift and VSCode working. Thanks!

For the basic stuff on Windows (setting up Swift and VS Code), I maintain this guide for my students:


This is an excellent start. Thanks!

OK, I am not the only one who maintains a separate guide. I think this is very helpful, but we should all work helping to get the according documentation on swift.org (which is already quite good) even better (I am mostly blaming myself here). The ultimate goal should be that our own guides become superfluous. Our own guides might also become outdated fast, e.g. the repair after a Visual Studio update should not be necessary any more.


Swift on Windows has been moving fast and it’s a challenge to maintain guides that can cover all releases. Perhaps that’s a topic for SSWG’s next meeting. I’m looking forward to some ultimate solution that’s reliable and both easy to read and maintain.

Has anyone successfully used the installation instructions on Swift.org - Windows Installation Options ?

The following command doesn't seem to work:

winget install Microsoft.VisualStudio.2019.Community —force —custom "—add Microsoft.VisualStudio.Component.Windows10SDK.19041 —add Microsoft.VisualStudio.Component.VC.Tools.x86.x64"

It fails for me with the following output:

No package found matching input criteria.
Package not found: Microsoft.VisualStudio.2019.Community
No package found matching input criteria.
Package not found: —force
No package found matching input criteria.
Package not found: —custom
No package found matching input criteria.
Package not found: —add Microsoft.VisualStudio.Component.Windows10SDK.19041 —add Microsoft.VisualStudio.Component.VC.Tools.x86.x64

I have a bit more success replacing 2019 with 2022, but the options -force and -custom don't seem to work, both in PowerShell and Command Prompt.

I can still use the graphical installer for Visual Studio, but unfortunately, after upgrading to Swift 5.9, I cannot build even Hello World anymore:

<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "AssertionReporting.h"
C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\shims/AssertionReporting.h:16:10: note: in file included from C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\shims/AssertionReporting.h:16:
#include "SwiftStdint.h"
C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\shims/SwiftStdint.h:28:10: error: 'stdint.h' file not found
#include <stdint.h>
<unknown>:0: error: could not build C module 'SwiftShims'
error: fatalError

Can you provide the WinGet version and repositories you’re using?

winget --version
winget source list

Looks like there’s a typo here caused by auto conversion from -- to . You can try again with all replaced by --.

A fix is up at Fix examples in Windows installation options by stevapple · Pull Request #415 · apple/swift-org-website · GitHub

Before digging into the problem, may I know if you’re using Windows on ARM? Since Visual Studio 2019 is not available for WoA, this could matter.

Version is v1.6.2701

Sources are
msstore https://storeedgefd.dsx.mp.microsoft.com/v9.0
winget https://cdn.winget.microsoft.com/cache

I'm using a regular Windows 11 on Intel.

Visual Studio 2019 Community doesn't seem to be available on winget (anymore?):

winget search VisualStudio
Name                                    Id                                        Version      Match             Source
Visual Studio Professional 2022 Preview Microsoft.VisualStudio.2022.Professional… 17.8.0       Tag: visualstudio winget
Visual Studio Enterprise 2022 Preview   Microsoft.VisualStudio.2022.Enterprise.P… 17.8.0       Tag: visualstudio winget
Visual Studio Community 2022 Preview    Microsoft.VisualStudio.2022.Community.Pr… 17.8.0       Tag: visualstudio winget
IsWiX                                   IsWiX.IsWiX                          Tag: visualstudio winget
Microsoft Visual Studio Code Insiders   Microsoft.VisualStudioCode.Insiders       1.83.0                         winget
Microsoft Visual Studio Code            Microsoft.VisualStudioCode                1.82.2                         winget
Visual Studio Locator                   Microsoft.VisualStudio.Locator            3.1.7                          winget
Visual Studio Configuration Finder      Microsoft.VisualStudio.ConfigFinder                   winget
Visual Studio Professional 2022         Microsoft.VisualStudio.2022.Professional  17.7.4                         winget
Visual Studio Enterprise 2022           Microsoft.VisualStudio.2022.Enterprise    17.7.4                         winget
Visual Studio Community 2022            Microsoft.VisualStudio.2022.Community     17.7.4                         winget
Visual Studio BuildTools 2022           Microsoft.VisualStudio.2022.BuildTools    17.7.4                         winget
Visual Studio Professional 2019         Microsoft.VisualStudio.2019.Professional  16.11.30                       winget
Visual Studio Enterprise 2019           Microsoft.VisualStudio.2019.Enterprise    16.11.30                       winget
Visual Studio BuildTools 2019           Microsoft.VisualStudio.2019.BuildTools    16.11.30                       winget

cc @compnerd, it seemed MS doesn't want to support VS Community 2019 in WinGet any more.

We have to either go with Visual Studio 2019 Build Tools or Visual Studio 2022 Community. I would suggest the latter, and we'd better drop hard-coded VS 2019 dependency in WinGet manifests, until the dependency selection/alternative/... feature is implemented.

After replacing the dashes, and changing 2019 to 2022, the command works

I also noticed that when installing Swift.Toolchain next, it installs the Visual Studio build tools:

This package requires the following dependencies:
  - Packages
      Microsoft.VCRedist.2015+.x64 [>= 14.28.29913.0]
Installing dependencies:
(1/2) Found Microsoft Visual C++ 2015-2022 Redistributable (x64) [Microsoft.VCRedist.2015+.x64] Version 14.38.32919.0
This application is licensed to you by its owner.
Microsoft is not responsible for, nor does it grant any licenses to, third-party packages.
Downloading https://download.visualstudio.microsoft.com/download/pr/02a6d5c5-3e10-47de-8025-d97a1321d3e3/5F60592799FAE0C82578112D4B621438FFC976AB39D848D8F7623F5705A83E27/VC_redist.x64.exe
  ██████████████████████████████  24.1 MB / 24.1 MB
Successfully verified installer hash
Starting package install...
Successfully installed

(2/2) Found Visual Studio BuildTools 2022 [Microsoft.VisualStudio.2022.BuildTools] Version 17.7.4
This application is licensed to you by its owner.
Microsoft is not responsible for, nor does it grant any licenses to, third-party packages.
Downloading https://download.visualstudio.microsoft.com/download/pr/e514a25b-a89d-4051-a63c-05ccd9be41e9/6ca2980598be2c888c3bb3b288c688a04b3fc1f1acb62d7c3cdaada47b36c3ea/vs_BuildTools.exe
  ██████████████████████████████  3.76 MB / 3.76 MB
Successfully verified installer hash
Starting package install...
Successfully installed

There seems to be some overlap between the two, but the setup works.

My other error (with SwiftShims) seems be to caused by me installing those Visual Studio components (Windows 10 SDK (10.0.19041.0) and MSVC v143 - VS 2022 C++ x64/x86 build tools (Latest)) through the graphical installer, just like I used to do before. Doing it this way, instead of using winget, causes that error.

If anyone can explain why that happens (and how it can be resolved), that would be helpful.

Also, is there a way to avoid the overlap between VS Community and the Build Tools?

The only way is to remove VS Build Tools and Windows SDK dependency in Swift's manifest. I think this is the right path given the complexity of Visual Studio and Windows SDK system.

LLVM on Windows also requires these two, but it didn't list them in the manifest, and the user can install any compatible version based on their preference.

1 Like

Bleh, that is really rather annoying. I don't know if the older releases are guaranteed to work with future releases :frowning:.

I agree with your suggestion - updating to VS2022 is the right thing to do, and dropping the VS2019 dependency seems very reasonable.

Perhaps we should follow suit here. I was hoping that we could make it easier to say just install Swift.Swift and get everything, but it seems to just be causing more trouble. It would be great if we could add some notes in the install via winget so that someone searching for swift and installing it without instructions would know this is needed. Maybe I am overthinking this.

Done for Swift 5.9.0. I’ll try to back-port to older versions in some day, but since WinGet only allow updating one version at a time, it can lead to a huge number of PRs.

1 Like

If we can package VCRedist MSM in Swift toolchain installer, one more dependency can be dropped. It feels like the dependency system in WinGet isn’t quite robust…

I noticed that, thanks!

Should I also bump the Windows 10 SDK version? The winget command installs version 19041, but the manifest says version 22000. I'm currently using 19041, and it seems to work fine.

19041 is the default for VS 2019 and 22000 is for VS 2022. I’m proposing to bump both requirements, so in your case it’s better to use 22000.

But 19041 should work. It doesn’t have compatibility issue with VS 2022, just a little bit old.

@stevapple Version 10.0.22000 seems to be the Windows 11 SDK? Will this work on Windows 10 as well? In other words, will the following command work on both Windows 10 and 11, or do we need separate commands for both platforms?

winget install Microsoft.VisualStudio.2022.Community --force --custom "--add Microsoft.VisualStudio.Component.Windows11SDK.22000 --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64"
1 Like