.Net Maui iOS Native Binding 创建 .Net Maui Nuget 包

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

我有一些 iOS 框架的 .net Maui Native iOS 绑定。我成功绑定了。但是,我想创建一个 .Net Maui 类库来使用 iOS 本机绑定。请参阅下面我的项目结构:

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFrameworks>net7.0;net7.0-android;net7.0-ios</TargetFrameworks>
        <!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
        <!-- <TargetFrameworks>$(TargetFrameworks);net7.0-tizen</TargetFrameworks> -->
        <UseMaui>true</UseMaui>
        <SingleProject>true</SingleProject>
        <ImplicitUsings>enable</ImplicitUsings>

        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">16.1</SupportedOSPlatformVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
    </PropertyGroup>

    <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net7.0-ios|AnyCPU'">
      <CreatePackage>false</CreatePackage>
    </PropertyGroup>
    <ItemGroup>
      <ProjectReference Include="..\NativeSdk.Android\NativeSdk.Android.csproj" />

      <ProjectReference Include="..\NativeSdk.iOS\NativeSdk.iOS.csproj" />
    </ItemGroup>
    <ItemGroup Condition=" '$(TargetFramework)' == 'net7.0-ios' ">
  <ProjectReference Include="Path\To\Your\iOSNativeBindingProject.csproj" />
</ItemGroup>
    <ItemGroup>
      <None Remove="Platforms\Android\Models\" />
      <None Remove="Platforms\Android\Aar\" />
      <None Remove="Platforms\Android\Aar\TransaktSDK.aar" />
    </ItemGroup>
    <ItemGroup>
      <Folder Include="Platforms\Android\Models\" />
      <Folder Include="Platforms\Android\Aar\" />
    </ItemGroup>
    <ItemGroup>
       <AndroidAarLibrary Include="Platforms\Android\Aar\TransaktSDK.aar">
          <AndroidSkipResourceProcessing></AndroidSkipResourceProcessing>
      </AndroidAarLibrary>
    </ItemGroup>
    <ItemGroup>
      <Compile Condition=" '$(EnableDefaultCompileItems)' == 'true' " Update="SecureServiceInfo.cs">
        <ExcludeFromCurrentConfiguration>true</ExcludeFromCurrentConfiguration>
      </Compile>
    </ItemGroup>
</Project>

我尝试在我的 Native 绑定项目中添加其他平台以避免兼容性问题。我还添加了条件来尝试仅使用 ios 进行编译。当我这样做时, apiDefinition 类中的所有文件都会中断。请参阅下面我的原生 iOS 项目

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
   <TargetFrameworks>net7.0-ios;net7.0;net7.0-android;net7.0-maccatalyst</TargetFrameworks>
    <Nullable>enable</Nullable>
    <ImplicitUsings>true</ImplicitUsings>
    <IsBindingProject>true</IsBindingProject>
  </PropertyGroup>

<!--  <ItemGroup>
    <Compile Remove="StructsAndEnums.cs" />
    <Compile Remove="ApiDefinitions.cs" />
  </ItemGroup>-->
  <ItemGroup>
    <ObjcBindingCoreSource Include="StructsAndEnums.cs" />
  </ItemGroup>
  <ItemGroup>
    <ObjcBindingApiDefinition Include="ApiDefinitions.cs" />
  </ItemGroup>
  <ItemGroup Condition="'$(TargetFramework)' == 'net7.0-ios'">
    <NativeReference Include="..\..\..\..\..\Downloads\nativeSKD_iOS\NativeSDK.xcframework">
      <Kind>Framework</Kind>
      <Frameworks>Foundation</Frameworks>
      <ForceLoad>True</ForceLoad>
    </NativeReference>
  </ItemGroup>
</Project>

我已经被这个问题困扰好几天了。我只想创建一个 maui 类库,包括我的本机 iOS 绑定项目

xamarin.forms xamarin.ios maui nuget-package class-library
1个回答
0
投票

为什么要创建 MAUI 类库?您可以直接在 .NET MAUI 应用程序项目中引用 iOS 绑定库创建的 dll。或者,您可以从 iOS 绑定库创建一个 nuget 并在 .NET MAUI 应用程序项目中使用它。

© www.soinside.com 2019 - 2024. All rights reserved.