Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly does EnableWindowsTargeting do?

Tags:

.net-core

I had a problem that I could not compile a .NET 6 project because it targets Windows but I'm working on MacOS. This is part of the .csproj file:

<OutputType>WinExe</OutputType>
<TargetFramework>net60-windows</TargetFramework>
<UseWPF>true</UseWPF>

When looking at the console output I saw the following interesting:

/usr/local/share/dotnet/sdk/6.0.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(90,5): error NETSDK1100: To build a project targeting Windows on this operating system, set the EnableWindowsTargeting property to true

If I just modify my project to this:

<OutputType>WinExe</OutputType> 
<TargetFramework>net60-windows</TargetFramework> 
<UseWPF>true</UseWPF> 
<EnableWindowsTargeting>true</EnableWindowsTargeting>

It then successfully compiles, but now I'm wondering what this actually does? I can't find that much documentation around that property, and the official docs only say it will download a runtime pack, but what exactly does that mean? I thought that when you specified <TargetFramework>netXX-windows</TargetFramework> it would, well, only run on Windows?

like image 312
Jim Aho Avatar asked Jan 18 '26 17:01

Jim Aho


2 Answers

Straight from the MSBuild reference for .NET SDK projects. Granted, the part about EnableWindowsTargeting was published about two weeks after the question was asked.

EnableWindowsTargeting

Set the EnableWindowsTargeting property to true to build Windows apps (for example, Windows Forms or Windows Presentation Foundation apps) on a non-Windows platform. If you don't set this property to true, you'll get build warning NETSDK1100. This error occurs because targeting and runtime packs aren't automatically downloaded on platforms that aren't supported. By setting this property, those packs are downloaded when cross-targeting.

ℹ Note

This property is currently recommended to allow development on non-Windows platforms. But when the application is ready to be released, it should be built on Windows. When building on a non-Windows platform, the output may not be the same as when building on Windows. In particular, the executable is not marked as a Windows application (which means that it will always launch a console window) and won't have an icon embedded.

like image 115
0xced Avatar answered Jan 21 '26 08:01

0xced


According to the dotnet docs on GitHub, setting this property to true allows you to build Windows apps on non-Windows platforms.

like image 31
Johannes Buchholz Avatar answered Jan 21 '26 08:01

Johannes Buchholz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!