Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify configuration-specific folder in nuspec

Tags:

nuget

nuspec

The examples I've seen specify files to be included using a path relative to the location of the nuspec file, e.g.:

<file src=".\bin\Debug\SomeFile.dll" target="..." />

Is there a way to specify this in such a way that it will use the appropriate source directory depending on my build configuration: i.e.:

  • bin\Debug if I package with -Prop Configuration=Debug
  • bin\Release if I package with -Prop Configuration=Release
like image 218
Joe Avatar asked Nov 16 '16 09:11

Joe


1 Answers

TL;DR

Use the $configuration$ token.

Full Explanation

In the .nuspec file reference, under Replace Tokens, it defines the $configuration$ token as:

"Configuration used to build the assembly, defaulting to Debug. Note that to create a package using a Release configuration, you always use -properties Configuration=Release on the command line."

And continues with:

Tokens can also be used to resolve paths when you include assembly files and content files. The tokens have the same names as the MSBuild properties, making it possible to select files to be included depending on the current build configuration.

And then concludes with two examples:

For example, if you use the following tokens in the .nuspec file:

<files>
    <file src="bin\$configuration$\$id$.pdb" target="lib\net40\" />
</files>

And you build an assembly whose AssemblyName is LoggingLibrary with the Release configuration in MSBuild, the resulting lines in the .nuspec file in the package is as follows:

<files>
    <file src="bin\Release\LoggingLibrary.pdb" target="lib\net40" />
</files>
like image 100
mattyb Avatar answered Oct 01 '22 10:10

mattyb