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 - 共享类


- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 输入按键事件处理程序 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01