我知道这看起来很简单,但我在网上找不到任何帮助.
I know this seems like a simple thing but I can't find any help online.
我想在使用 Visual Studio 发布 Azure 函数时包含一个文件 (.html).然后我希望能够在我的 Azure 函数中访问这个文件.为什么?我发布时似乎只有 .dll 被发送到服务器.
I want to include a file (.html) along with my Azure function when I publish it using Visual Studio. Then I want to be able to access this file in my Azure function. Why? It seems like only the .dll gets sent to the server when I publish.
此文件将是一个 .html 文件,它将是一个电子邮件模板.我想在我的函数中阅读它,然后发送电子邮件.
This file will be an .html file that will be an email template. I want to read it in my function and then send emails out.
非常感谢任何帮助.
我知道我可以使用 [Azure 函数中的发送网格][1],但看起来我只能发送一封电子邮件而不能发送多封电子邮件,这正是我想要的.
I see I can use [send grid in Azure functions][1], but it looks like I can only send out one email and not multiple emails, which is what I want.
首先,您需要将 html 文件添加到您的项目中,并在属性中将 Copy to Output Directory 设置为Copy if newer".
First, you need to add the html file to your project, and in the properties, set Copy to Output Directory to "Copy if newer".
然后在你的函数代码中,接受一个额外的 ExecutionContext context
参数(注意这是 Microsoft.Azure.WebJobs.ExecutionContext
和 not System.Threading.ExecutionContext
).当您需要访问您的 html 文件时,您可以编写:
Then in your function code, take in an additional ExecutionContext context
parameter (note that this is Microsoft.Azure.WebJobs.ExecutionContext
and not System.Threading.ExecutionContext
). And when you need to access your html file, you can then write:
string htmlFilePath = Path.Combine(context.FunctionAppDirectory, "test.html");
假设您在 VS 项目的 root 中添加了该文件.如果您将其添加到某个 Data
文件夹中(更好的做法),您会写:
That's assuming you added the file at the root of your VS project. If you instead added it in some Data
folder (better practice), you'd write:
string htmlFilePath = Path.Combine(context.FunctionAppDirectory, "Data", "test.html");
请参阅此处了解完整的工作示例.
See here for full working sample.
这篇关于在 Visual Studio 中发布 Azure 函数时包含文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!