1

I have created a nuget package with this structure:

NugetName/lib/net/*.dll

NugetName/contentFiles/A/*.dll

NugetName/contentFiles/B/*.dll


> <?xml version="1.0" encoding="utf-8"?> <package
> xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">  
> <metadata>
>     <id>..</id>
>     <version>1.0.0.22</version>
>     <title>...</title>
>     <authors>...</authors>
>     <owners>..</owners>
>     <requireLicenseAcceptance>false</requireLicenseAcceptance>
>     <description>...</description>     
>     <contentFiles>
>       <files include="contentFiles\A" buildAction="content" copyToOutput="true" flatten="true" />       
>       <files include="contentFiles\B" buildAction="content" copyToOutput="true" flatten="true" />
>     </contentFiles> 
>  </metadata> 
>  <files>
>     <file src="Build\Debug\*.dll" target="lib\net\" />
>     <file src="Build\Debug\A\*.dll" target="contentFiles\A"  />   
>     <file src="Build\Debug\B\*.dll" target="contentFiles\B"  />   
>  </files>    
> </package>

And now, I need to copy the folders A and B into the project's output folder, but it does not do that! After installing the nuget package, only the NugetName/lib/net/*.dll files are copied, but A and B are not!

1 Answers1

0

After testing the different ways I came up with this solution. First, I sent the dll files into the Build folder instead of the content folder.

<files>
    <file src="Build\Debug\*.*" target="lib\net\" />
    <file src="Build\Debug\A\*.dll" target="build\A"  />    
    <file src="Build\Debug\B\*.dll" target="build\B"  />    
    <file src="MyTargetFile.targets" target="build\MyTargetFile.targets" />
</files>

Then, I created a target file in the Build folder. This is the new structure of my nuget package:

 •Build
   •A
      •*.dll
   •B
      •*.dll
   •MyTargetFile.target

 •lib
  • net
     •*.dll

In the target file I defined how to copy the folder by MsBuild:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
 <ItemGroup>
    <NativeLibs Include="$(MSBuildThisFileDirectory)**\*.dll" />
    <None Include="@(NativeLibs)">
      <Link>%(RecursiveDir)%(FileName)%(Extension)</Link>
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>
</Project>

Finally I created the new nuget package and installed it, and when I built the project, folders A and B are copied into the output folder.