Templating support for nuget pack in nuspec file

Sep 1, 2011 at 8:09 AM

I know that "nuget pack" supports passing Version to override the version number in the nuspec file, but having templating feature in nuspec could be useful too.

Let's say there is a project that contains more than one nuspec file, like one for Web, another for MVC, other for desktop and might be bunch of nuget sample packages.

Some day, I decided that I need to add one more author or change the license or project url or anything. I would rather love to change the settings in build script in one place rather than chaning all the nuspec files that I have.

Here is an example of the template nuspec file.

<?xml version='1.0'?>
<package xmlns='http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd'>
    <metadata>
        <id>Foo</d>
        <version>{{version}}</version>
        <authors>{{authors}</authors>
        <description>Some description</description>
        <language>en-US</language>
        <licenseUrl>{{licenseUrl}}</licenseUrl>
        <projectUrl>{{projectUrl}}</projectUrl>
        <iconUrl>{{iconUrl}}</iconUrl>
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <tags>some tags</tags>
        <dependencies>
            <dependency id='CodeContracts.Unofficial' version='{{codeContractsVersion}}'/>
        </dependencies>
    </metadata>
	<files>
		......
	</files>
</package>

 

then in command line

nuget pack foo.nuspec /t:version=1.0.0.0 /t:authors="a, b, c" /t:licenseUrl=http://a.com ..... /t:codeContractsVersion=1.2.0.0

/t stands for template

So it would then override the value in the nuspec file.

 

Developer
Sep 1, 2011 at 8:41 AM
Edited Sep 1, 2011 at 10:18 AM

We actually have this already. The way syntax is different but here's what you can do today:

 

<?xml version='1.0'?>
<package xmlns='http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd'>
    <metadata>
        <id>Foo</d>
        <version>$version$</version>
        <authors>$authors$</authors>
        <description>Some description</description>
        <language>en-US</language>
        <licenseUrl>$licenseUrl$</licenseUrl>
        <projectUrl>$projectUrl$</projectUrl>
        <iconUrl>$iconUrl$</iconUrl>
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <tags>some tags</tags>
        <dependencies>
            <dependency id='CodeContracts.Unofficial' version='$codeContractsVersion$'/>
        </dependencies>
    </metadata>
	<files>
		......
	</files>
</package>

 

then in command line

nuget pack foo.nuspec /p version=1.0.0.0;authors="a, b, c";licenseUrl=http://a.com;codeContractsVersion=1.2.0.0

:)

Sep 1, 2011 at 8:53 AM

awesome,  i must have missed this feature. in which version did it come out?

Developer
Sep 1, 2011 at 8:57 AM

1.4 I believe

Sep 1, 2011 at 10:10 AM

Seems like it should be this instead.

nuget pack foo.nuspec /p version=1.0.0.0 /p authors="a, b, c" /p licenseUrl=http://a.com /p codeContractsVersion=1.2.0.0

Developer
Sep 1, 2011 at 10:17 AM

it works that way without the colon as well so this:

nuget pack foo.nuspec /p a=1;b=2

and

nuget pack foo.nuspec /p a=1 /p b=2

Are the same.

Sep 1, 2011 at 10:24 AM

oops my mistake.

i was adding : after /p

nuget pack foo.nuspec /p:a=1;b=2