NuSpec File Element

This document describes the <file> element used in the NuSpec format.

The file element has two attributes, src and target. The src describes which file or set of files (via a wildcard) to copy. The target describes where to copy the file to.

Let's look at some use cases:

Single assembly

Source: Foo.dll in the root folder.

<file src="foo.dll" target="lib" />

Result: Copies foo.dll to \lib\foo.dll

Single assembly in deep path

Source: Foo.dll in \bar\baz\foo.dll

<file src="bar\baz\foo.dll" target="lib" />

Result: copies foo.dll to \lib\foo.dll

Set of dlls from the bin

Source: Foo.dll, Bar.dll in the bin\release folder.

<file src="bin\release\*.dll" target="lib" />

Result: \lib\foo.dll, \lib\bar.dll

Notes: Everything up to the wildcard character is truncated from the source path when copying to the target.

DLLs for different frameworks

Source: lib\net40\foo.dll, lib\net20\foo.dll

<file src="lib\**" target="lib" />

Result: \lib\net40\foo.dll \lib\net20\foo.dll

Content Files

Source: \css\mobile\style1.css \css\mobile\style2.css

<file src="css\mobile\*.css" target="content\css\mobile" />

Result: \Content\css\mobile\style1.css \Content\css\mobile\style2.css

Content files with directory structure

Source: \css\mobile\style.css, \css\mobile\wp7\style.css, \css\browser\style.css

<file src="css\**\*.css" target="content\css" />

Result: \content\css\mobile\style.css \content\css\mobile\wp7\style.css \content\css\browser\style.css

Content File with deep path

Source: \css\cool\style.css

<file src="css\cool\style.css" target="Content" />

Result: \Content\style.css

Content File copied to Folder with dot in name

<file src="images\Neatpic.png" target="Content\images\" />

Result: \Content\images\\Neatpick.png

Note: Because the target "extension" doesn't match the src extension, NuGet treats it as a directory.

Content file with deep path and deep target

<file src="css\cool\style.css" target="Content\css\cool" />

Result: \Content\css\cool\style.css

Note: This also works:

<file src="css\cool\style.css" target="Content\css\cool\style.css" />

That works because the file extensions of the source and target match.

Content file copy and rename

<file src="ie\css\style.css" target="Content\css\ie.css" />

Result: \Content\css\ie.css

Last edited Nov 24, 2010 at 4:38 PM by Haacked, version 17