10

How can we create another run.csx and call the existing function from one csx file to another in an Azure Function App?

DAXaholic
  • 33,312
  • 6
  • 76
  • 74

1 Answers1

14

You can just write another file, e.g. lib.csx and load it via #load "lib.csx" in your main script file. See here for the docs

As an example, place this into your run.csx

#load "lib.csx"

using System;

public static void Run(TimerInfo myTimer, TraceWriter log)
{
    log.Info($"C# Timer trigger function executed at: {DateTime.Now}");    
    log.Info(doubleTheInt(5).ToString());
}

and that into a lib.csx

using System;

public static int doubleTheInt(int x) {
    return x+x;
}

and it should output 10 in the log

DAXaholic
  • 33,312
  • 6
  • 76
  • 74
  • I assume "lib.csx" gets created and saved like any other .csx, but how do you indicate where it should get stored? – Randy Minder May 02 '18 at 17:13
  • 1
    @RandyMinder I am not sure if I understand you correctly but `#load` can work with relative paths like `"..\shared\lib.csx"` (see e.g. the [docs](https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-csharp#reusing-csx-code)) – DAXaholic May 03 '18 at 04:42