Press "Enter" to skip to content

Pass parameters from TeamCity to nuspec files

Aim: Pass parameters from TeamCity to nuspec files in order to set the solution configuration from TeamCity.

In TeamCity, create a new system parameter in the Parameters page of project. In this case, the parameter DatabaseConfiguration sets which solution configuration will be built (e.g. Full = all projects, Partial = only newly updated projects).
1 tc_system_parameter
In the Visual Studio (sln) build step, set Configuration to

%DatabaseConfiguration%

and set Command Line Parameters to

/p:OctoPackNuGetProperties=DatabaseConfiguration=%system.DatabaseConfiguration%

2 tc_build_parameters
In the SSDT projects, update the .nuspec files, e.g. update Accounts.nuspec to


<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Accounts</id>
<version>1.0.0.0</version>
<authors>Deirdre OLeary</authors>
<description>Package for Accounts</description>
</metadata>
   <files>
      <file src="\bin\$DatabaseConfiguration$\Deploy.ps1" />
      <file src="\bin\$DatabaseConfiguration$\Accounts.dacpac" target="Content" />
   </files>
</package>

This method is particularly useful for composite projects where the Accounts project has a reference (Same Database) to a snapshot of the Accounts-Base project (e.g. because Accounts-Base contains the “old” unchanging objects & Accounts contains only newly updated objects). In this case, to ensure that the Accounts-Base snapshot is included in the .nupkg, include the following line in the .nuspec file.


   <files>
      ...
      <file src="\bin\$DatabaseConfiguration$\Accounts-Base*.dacpac" target="Content" />
   </files>

When building from TeamCity, you will see the following warning in the log.


MSBuild command line parameters contain "/property:" or "/p:". It is recommended to define System Property on Build Parameters instead.

However, I have not yet found a way to pass the parameter to the .nuspec file without using “/p”.

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *