1

我正在尝试构建一个可以安装在 Xamarin.Android、Xamarin.iOS、Xamarin.UWP 和 Xamarin.Forms(.NET 标准)项目中的 NuGet 包。我不能使用 .NET Standard,因为我需要Activity为我的 Android 项目自定义AppDelegate、为我的 iOS 项目自定义,以及为我的 UWP 项目自定义 MainPage。在发起程序中,我想使用ServiceCollection作为 DI 提供程序。

在文档中,他们仍然提到Portable Class Library(明确提到的遗留,在 VS 中不再存在),或手动创建包(无法弄清楚在这里做什么),然后你也有网站Xamarin.Forms Plugin提到也不再存在。

我已经为所有 4 个项目制定了解决方案,但我不知道如何为所有 4 个项目(所有 3 个目标平台)创建单个 NuGet 包。

有谁知道我们如何构建一个包含 Android、iOS 和 UWP 代码的多目标 NuGet 包,就像Xamarin.Forms NuGet 包一样?

我还看到过这样的讨论:如何创建一个项目来为支持 iOS、Android 和 UWP 的 Xamarin Forms 创建 Nuget 包?,但我不确定这是否仍然相关,因为build.propsandbuild.targets不再存在于 MvvmCross 存储库中。

4

2 回答 2

1

起点是https://github.com/onovotny/MSBuildSdkExtras

一年前,我做了一个示例(并收集了一些文档和参考资料),这可能对这个主题很有启发:https ://github.com/ZeProgFactory/MSBuildSdkExtrasTest

并且https://github.com/ZeProgFactory/MediaPlayer正在使用它

最后,您应该在https://github.com/jamesmontemagno查看 James Montemagno 组件的存储库

有了这些参考资料,您应该可以开始了。但是所有这些都与您的方法有很大的不同:

  • 他们正在使用一个项目(通过 MSBuildSdkExtras),
  • 这是为所有平台构建的
  • 最后,将二进制文件组装到一个 NuGet 中。

也许你可能只采取这最后一步。无论如何,这种方法至少是一种选择。希望这会有所帮助……</p>

于 2020-07-25T11:27:55.857 回答
0

我已将工作版本推送到https://github.com/MintPlayer/MintPlayer.MVVM

csproj 文件

<Project Sdk="MSBuild.Sdk.Extras/2.0.41">

  <!-- You must have the Android 8.0 SDK installed through the Android SDK manager -->

  <PropertyGroup>
    <AssemblyName>MintPlayer.MVVM</AssemblyName>
    <RootNamespace>MintPlayer.MVVM</RootNamespace>
    <TargetFrameworks>netstandard2.0;Xamarin.iOS10;MonoAndroid80;uap10.0.16299</TargetFrameworks>
    <_WriteTelemetryProperties>false</_WriteTelemetryProperties>
    <Authors>Pieterjan De Clippel</Authors>
    <Company>MintPlayer</Company>
    <Product>MintPlayer.MVVM</Product>
    <IncludeSymbols>true</IncludeSymbols>
    <SymbolPackageFormat>snupkg</SymbolPackageFormat>
    <Description>This package allows you to implement ViewModel Navigation and Dependency Injection in a Xamarin.Forms project</Description>
    <Version>1.0.0</Version>
    <Copyright />
    <PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
    <PackageProjectUrl>https://github.com/MintPlayer/MintPlayer.MVVM</PackageProjectUrl>
    <RepositoryUrl>https://github.com/MintPlayer/MintPlayer.MVVM</RepositoryUrl>
    <PackageTags>Xamarin.Forms, Viewmodel navigation, Dependency Injection</PackageTags>
    <PackageReleaseNotes>This package is still under construction</PackageReleaseNotes>
  </PropertyGroup>

  <ItemGroup>
    <Compile Remove="Platforms\**\*.cs" />
    <None Include="Platforms\**\*.cs" />
    <None Include="Resources\*.cs" />
    <Compile Remove="Resources\*.cs" />
  </ItemGroup>

  <ItemGroup Condition=" $(TargetFramework.StartsWith('uap')) ">
    <Compile Include="Platforms\UAP\**\*.cs" />
    <Compile Include="Platforms\Common\**\*.cs" />
  </ItemGroup>

  <ItemGroup Condition=" $(TargetFramework.StartsWith('netstandard')) ">
    <Compile Include="Platforms\Common\**\*.cs" />
  </ItemGroup>

  <ItemGroup Condition=" $(TargetFramework.StartsWith('Xamarin.iOS')) ">
    <Compile Include="Platforms\iOS\**\*.cs" />
    <Compile Include="Platforms\Common\**\*.cs" />
  </ItemGroup>

  <ItemGroup Condition=" $(TargetFramework.StartsWith('MonoAndroid')) ">
    <Compile Include="Platforms\Android\**\*.cs" />
    <Compile Include="Platforms\Common\**\*.cs" />
    
    <AndroidResource Include="Resources\**\*.xml" SubType="Designer" Generator="MSBuild:UpdateAndroidResources" />
    <AndroidResource Include="Resources\**\*.axml" SubType="Designer" Generator="MSBuild:UpdateAndroidResources" />
  </ItemGroup>

  <ItemGroup>
    <None Remove="Platforms\Common\MintPlayerMvvmExtensions.cs" />
    <None Remove="Platforms\Common\NavigationService.cs" />
    <None Remove="Platforms\Common\Platform.cs" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.6" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.6" />

    <!--<PackageReference Include="Xamarin.Forms" Version="4.5.0.495" />-->
    <PackageReference Include="Xamarin.Forms" Version="3.1.0.697729" />
  </ItemGroup>

