Calling Script Module function inside of Script Step Template

Hi,

can I call a Script Module function (c#) inside of Script Step Template with inline C# Code ?

Thx.

Hi @applepi,

Thanks for getting in touch! You certainly can, and to do so you’d load a c# script module into your script step, and use the functions contained within. C# script modules are created as .csx files next to your script (so if your c# module is named CSharp Script Module, this will be created as CSharpScriptModule.csx). To load it in, you can use the following at the top of your c# script (using the same example name).

#load "CSharpScriptModule.csx"

I hope that helps. Let me know if you have any further questions or concerns moving forward. :slight_smile:

Best regards,

Kenny

Thank you Kenny!

Another question is, if I have a Script Modul written in C# and want use it in a Script Template with inline Code written in Powershell, is this possible ?

B.regards,
Johnny

Hi Johnny,

Thanks for keeping in touch! I haven’t done this before personally, and I’m not aware of a way to accomplish this, unfortunately. Though I imagine it might be possible with some trickery. Maybe something like the following might point you in the right direction?

https://blog.adamfurmanek.pl/2016/03/19/executing-c-code-using-powershell-script/

With this, perhaps you could do something like read the .csx file, store a function in a variable and execute it that way? I’d be interested to hear if you get it working some how. :slight_smile:

Best regards,

Kenny

Thanks Kenny.

I will explain you how is the current situtation on my side, I have code written in C# ( long code ) and I will use it in a Script Step Template (Powershell) as “binded” code behind, next idea was: Is it possible to upload the c# code as dll into the octopus Built-in Package repository then loading it in the script template for calling the sub/procedure of this ?

Or is this completely unnormal approach in this case ?

I will give the answer to me self, it works :wink: !!!

This means: you can call Package Repository DLL Code with Powershell , great wonderful, I’m very amused :wink:

Thank you Octopus Team!

Hi @applepi,

Thanks for keeping in touch and letting me know the outcome of that solution! Great to hear that works as needed. If you have any questions or concerns, please don’t hesitate to reach out. :slight_smile:

Best regards,

Kenny

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