Nuget 包,带有用于 sdk 和非 sdk 项目类型的本机库并支持多目标net452、netstandard20、netstandard21

如何解决Nuget 包,带有用于 sdk 和非 sdk 项目类型的本机库并支持多目标net452、netstandard20、netstandard21

我有一个 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 中)

另外,对提供的配置有什么建议吗?

解决方法

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?