</Project>

目录.build.props

<Project>
  <PropertyGroup>
    <Company>MintPlayer</Company>
    <Copyright>Copyright © MintPlayer</Copyright>
    <RepositoryUrl>https://github.com/MintPlayer/MintPlayer.MVVM</RepositoryUrl>
    <Authors>Pieterjan De Clippel</Authors>
    <Owners>MintPlayer</Owners>
    <PackageReleaseNotes />
    <PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
    <PublishRepositoryUrl>true</PublishRepositoryUrl>
    <RepositoryType>git</RepositoryType>
    <Product>$(AssemblyName) ($(TargetFramework))</Product>
    <NeutralLanguage>en</NeutralLanguage>
    
    <LangVersion>latest</LangVersion>
    <NoWarn>$(NoWarn);1591;1701;1702;1705;VSX1000;NU1603</NoWarn>
    <GenerateDocumentationFile Condition=" '$(Configuration)' == 'Release' ">true</GenerateDocumentationFile>
    <GeneratePackageOnBuild Condition=" '$(Configuration)' == 'Release' and '$(IsTestProject)' != 'true'">true</GeneratePackageOnBuild>
    
    <Platform>AnyCPU</Platform>
    <DebugType>portable</DebugType>
    <AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
    <EmbedUntrackedSources>true</EmbedUntrackedSources>
    
    <IsTestProject>$(MSBuildProjectName.Contains('UnitTests'))</IsTestProject>
  </PropertyGroup>
</Project>

Directory.build.targets

<Project>
  <PropertyGroup Condition="$(TargetFramework.StartsWith('netstandard'))">
    <DefineConstants>$(DefineConstants);NETSTANDARD;PORTABLE</DefineConstants>
  </PropertyGroup>
  <PropertyGroup Condition="$(TargetFramework.StartsWith('Xamarin.iOS'))">
    <DefineConstants>$(DefineConstants);MONO;UIKIT;COCOA;IOS</DefineConstants>
  </PropertyGroup>
  <PropertyGroup Condition="$(TargetFramework.StartsWith('MonoAndroid'))">
    <DefineConstants>$(DefineConstants);MONO;ANDROID</DefineConstants>
    <MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
    <AndroidResgenClass>Resource</AndroidResgenClass>
    <AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
  </PropertyGroup>
</Project>

您必须将以下内容添加到您的.sln文件中

Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7004E39A-BAF2-4F2F-B505-CC3DEC393CB6}"
    ProjectSection(SolutionItems) = preProject
        Directory.build.props = Directory.build.props
        Directory.build.targets = Directory.build.targets
    EndProjectSection
EndProject
于 2020-07-27T22:38:32.710 回答