NuGet / Home

Repo for NuGet Client issues
Other
1.5k stars 252 forks source link

[Question] - Pack Native dependencies #7479

Open rainersigwald opened 6 years ago

rainersigwald commented 6 years ago

From @deinok on November 3, 2018 16:54

Hi, I'm searching the internet for this information, trying to reproduce what other libs, etc.. But I can't find a way to do the following:

Imagine that I want to create library for https://github.com/intel-iot-devkit/mraa So I create a netstandard2.0 called Mraa.runtime.linux-arm that just have a a folder like this runtimes/linux-arm/native/ and inside that folder I put the generated libmraa.so for linux-arm

Inside Mraa.runtime.linux-arm.csproj is something like this:

<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <RuntimeIdentifier>linux-arm</RuntimeIdentifier>
        <TargetFramework>netstandard2.0</TargetFramework>
    </PropertyGroup>

    <ItemGroup>
        <Content CopyToOutputDirectory="PreserveNewest"
            Include="runtimes/linux-arm/native/**/*"
            Pack="true"
            PackagePath="runtimes/linux-arm/native/"/>
    </ItemGroup>

</Project>

But due the fact that I have to support diferent RIDs I create a Mraa.runtime.linux-x64 with the same aproach but for linux-x64, and the list could continuate for diferent RIDs

Now, I create a Mraa.runtimes that just referenciate all the specific RIDs, like this:

<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFramework>netstandard2.0</TargetFramework>
    </PropertyGroup>

    <ItemGroup>
        <ProjectReference Include="..\Mraa.runtime.linux-x64.csproj" />
        <ProjectReference Include="..\Mraa.runtime.linux-arm.csproj" />
                <!--Other runtimes-->
    </ItemGroup>

</Project>

What I'm doing wrong? I expect that when working with OS Any and Arch Any, unpack everything. If publish with Os Any and Arch Any, unpack everything. If a project have just unpack that required runtimes. If publish with --runtime linux-arm just publish the linux-arm .so Also, can I pack inside runtime/<rid>/native/ executable files, like .exe, .py, .ps1, .cmd, .sh?

Can somebody point me to a standard documentation, or a convention?

Copied from original issue: Microsoft/msbuild#3909

deinok commented 6 years ago

Thanks @rainersigwald

jainaashish commented 6 years ago

Look at https://docs.microsoft.com/en-us/nuget/create-packages/supporting-multiple-target-frameworks to understand how to create package which targets multi tfms or multi runtimes. It also has bunch of end-to-end examples to create UWP libraries for different tfms/ rids which should also help understand better.

deinok commented 6 years ago

@jainaashish Okey, that documentation is really bad. The doc tell how should look like the nupkg. But they dont tell how to do it via a *.csproj. The way to do it is like this for example:

        <Content CopyToOutputDirectory="PreserveNewest"
            Include="runtimes/linux-arm/native/**/*"
            Pack="true"
            PackagePath="runtimes/linux-arm/native/"/>

But my real interest is how to do the following: dotnet publish | No RID defined -> All runtimes are published dotnet publish -r <rid> | RID defined -> Just valid RIDs runtimes are published.

So, how are the runtimes folder extracted? Is there a better way I can pack this runtimes inside a *.nupkg? How are handled the runtimes folder at runtime?