Note - this is a follow-up question to How do I create a Nuget package with Visual Studio 2017
My CodeFirstWebFramework NuGet package on GitHub needs to install a specifically named folder of content files in any project which uses it. These files are javascript, css, html, image and template files to support the web server the package creates. They need to be in a folder called CodeFirstWebFramework
, and need to be copied to the project output folder.
In the absence of specific documentation on how to do this, I have tried various experiments. I can create a folder called contentFiles
, with the CodeFirstWebFramework
folder inside it, and get the contentFiles
folder copied to the using project OK (although, pending an as yet unreleased update to VS 2017, this is not automatically copied to the output folder).
I tried putting the files in a CodeFirstWebframework
folder (i.e. removing contentFiles
from the hierarchy), and setting ContentTargetFolders
in the .csproj to .
. This copied the files into the package OK, but they were not copied out into the using project.
<ItemGroup>
<Content Include="CodeFirstWebFramework/**/*.*" copyToOutput="true">
<IncludeInPackage>true</IncludeInPackage>
<CopyToOutput>true</CopyToOutput>
<BuildAction>Content</BuildAction>
<copyToOutput>true</copyToOutput>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<PackageCopyToOutput>true</PackageCopyToOutput>
</Content>
</ItemGroup>
[Note there are some incorrect and unnecessary XML elements in the above, as part of my attempts to get this to do what I want - but this worked when the content was in a contentFiles folder]
I now realise I am not exactly being clear. My code is a DLL which runs a web server. It needs to be able to find certain js, html, etc. files and folders in a subfolder of the using project's output folder. It is currently expecting that subfolder to be called CodeFirstWebFramework
, but I could change that.
It is usual for the project using the DLL to have another folder, or even series of folders, where the DLL will also search for these files (so the project author can provide versions more suitable to their needs).
I would like these folders to be consistently named so they relate to the project (i.e. I am currently calling the one I supply CodeFirstWebFramework
, and the using project's one after the name of the using project).
If I use contentFiles/CodeFirstWebFramework
for mine, the using project would have to use contentFiles/ProjectName
for its ones - I imaging that would cause conflicts, wouldn't it?