-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Describe the bug
The docs state:
To make your app portable across different platforms but still have access to OS-specific APIs, you can target multiple OS-specific TFMs and add platform guards around OS-specific API calls using #if preprocessor directives.
I did this and most of the projects in the solution are targeting net6.0-windows;net6.0 if they have optional GUI components, and only net6.0 otherwise.
Now, when I ask dotnet to specifically target net6.0 when building in CI (so, Linux), it fails and complains about Windows regardless, even though it had no reason to even touch that. The same solution publishes flawlessly to Linux targets when building on Windows. Note that Sdk is not set to Microsoft.NET.Sdk.WindowsDesktop.
$ dotnet build TheSolution.sln -c Release -f net6.0
Microsoft (R) Build Engine version 17.0.0+c9eb9dd64 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
/usr/share/dotnet/sdk/6.0.101/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(90,5): error NETSDK1100: Windows is required to build Windows desktop applications. [/builds/foo/Project/Project.csproj]
Expected behavior
When I specify -f net6.0, it assumes TargetFramework = 'net6.0' for all projects and acts as if net6.0-windows weren't there.
To Reproduce
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0-windows;net6.0</TargetFrameworks>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<OutputType>Exe</OutputType>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework.EndsWith('windows'))">
<UseWindowsForms>true</UseWindowsForms>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
<DefineConstants>TARGET_WINDOWS</DefineConstants>
</PropertyGroup>
<ItemGroup Condition="!$(TargetFramework.EndsWith('windows'))">
<Compile Remove="MainForm.cs" />
<Compile Remove="MainForm.Designer.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.1" />
<PackageReference Include="System.Resources.Extensions" Version="6.0.0" />
</ItemGroup>
</Project>