09 Oct 2020
With NuGet it is possible to package and distribute content files similar to npm package manager. The following steps show how to add and consume a content folder.
For full source code see: github.com/WorkplaceX/Util/tree/master/NuGet
In the (*.csproj) add the following lines of code. It adds MyContent folder to the class library.
<ItemGroup> <None Include="MyContent\**" Pack="true" /> <Content Include="ClassLibrary.targets" PackagePath="build\ClassLibrary.targets" /> </ItemGroup>
Add a new file ClassLibrary.targets. It defines where to extract MyContent folder to in the consuming application.
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup> <SourceScriptFiles Include="$(MSBuildThisFileDirectory)..\content\**" /> </ItemGroup> <Target Name="CopyScriptsToProject" BeforeTargets="Build"> <Copy SourceFiles="@(SourceScriptFiles)" DestinationFolder="$(ProjectDir)MyContent\" /> </Target> </Project>
Then create the package by running Pack.
To verify falies are packet into NuGet as expected rename any (*.nupkg) file to (*.nupkg.zip) and open it.
In the consuming application add the (*.nupkg) file and build it. MyContent folder is copied from package to solution.