Quantcast
Channel: Active questions tagged nuget-package - Stack Overflow
Viewing all articles
Browse latest Browse all 3067

NuGet package targets - how to copy files to subfolder of target dir on build?

$
0
0

I'm trying to add two text files to my nuget package so that when the user of the package builds the project, one file is copied to the root of the build directory, but another file is copied to a subfolder of the root like this

\bin\Debug\ - 1.TXT            - SubFolder\  - 2.TXT

This directory structure is a requirement of the assemblies in the package which will be looking for those files in those particular locations at runtime.

Based on this https://stackoverflow.com/a/30386836/1462656and this https://stackoverflow.com/a/44752745/1462656

I am able to create a targets file that copies 1.txt to the root, but when I add the package to a project and build it, it just copies 2.txt to the root. I created a build folder as follows

enter image description here

And my targets file looks like this

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"><ItemGroup><None Include="$(MSBuildThisFileDirectory)1.txt"><Link>1.txt</Link><CopyToOutputDirectory>Always</CopyToOutputDirectory></None><None Include="$(MSBuildThisFileDirectory)SubFolder\2.txt"><Link>2.txt</Link><CopyToOutputDirectory>Always</CopyToOutputDirectory></None>  </ItemGroup></Project>

How do you get it to create the SubFolder and copy the file to that folder?

Initially I was using the content folder to add my content files with subfolders to the nuget package, but I found that although the files were added with the correct directory structure to the solution itself, the files were added with attributes set to 'Do Not Copy' so they were not copied to the build directory - so I switched to the above approach instead. Is there a way to combine the two approaches?


Viewing all articles
Browse latest Browse all 3067

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>