I created a step which executes C# script using Octopus.Client but when executed, it fails with below error:
ERROR: Script compilation failed. [CompilationErrorException] C:\Octopus\Work\20221124025558-346424-11426\Script.csx(10,22): error CS0012: The type ‘Object’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘netstandard, Version=188.8.131.52, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51’.
Below is first few lines of code of Script which shows, how I referenced it
var octopusURL = "https://octopusdeploy.mycompany.co.nz/";
var octopusAPIKey = "";
var endpoint = new OctopusServerEndpoint(octopusURL, octopusAPIKey);
var repository = new OctopusRepository(endpoint);
Below is screen shot of settings of script execution details:
Since you are referencing the Octopus.Client library on the fly when deployed, and this is being deployed to a worker; the reference folder for the client will change each time. When a package is extracted for a script, it’s put into a “Work” folder with the folder made up of the date-time, thread number, and task count. Since it’s different every time, trying to do it in this way will be next to impossible since we don’t have any variables with the thread or task counts.
If you wish to use the client, I’d recommend making a custom worker and putting the client library somewhere you know so you can access it directly by referencing the file path at the top.
We also try to steer customers away from using the client library since some functionality is mismatched with the API, and sometimes desired data can’t be found. I’d recommend using web requests to query the API directly instead of utilising the client, but at the end of the day, it’s down to what you’d like to use.
If you have any further questions, please let me know!