C# Deployment Scripts - external libraries

We want to deploy one of our apps to Microsoft Intune with a custom deployment script. Problem is it requires a few external references so that we can obtain access tokens etc.

Is there a way to reference external libraries in C# deployment scripts, via nuget for example? If so, are there any documentation available on this?

1 Like

Hi Kristian, thanks for reaching out.

It is possible to reference additional libraries in C# scripts using the instructions at https://github.com/scriptcs/scriptcs/wiki/Writing-a-script#referencing-assemblies. So the process would work like this.

  1. You bundle up all the dlls that you wish to reference into a package with the ID of bin (for example, in a file called bin.1.0.0.zip). It is important this file is called bin, because ScriptCS only loads dll files from a directory called ./bin. In this example I have saved the Octopus.Client.dll file from https://www.nuget.org/packages/Octopus.Client/ into a package called bin.1.0.0.zip.
  2. Upload the file bin.1.0.0.zip to the internal library.
  3. Create a C# script step where the first instructions are #r "Your.dll". For example I have loaded the Octopus.Client.dll file in the example script below.
#r "Octopus.Client.dll"
using Octopus.Client;

var endPoint = new OctopusServerEndpoint("https://master.octopushq.com", "API-APIKEY");
var repository = new OctopusRepository(endPoint);
var projects = repository.Projects.FindAll();
foreach (var project in projects) {
 	Console.Out.WriteLine(project.Name); 
}
  1. Add the bin package as an additional package reference, and make sure the package is extracted. This will result in the dll files you added to the bin package being extracted under a path called ./bin and made available to the C# script. In the screesnhot below you can see this example script and the additional package.

Regards
Matt C

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.