error NETSDK1100: To build a project targeting Windows on this operating system, set the
EnableWindowsTargeting property to true. appears when the .NET SDK runs on Linux, for example
in the mcr.microsoft.com/dotnet/sdk container or in WSL, and the project targets
net10.0-windows. Set the property, as the message says, and the build passes. The app
still cannot run there.
Add <EnableWindowsTargeting>true</EnableWindowsTargeting> to the project's
PropertyGroup, or pass -p:EnableWindowsTargeting=true to
dotnet build for a one-off build.
The error
Determining projects to restore...
/usr/share/dotnet/sdk/10.0.302/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(120,5): error NETSDK1100: To build a project targeting Windows on this operating system, set the EnableWindowsTargeting property to true. [/src/WinLab.csproj]
Build FAILED.
Why it happens
A Windows Forms or WPF project targets net10.0-windows and references the Windows
Desktop framework. To compile it, the SDK needs that framework's reference assemblies. A Linux SDK
refuses by default, at the framework-reference step named in the message, and the property is the
explicit opt-in it asks for. With it set,
restore in a fresh container fetched one extra package, microsoft.windowsdesktop.app.ref,
and compiled the project.
WSL is Linux too. With SDK 10.0.402 installed inside Ubuntu 24.04 under WSL, the same unchanged
project failed with the same NETSDK1100 line, and dotnet build
-p:EnableWindowsTargeting=true built it. Being on a Windows PC does not matter; what matters is
the operating system the SDK runs on.
The fix
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net10.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
</PropertyGroup>
</Project>
docker run --rm --name fix6-winforms -v ...\WinLab:/src -w /src mcr.microsoft.com/dotnet/sdk:10.0 dotnet build
Determining projects to restore...
Restored /src/WinLab.csproj (in 3.59 sec).
WinLab -> /src/bin/Debug/net10.0-windows/WinLab.dll
Build succeeded.
That is useful when a Linux build only has to compile the project, for example to check a pull request. It does not make the app run on Linux. Starting the built DLL in the same container failed, because the Windows Desktop runtime does not exist there:
You must install or update .NET to run this application.
App: /src/bin/Debug/net10.0-windows/WinLab.dll
Architecture: x64
Framework: 'Microsoft.WindowsDesktop.App', version '10.0.0' (x64)
.NET location: /usr/share/dotnet/
No frameworks were found.
To run or publish a Windows Forms or WPF app, build it on Windows. If only part of the code is
needed on Linux, move that part into a class library that targets plain net10.0.
How it was reproduced
On Windows 11 with .NET SDK 10.0.402 and Docker 29.9.2: a project from dotnet new winforms -n
WinLab --no-restore was mounted into the cached mcr.microsoft.com/dotnet/sdk:10.0
image, which carries SDK 10.0.302, and built with dotnet build. The WSL run used
Ubuntu 24.04.4 with SDK 10.0.402 installed for the test into a temporary folder by Microsoft's
dotnet-install.sh. The container name fix6-winforms is the test's own and
was removed after each run.
Frequently asked
- How do I build a WinForms or WPF project in a Linux Docker container?
- Set EnableWindowsTargeting to true in the project file or pass -p:EnableWindowsTargeting=true to dotnet build. The build then downloads the Windows Desktop reference package and compiles, but the output can only run on Windows.
- Why do I get NETSDK1100 in WSL on a Windows PC?
- Inside WSL the SDK runs on Linux, so it applies the same rule as any Linux machine. The same project built in WSL only after EnableWindowsTargeting was set.
- Can I run a net10.0-windows app on Linux after setting EnableWindowsTargeting?
- No. The property only allows the build. Starting the DLL on Linux fails with You must install or update .NET, because the Microsoft.WindowsDesktop.App framework does not exist there.
The "No frameworks were found" message has its own post for console and web apps: You must install or update .NET to run this application. More decoded errors are in the Fixes category.