I was experimenting on a nuget package project in Visual Studio 2022 Community Edition and my goal is to add a folder and a file to the nuget package which it would install in the root folder of the target project. It did not work. I don't know what was missing in the nuspec file but here are the steps I did:
- I've created 2 new C# Class library projects in .net 8 and named them MyPackage and TargetLibrary.
- I've created a contentFiles folder in the MyPackage project and added a test.js file inside it. Here is the test.js file:
alert("it works!");
- I've added a simple icon.png and created a MyPackage.nuspec file in the project root:
<?xml version="1.0"?><package> <metadata><id>MyPackage</id><version>3.0.6</version><description>A content sample package.</description><authors>Solomio Sisante</authors><owners>Solomio Sisante</owners><requireLicenseAcceptance>true</requireLicenseAcceptance><license type="expression">MIT</license><tags>content contentFiles</tags><icon>icon.png</icon><!-- Build actions for items in the contentFiles folder --><contentFiles><!-- Include Assets as Content --><files include="**/contentFiles/*.*" buildAction="None" copyToOutput="true" flatten="true" /></contentFiles> </metadata> <files> <file src="contentFiles\**" target="contentFiles" /> <file src="icon.png" target="icon.png" /> </files> </package>
Finally, I created the package by running the nuget pack command:
nuget pack Mypackage.nuspec -OutputDirectory bin\Release
When I tried to install it, it did not create the contentFiles folder or the test.js file.What am I missing here?