Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Whiletru3 opened this issue Dec 11, 2019 · 3 comments
Closed

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

Whiletru3 opened this issue Dec 11, 2019 · 3 comments

Comments

@Whiletru3
Copy link

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 :

  • reference xxxnet.dll (c++/cli) in project
  • copy all native dlls in output path
  • copy the folder resources with all the files in output path

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

@karann-msft karann-msft transferred this issue from NuGet/docs.microsoft.com-nuget Dec 12, 2019
@sbraswell
Copy link

@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
Copy link
Author

Whiletru3 commented Apr 3, 2020

@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
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants