具有本地依赖项的Meta-Package NetStandard2.0库

时间:2018-08-14 14:22:13

标签: .net-core nuget package

我有一个带有NetStandard2.0包装器的C ++库;该库具有针对Windows,Linux和MacOS的专门版本。我可以仅在此平台上生成特定于每个平台的.Net包装器和共享库(即无交叉编译)。

注意:您可以在以下位置找到此示例:https://github.com/Mizux/dotnet

本地OS库:Mizux.Foo。*-x64.npkg

例如:
在Linux-x64上:

Native.cpp -> Native.so -------+
Native.cpp -> Native.linux.cs -+-> Foo.linux-x64.csproj -> Mizux.Foo.linux-x64.npkg

src:https://github.com/Mizux/dotnet/blob/master/src/Foo.linux-x64/Foo.linux-x64.csproj

在osx-x64上:

Native.cpp -> Native.dylib --+
Native.cpp -> Native.osx.cs -+-> Foo.osx-x64.csproj -> Mizux.Foo.osx-x64.npkg

src:https://github.com/Mizux/dotnet/blob/master/src/Foo.osx-x64/Foo.osx-x64.csproj

在win-x64上:

Native.cpp -> Native.dll ----+
Native.cpp -> Native.win.cs -+-> Foo.win-x64.csproj -> Mizux.Foo.win-x64.npkg

src:https://github.com/Mizux/dotnet/blob/master/src/Foo.win-x64/Foo.win-x64.csproj

因此,我可以为此操作系统在每个操作系统中生成一个本地软件包。

问题1:我的nuget包布局正确吗?

unzip -l package/Mizux.Foo.linux-x64.1.0.0.nupkg
Archive:  package/Mizux.Foo.linux-x64.1.0.0.nupkg
  Length      Date    Time    Name
---------  ---------- -----   ----
      509  2018-08-14 15:47   _rels/.rels
      498  2018-08-14 15:47   Mizux.Foo.linux-x64.nuspec
     3584  2018-08-14 13:33   runtimes/linux-x64/lib/netstandard2.0/Mizux.Foo.linux-x64.dll # .CS which load the native.so -> should be in the same repository
        0  2018-08-09 12:04   runtimes/linux-x64/lib/netstandard2.0/native.so
      520  2018-08-14 15:47   [Content_Types].xml
      633  2018-08-14 15:47   package/services/metadata/core-properties/d5f8836b446941b1a8eb822b3c4e009c.psmdcp
---------                     -------
     5744                     6 files

因此,我在这里将文件放在runtimes/linux-x64/lib/netstandard2.0中,但是在使用dotnet build --runtime win-x64 src/Foo.linux-x64时,文件放在[bin/Debug/]netstandard2.0/linux-x64/*中,那么我是否需要将文件放在lib/linux-x64/netstandard2.0中? >

元包装:Mizux.Foo.npkg

然后,我想创建一个元软件包Mizux.Foo,其中包含三个依赖项,PackageReference(假设我复制了过去在本地软件包文件夹中生成的所有依赖项)。

package/Mizux.Foo.linux-x64 -+
package/Mizux.Foo.osx-x64 ---+-> Foo.csproj -> Mizux.Foo.nupkg
package/Mizux.Foo.win-x64 ---+

src:https://github.com/Mizux/dotnet/blob/master/src/Foo/Foo.csproj

我设法在nuget包内使用.csproj和Mizux.Foo.nuspec创建nupkg,

<dependencies>
  <group targetFramework=".NETStandard2.0">
    <dependency id="Mizux.Foo.linux-x64" version="1.0.0" exclude="Build,Analyzers" />
    <dependency id="Mizux.Foo.osx-x64" version="1.0.0" exclude="Build,Analyzers" />
    <dependency id="Mizux.Foo.win-x64" version="1.0.0" exclude="Build,Analyzers" />
  </group>
</dependencies>

使用Foo.csproj的FooApp

到目前为止一切都很好???
如果我在Foo.csproj上使用ProjectReference并在RuntimeIdentifier上使用条件,则可以成功构建一个FooApp。

dotnet build --runtime linux-x64 src/FooApp
dotnet src/FooApp/bin/Debug/netcoreapp2.1/linux-x64/Mizux.FooApp.dll

src:https://github.com/Mizux/dotnet/blob/master/src/FooApp/FooApp.csproj

这有效,但实际上它创建了一个退化的项目,其中Foo.osx-x64和Foo.win-x64被忽略(在本地测试时很酷,而在构建元包时则很酷……)

旁注:dotnet run --runtime linux-x64 --project src/FooApp无法运行,因为RuntimeIdentifier被忽略,因此它尝试重建为纯.Net项目并查看bin / debug / netstandard2.0 ...

使用Mizux.Foo.nupkg的示例

到目前为止一切都很好???
现在,我现在要创建一个Exemple的PackageReference Mizux.Foo软件​​包...

dotnet build -r linux-x64 example/Example
Program.cs(8,7): error CS0103: The name 'Foo' does not exist in the current context [/usr/local/google/home/corentinl/work/dotnet/example/Example/Example.csproj]
Build FAILED.

src:https://github.com/Mizux/dotnet/blob/master/example/Example/Example.csproj

问题2:这是什么问题,为什么示例没有看到运行时目录?

问题3:Foo似乎没有公开Foo。*-x64,即传递性无效,为什么?

0 个答案:

没有答案