Azure Functions - Shared classes(Azure Functions - 共享类)
问题描述
我想在我的 Azure Functions 上使用一些共享类来避免重复代码.
I want to use some shared classes on my Azure Functions to not duplicate code.
我尝试创建一个空的 C# 函数并在函数内部创建类,然后导入到其他函数:
I have tried to create a empty C# function and create the classes inside the function and then import to the other functions with:
#r "../Shared/Class.cs"
推荐答案
首先,将您的共享代码放在 Function App 目录根目录下的文件夹中(例如Shared").假设我在该文件夹中放置了一个共享的 Message.csx
类(例如完整路径 D:homesitewwwrootSharedMessage.csx
).
First, put your shared code inside a folder in the root of your Function App directory (e.g. "Shared"). Let's say I put a shared Message.csx
class in that folder (e.g. full path D:homesitewwwrootSharedMessage.csx
).
要将其包含到您的函数中,请使用 #load
命令:
To include this into your function use the #load
command:
#load "..SharedMessage.csx"
using System;
using Microsoft.Azure.WebJobs.Host;
public static void Run(Message message, TraceWriter log)
{
log.Info($"C# Queue trigger function processed message: {message.Id}");
}
查看帮助页面此处了解更多信息信息.默认情况下,不会跟踪该目录中的文件的更改.如果您想确保当该目录中的文件发生更改时,您的函数将获取更改并重新编译,您可以将共享"目录添加到 host.json<中的
watchDirectories
列表中/代码>.例如:
See the help page here for more information. By default, the files in that directory won't be tracked for changes. If you want to ensure that when files in that directory change your functions will pick up the changes and be recompiled, you can add your "Shared" directory to the watchDirectories
list in host.json
. E.g.:
{
"watchDirectories": [ "Shared" ]
}
这篇关于Azure Functions - 共享类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Azure Functions - 共享类


基础教程推荐
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01