简体   繁体   English

如何从引用的nuget包中加载Azure活动功能

[英]How to load azure activity function from a referenced nuget package

I've implemented an Azure durable function which as you know contains my Orchestration , Orchestrator and Activities . 我已经实现了Azure持久功能,如您所知,该功能包含我的业务流程 ,业务流程活动
the point is one of my activities is implemented in another assembly and I referenced it as a nuget package. 关键是我的活动之一是在另一个程序集中实现的,我将其称为nuget程序包。
Now the problem is when I'm running my solution in Visual Studio all the Azure Functions loading by AzureFunctionsTools but this activity which located in the nuget package is not listed and I'm facing the below error message: 现在的问题是,当我在Visual Studio中运行我的解决方案时,所有由AzureFunctionsTools加载的Azure函数都没有列出,但未列出位于nuget包中的此活动,并且我遇到了以下错误消息:

Error: 'MyExternalActivity' doesn't exist, is disabled, or is not an activity function. 错误: “ MyExternalActivity”不存在,被禁用或不是活动功能。 Additional info: The following are the known activity functions: 'MyLocalActivity'. 附加信息:以下是已知的活动功能:“ MyLocalActivity”。

And here is my MyExternalActivity definition in the nuget project: 这是我在nuget项目中的MyExternalActivity定义:

[FunctionName(FunctionName)]
public async Task<object> Run([ActivityTrigger] DurableActivityContextBase context) 
{
...
}

And here it is my Orchestrator class: 这是我的Orchestrator类:

[FunctionName(FunctionName)]
public static async Task RunOrchestrator([OrchestrationTrigger] DurableOrchestrationContextBase context, ILogger log)
 {
    ...
    await context.CallActivityAsync<object>("MyLocalActivity", parameters); // Successfull; code is in this solution
    ...   
    ...
    await context.CallActivityAsync<object>("MyExternalActivity" , parameters); // Error; Referenced by nuget package
    ...
}

Note: I tried to remove the reference and add the nuget code project to the same solution and reference through the project directly, But same error happening 注意:我试图删除引用并将nuget代码项目添加到相同的解决方案中,并直接通过该项目进行引用,但是发生了相同的错误

The reason you are having this issue is because calling a different function is not the same as calling a method in a different project or nuget package. 您遇到此问题的原因是因为调用其他函数与在其他项目或nuget包中调用方法并不相同。 They are completely seperate entities so adding a reference will not cause the activity function to be included. 它们是完全独立的实体,因此添加引用不会导致包含活动功能。

The correct way to implement this is to have both of the functions defined in a single project. 正确的实现方法是在一个项目中定义两个功能。 You can absolutely have the function definition be a shell that then calls out to code in a nuget package. 您绝对可以将函数定义作为外壳,然后调用nuget包中的代码。

[FunctionName(FunctionName)]
public async Task<object> Run([ActivityTrigger] DurableActivityContextBase context) 
{
    MethodFromNugetPackage(context);
}

If you want to have the functions in different projects, there are a couple options: 如果要在不同项目中使用这些功能,则有两种选择:

1) Have multiple Function services in Azure. 1)在Azure中具有多个功能服务。

2) Deploy the code with "Remove additional files in destination" turned off. 2)在关闭“删除目标中的其他文件”的情况下部署代码。 This assumes that you are deploying from Visual Studio, so if you are using a different deployement method you will need to find and adjust the equivelent setting. 这假定您是从Visual Studio进行部署的,因此,如果使用其他部署方法,则需要查找并调整等价设置。 To be clear this is not recommended as you could run into issues that are difficult to track down, but it should work. 需要明确的是, 建议这样做,因为您可能会遇到难以跟踪的问题,但是应该可以解决。 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM