1

Description

I need to sign the nuget packages (MathNet.Numerics) before I build my project, to do this, I'm using Nivot.StrongNaming package, and I run the commands below in the Package Manager Console:

Install-Package Nivot.StrongNaming
$root = join-path (split-path $dte.solution.filename) packages
$solution = (split-path $dte.solution.filename)
$key = Import-StrongNameKeyPair -KeyFile $solution\MuProjectFolder\Key.snk
dir -rec  $root\MathNet.Numerics.3.11.0\*.dll | where { -not (Test-StrongName $_) } | Set-StrongName -KeyPair $key -Verbose

(NOTE I cannot use the signed version of the packages, since this is a shared project, it will break other projects...)

Question

Is there a way I can add these steps to TeamCity before it attempts to build the solution? That would ensure that we have it signed.

How can I run some Package Manager Console commands (Visual Studio) in a build step in the Team City project?

Can I run it as a Command Line?

A-Sharabiani
  • 17,750
  • 17
  • 113
  • 128

1 Answers1

2

I've done this assuming that Nivot.StrongNaming isn't a referenced package in packages.config - if it is then just ignore the relevant step to install the package.

I've also pinned the version number, so it's easier to import the powershell module file - Ultimately you might need to tinker with the paths to get it working in your environment, but conceptually it's fine.

  1. Save the following script to a .ps1 and add it to your version control - this way you know it'll be on the build agent when you need it. sign-assembly-using-nivot.ps1

  2. Create a build configuration with a command line step to install Nivot.StrongNaming (optional depending on my assumption) and a PowerShell step to run the script. I'm installing MathNet.Numerics only because I don't have a solution.

enter image description here

Command line runner to install Nivot.StrongNaming if required enter image description here

PowerShell runner to bootstrap script enter image description here

  1. Now create these variables to allow you to easily adjust the paths required for your environment.

enter image description here

Your build log should look something like this

enter image description here

Hope this helps.

Matt
  • 3,684
  • 1
  • 17
  • 19