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”.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Kevin Kline

Career and Technical Advice for the IT Professional

TroubleshootingSQL

Explaining the bits and bytes of SQL Server and Azure

SQL Authority with Pinal Dave

SQL Server Performance Tuning Expert

Powershellshocked

A blog about PowerShell and general Windows sysadmin stuff

Simon Learning SQL Server

I'm trying to become "better" at SQL Server and data - here's how I'm doing it!

%d bloggers like this: