5

I have a nuget spec file with the file spec:

   <files>
     <file src="content\App_Start\*" target="content\App_Start" />
     <file src="content\Views\*" target="content\Views" />
     <file src="content\web.config.transform" target="content" />
     <file src="readme.txt" target="" />
   </files>

This used to be:

   <files>
     <file src="content\*" target="content" />
     <file src="readme.txt" target="" />
   </files>

but that had odd behaviour as well (spefically the App_Start wasn't being included, though the extra content folder was still being added for the views ... see description below)

The project itself is arranged in the format

 \<root>
 |_ readme.txt
 |_ content
      |_ Views
      |    |_ Home
      |         |_ <viewname>.cshtml
      |         |_ <viewname2>.cshtml
      |_ App_Start
           |_ <PreprocessFilename>.cs.pp

What appears to be odd behavior to me however is that NuGet pack is producing a zip file with the structure:

 \<root>
 |_ readme.txt
 |_ content
      |_ content
      |    |_ Views
      |         |_ Home
      |              |_ <viewname>.cshtml
      |              |_ <viewname2>.cshtml
      |_ App_Start
      |    |_ <PreprocessFilename>.cs.pp
      |_ readme.txt

So with respect to nuget packaging file paths:

  • Why is readme.txt being duplicated in two places?
  • Why are the views being given a second 'content' sub folder? (while App_Start isn't)
  • How can I make the copy of my content folder reflect precisely what the actual structure is?
  • How can I return to the <file src="content\*" target="content" /> directive to make the nuspec file more "maintainable"

If it is relevant, I am using a .csproj file to create the package.

Alex C
  • 16,624
  • 18
  • 66
  • 98

2 Answers2

0

I am having the same issue, i was able to work around it but kinda a hack IMO. I would love to see a better solution so that my project can have the dir tree I intend in the final package but I needed this to work today so.......

what i had to do to get around this was pull all sub dir in the content dir out and place at the root level then in the set the target to the sub dir i wanted it to end up in.

<file src="Scripts\" target="content\Scripts" />
workabyte
  • 3,496
  • 2
  • 27
  • 35
0

The behavior seems to be that when you pack a .csproject nuget pack MyProject.csproj, it will first arrange the package accordingly to your project structure and then look at the nuspec for additional instructions. But there doesn't seem to be any way to have your nuspec remove content added in the previous step when you pack by the project.

Thus, if the default project structure leads to unwanted content in your package, you should rely on packing directly by the .nuspec instead. nuget pack MyProject.nuspec Then it will only fetch the content that is specified in your nuspec, in which you can define the content exactly how you want it.

If you have a big project that almost have the structure you want, it could be convenient to first build the package from the project, use Nuget Package Explorer to extract a nuspec from this package that you later adjust to fit your need and that you finally pack against. That way you don't have to build it from scratch.

Edit

Or... You could execute the packing with the -Exclude parameter on a .csproj where you tell it to ignore some specific files and write a custom specification for these files in the .nuspec that will be read automatically for additional data.

I personally find it to be more concise to have the .nuspec as your sole definition for your package though.

Alex
  • 14,104
  • 11
  • 54
  • 77