问题描述
我有一个 NuGet 包,它支持 3 种不同的 TF
,应该以 Non-sdk
(旧 csproj
格式)和 Sdk
(a新的)csproj
文件。我的 nugget 还包含适用于 Windows、Linux 和 Mac 操作系统的 native
库。
我遇到的唯一问题与本机库的处理有关。
我以这种方式配置它(也有涵盖非 Windows OS
的类似步骤):
<!--IsWindows is defined in the first steps-->
<ItemGroup Condition=" '$(IsWindows)' == 'true' ">
<Content Include="$(MyLibrariesPathInTheSolution)/nativeWindowsLibrary.dll">
<Pack>true</Pack>
<PackagePath>runtimes/win/native</PackagePath>
</Content>
</ItemGroup>
<ItemGroup Condition=" '$(IsWindows)' == 'true' ">
<Content Include="$(MyLibrariesPathInTheSolution)/nativeWindowsLibrary.dll">
<copyToOutputDirectory>PreserveNewest</copyToOutputDirectory>
<Link>nativeWindowsLibrary.dll</Link>
</Content>
</ItemGroup>
上述配置适用于 sdk
项目,但不包括 non-sdk
。因此,我在主要的 csproj
中又添加了一个步骤:
<ItemGroup Condition=" '$(IsWindows)' == 'true' ">
<Content Include="MyApp.targets">
<Pack>true</Pack>
<PackagePath>build</PackagePath>
</Content>
</ItemGroup>
其中 MyApp.targets 看起来像:
<?xml version="1.0" encoding="utf-8"?>
<!--IsWindows is also defined here,skipped this deFinition just to reduce the number of lines-->
<Project Toolsversion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Condition=" '$(IsWindows)' == 'true' ">
<Content Include="$(MSBuildThisFileDirectory)../runtimes/win/native/nativeWindowsLibrary.dll">
<copyToOutputDirectory>PreserveNewest</copyToOutputDirectory>
<Link>nativeWindowsLibrary.dll</Link>
</Content>
</ItemGroup>
</Project>
以上修复了消费者与 non-sdk
项目相关的问题,但如果消费者使用 xamarin
+ mac OS
会触发问题,因为该平台尝试处理 nativeWindowsLibrary.dll
({ {1}} 库也会被处理,但在构建过程中预计与 MacOS-built
) 不同,即使 Windows-built
上存在条件(在本例中为 OS = Windows
)。
所以,我的主要问题是关于如何为我们需要支持的上述情况创建 NuGet 包的任何指南(示例):
- 非 sdk 和 SDK csproj 文件
- 不同的目标框架
- 平台相关库(位于
false
中)
另外,对提供的配置有什么建议吗?
解决方法
这是 xamarin https://github.com/xamarin/xamarin-macios/issues/10337 中与 mono msbuild 问题相关的错误 https://github.com/mono/mono/issues/15569