错误NETSDK1136:目标平台必须设置为Windows

问题描述 投票:0回答:2

当我想在 iPad 上运行 iOS 项目时,我在 Visual Studio for Mac 2022 17.3.8 (build 5) 中收到此错误消息:

/usr/local/share/dotnet/sdk/6.0.402/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.DefaultItems.Shared.targets(5,5):错误NETSDK1136:目标平台必须使用 Windows 窗体或 WPF 或引用这样做的项目或包时,设置为 Windows(通常通过在 TargetFramework 属性中包含“-windows”)。

但我不知道这个错误来自哪里,因为我在我的iOS csproj文件中使用net6.0-ios,而我的SharedCode项目似乎没有csproj文件。

我的 iOS 项目出了什么问题?我应该改变什么?

编辑: 我在 Microsoft.NET.Sdk.DefaultItems.Shared.targets 文件中的这一行中收到错误:

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

我的 iOS 项目中的依赖项:

c# ios visual-studio-mac
2个回答
0
投票

您似乎正在尝试在 Mac/iOS 中运行 WPF 或 WinForms 应用程序(或者您的应用程序依赖于这些应用程序)。你不能这样做,因为 WPF/Winforms 仅限于 Windows。

尝试为多平台解决方案创建 Xamarin 或 MAUI 应用程序。


0
投票

据我所知,Xamarin.CommunityToolkit 使用 WPF 并导致我的项目出现错误。它对我有用,可以禁用该错误:

    <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>
© www.soinside.com 2019 - 2024. All rights reserved.