harry_mitch
harry_mitch

Reputation: 167

Error NETSDK1136: The target platform must be set to Windows

I get this error message in Visual Studio for Mac 2022 17.3.8 (build 5) when I want to run my iOS project on my iPad:

/usr/local/share/dotnet/sdk/6.0.402/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.DefaultItems.Shared.targets(5,5): Error NETSDK1136: The target platform must be set to Windows (usually by including '-windows' in the TargetFramework property) when using Windows Forms or WPF, or referencing projects or packages that do so.

But I don't know where this error comes from because I use net6.0-ios in my iOS csproj file and my SharedCode project doesn't seem to have a csproj file.

What is wrong with my iOS project? What should I change?

EDIT: I get the error in this line in the file Microsoft.NET.Sdk.DefaultItems.Shared.targets:

    <NetSdkError Condition="'@(_WindowsDesktopTransitiveFrameworkReference)' != ''"
             ResourceName="WindowsDesktopTargetPlatformMustBeWindows" />

My dependencies in my iOS project:

Dependencies picture

Upvotes: 6

Views: 9004

Answers (3)

In project file (.csproj) you have to definition OutputType (for example Library). If not you got the error

Upvotes: 0

Burgler-dev
Burgler-dev

Reputation: 317

As far as I know Xamarin.CommunityToolkit uses WPF and caused the error in my project. It works for me to disable the error:

    <Target BeforeTargets="_CheckForTransitiveWindowsDesktopDependencies" Name="_FixSdkError_NETSDK1136">
        <ItemGroup>
            <TransitiveFrameworkReference Remove="Microsoft.WindowsDesktop.App" />
            <TransitiveFrameworkReference Remove="Microsoft.WindowsDesktop.App.WPF" />
            <TransitiveFrameworkReference Remove="Microsoft.WindowsDesktop.App.WindowsForms" />
        </ItemGroup>
    </Target>

Upvotes: 5

LoLo2207
LoLo2207

Reputation: 118

It seems you're trying to run a WPF or WinForms application (or your application has a dependency on these) in Mac/iOS. You can't do that as WPF/Winforms are Windows only.

Try creating a Xamarin or MAUI app for a multiplatform solution.

Upvotes: 0

Related Questions