Executing Azure SDK operations during a deployment - best approach?

I’ve got a number of Azure objects that I’d like to create during a deployment. These include Azure Service Bus topics, DocumentDB collections, and Azure Scheduler jobs, all of which are not able to be created using the Azure PowerShell cmdlets or using Azure Resource Manager templates. So, I’ve been thinking about other ways of doing this within my deployment from Octopus.

I’ve been experimenting with using a scriptcs script, in combination with the references to the Azure SDK libraries that I’d need to use for these tasks. This seemed like a nice option, but after spending several hours trying to just get a scriptcs script to even run locally against the Azure SDK, I’ve been pretty frustrated. I haven’t been able to reference the SDK libraries/NuGet packages successfully from scriptcs. If I try to use the scriptcs package installer it fails with error 1 below. If I manually reference the DLL files I get error 2 below, seemingly because the scriptcs script is executing on version 4.0 of the framework rather than 4.5/4.6. So, I’m not sure if it’s even possible to interact with the Azure SDK libraries using scriptcs.

A second option I’ve considered, but haven’t yet tried, is to use PowerShell to create the .NET objects I need, by using PowerShell’s [System.Reflection.Assembly]::LoadFrom(...) capability.

A third option is to use the Azure REST API directly, rather than the SDK. I could then call it from a PowerShell script like this one. This will require a lot of work to get the actual calls and responses working though, and I don’t know if it’s worth it.

A fourth option is to write a console app in C#, and then have a script just execute that somehow. I’d really like to find a nicer way of making this work though.

Are there any options I’m missing? Thanks!

Error 1:

ERROR: Error installing package. [NuGetVersionNotSatisfiedException] The 'System.Net.Http 4.0.0' package requires NuGet client version '3.0' or above, but the current NuGet version is '2.8.60717.93'.

Error 2:

ERROR: Script compilation failed. [CompilationErrorException] C:\Temp\Script\mytest.csx(15,37): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

Hi,

Thanks for getting in touch. I think your best option for cases like yours, where you are on the edge of what is supplied in the PowerShell cmdlets, is to go with your fourth option.

Write a console app in C#. Then you can bundle it up in a simple package that Octopus can manage and include a simple, one line Deploy.ps1 powershell script that calls your console app. This approach allows you to easily nuget in all your dependencies and bundle them up in your package, and I like that you can feed it through your normal build pipeline to keep everything versioned and controlled.

Once you have that, you can run it using the “Run a script” step, and configure it to run your script on the server. Octopus will unzip your entire package before trying to run the script, so all your dependencies will be there. An example step configuration is shown here. Alternatively you can deploy it to a tentacle and Octopus will run your Deploy.ps1 automatically.

Note that you’ll also have access to Octopus variables in your Deploy script, so you can use that to hand command line parameters to your console app. See here for details.

I hope that helps.

Mark

Thanks Mark, that’s great.

I also just heard from Microsoft that they plan on adding some of the support I need in an upcoming Azure PowerShell update, so hopefully that will mitigate the need for some of this - but it’s good to know the best way if I do have to go down that track.

Thanks again.

John