Attribute function in dependency project as entry point

Teng L 21 Reputation points
2020-06-29T18:32:38.627+00:00

Hi, I'm using C# to write my Azure Functions. I found that the framework does not use the functions, which are attributed with [FunctionName] already, OUT of the start-up project. For example, I have ProjectA depending on ProjectB. ProjectA is the targeted starting up project and ProjectB is the dependency that has "function1" attributed with [FunctionName('function1')]. When I start ProjectA, the function1 doesn't get loaded.

Question: Is this the expected behavior? Is there any documents that show details about how the attributes would be looked up? Like only per current assembly, or all assemblies in current appDomain or so. Is there a way that we can register a dependency for that purpose? Thank you so much!

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,092 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Pramod Valavala 20,636 Reputation points Microsoft Employee
    2020-07-02T10:43:20.187+00:00

    UPDATE: Apart from the below approach, while not documented yet. You can set the FunctionsInDependencies property in your csproj file. This was mentioned in this SO thread.

    ---

    Functions are loaded by reading function.json files. These are generated during compilation even for C# functions. I have attached one that I've generated by running a release build in a fresh function app

       dotnet build -c release  
    

    Here is the same for reference

       {  
         "generatedBy": "Microsoft.NET.Sdk.Functions-1.0.31",  
         "configurationSource": "attributes",  
         "bindings": [  
           {  
             "type": "httpTrigger",  
             "methods": [  
               "get",  
               "post"  
             ],  
             "authLevel": "function",  
             "name": "req"  
           }  
         ],  
         "disabled": false,  
         "scriptFile": "../bin/funk-csharp.dll",  
         "entryPoint": "funk_csharp.HttpTrigger.Run"  
       }  
    

    A similar file with the appropriate scriptFile and entryPoint values should do the trick. Here is how the release folder structure looks like

    11272-image.png

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.