NuGet / Home

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

nuspec with dll, native and content in output folder #8926

Closed Whiletru3 closed 4 years ago

Whiletru3 commented 4 years ago

Hello

I try to create a nuget package with existing dlls and content files

I have to reference one dll (c++/cli), add some native dlls and copy to output and add one folder with files to output path. I read the nuspec documentation ( https://docs.microsoft.com/en-us/nuget/reference/nuspec ) but it is unclear...

Here is the folder structure : bin\xxx.dll -> all the binaries c++/cli and native resources*. -> all the content files

after install of nuget package, it should :

Here is my current nuspec file :

<?xml version="1.0"?>
<package  xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
  <metadata>    
    <id>xxx.x64</id>
    <version>15.5.3.3</version>
    <title>xxx toolkit</title>
    <authors>xxx</authors>
    <owners>xxx</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>xxx x64 Windows</description>
    <releaseNotes></releaseNotes>
    <copyright>2019</copyright>
    <tags></tags>
    <references>
        <reference file="xxxnet.dll" />
    </references>
    <!-- <contentFiles> -->
        <!-- <files include="ressources\*.*"  buildAction="None" copyToOutput="true" /> -->
        <!-- <files include="bin\xxx*.dll" exclude="bin\xxxnet.dll" flatten="true" buildAction="None" copyToOutput="true" /> -->
    <!-- </contentFiles> -->
  </metadata>
  <files>
    <file src="bin\xxxnet.dll" target="lib\any" />
    <file src="resources\*.*"  target="content\resources"  />
    <file src="bin\xxx*.dll" exclude="bin\xxxnet.dll" target="content" />
  </files>
</package>

I already tried contentFiles, references but it doesn't work and now i'm lost. Any example whould be great

Thanks

sbraswell commented 4 years ago

@Whiletru3 Did you ever figure out how to get this to work? I'm trying to package a 3rd party native library for my team to use on our internal Azure DevOps artifact feed.

I need to be able to include native binaries that aren't referenced by the project but are copied to the output folder of the project. Sounds like you were trying to accomplish something similar. Would appreciate any advice you may have. Thanks!

Whiletru3 commented 4 years ago

@sbraswell do you targeting .Net core ?

Here is how i got it worked for .net Core :

<package  xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
  <metadata>    
    <id>xxx.x64</id>
    <version>15.5.3.3</version>
    <title>xxx toolkit</title>
    <authors>xxx</authors>
    <owners>xxx</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>xxx x64 Windows</description>
    <releaseNotes></releaseNotes>
    <copyright>2019</copyright>
    <tags></tags>
    <contentFiles>
        <files include="**\resources\*.*"  buildAction="Content" copyToOutput="true" />
        <files include="**\*.dll" exclude="**\xxxnet15.dll" flatten="true" buildAction="Content" copyToOutput="true" />
    </contentFiles>
  </metadata>
  <files>
    <file src="bin\xxxnet15.dll" target="lib\netcoreapp3.0" />
    <file src="resources\*.*" target="contentFiles\any\any\resources"  />
    <file src="bin\*.dll" exclude="bin\xxxnet15.dll" target="contentFiles\any\any" />   
  </files>
</package>

if you target .net framework, it's a little more complicated...

You need a nuspec fie like this one

<package  xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
  <metadata>    
    <id>xxx.x64</id>
    <version>15.5.3.3</version>
    <title>xxx toolkit</title>
    <authors>xxx</authors>
    <owners>xxx</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>xxx x64 Windows to .net framework 4.6.1</description>
    <releaseNotes></releaseNotes>
    <copyright>2019</copyright>
    <tags></tags>
    <dependencies>
       <group targetFramework=".NETFramework4.6.1" />
    </dependencies>
    <tags></tags>
  </metadata>
  <files>
    <file src="bin\xxxnet.dll" target="lib\net461" />
    <file src="resources\*.*" target="build\resources"  />
    <file src="bin\*.dll" target="build" />
    <file src="xxx.Win.x64.targets" target="build" />
    <file src="install.ps1" target="tools" />
  </files>
</package>

the target file xxx.Win.x64.targets

  <ItemGroup>
    <NativeLibs Include="$(MSBuildThisFileDirectory)**\*.*" />
    <None Include="@(NativeLibs)">
      <Link>%(RecursiveDir)%(FileName)%(Extension)</Link>
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>
</Project>

and the install.ps1

$asms = $package.AssemblyReferences | %{$_.Name} 
foreach ($reference in $project.Object.References) 
{
    if ($asms -contains $reference.Name + ".dll") 
    {
        $reference.CopyLocal = $false;
    }
}

it was a nightmare to discover this ! :)

nkolev92 commented 4 years ago

Issue moved to NuGet/docs.microsoft.com-nuget #2038 via ZenHub