问题描述
我使用了 Visual Studio 2019。我使用了 2 个 API 调用 我参考了下面的文档:
使用 Kudu API 更改 function.json https://github.com/projectkudu/kudu/wiki/REST-API
1.PUT https://{functionAppName}.scm.azurewebsites.net/api/vfs/{pathToFunction.json},Headers: If-Match:"*",Body: new function.json content 然后发送应用更改的请求
2.POST https://{functionAppName}.scm.azurewebsites.net/api/functions/synctriggers 两个api都是返回成功状态码
状态码:
API2 给出 201 表示文档成功完成同步触发以保存文件修改
代码如下:
using (var client = new HttpClient())
{
var creds = "credentials";
var credentials = Encoding.ASCII.GetBytes(creds);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",Convert.ToBase64String(credentials));
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.TryAddWithoutValidation("If-Match","*");
var data = new List<ChangeData>
{
new ChangeData{schedule="125255"}
};
string json = "{'schedule':'*/48 * * * * *'}";
var customerjson = JsonConvert.SerializeObject(data);
var content = new StringContent(customerjson,Encoding.UTF8,"application/json");
var response = client.PutAsync("https://********.scm.azurewebsites.net/api/vfs/home/site/wwwroot/Function7/function.json",content);
Console.WriteLine(response.Result);
/// var errorMessage = response..ToString();
using (var request = new HttpRequestMessage(new HttpMethod("POST"),"https://******.scm.azurewebsites.net/api/functions/synctriggers"))
{
var base64authorization = Convert.ToBase64String(Encoding.ASCII.GetBytes("basestring"));
request.Headers.TryAddWithoutValidation("Authorization",$"Basic {base64authorization}");
var response3 = await client.SendAsync(request);
Console.WriteLine(response3);
}
我想更改 function.json 中的计划值
解决方法
最新
之前版本的azure函数可以通过run-from-package配置修改文件。现在通过vs2019直接发布的功能应用不支持这个操作。
为了实现您的需求,我们可以使用命令行进行发布。具体步骤在你的另一个帖子里,需要帮助更多的论坛用户。
func azure functionapp publish function_app_name --csharp --nozip --force
How to change content dynamically after function is called in Azure function app
您想更改 function.json 中的计划值。
-
正如我在你的另一个帖子中回答的那样,没有意义,但我也有一个方法(通过
SCM_DO_BUILD_DURING_DEPLOYMENT
)让你进行更改。 -
主要是修改json文件不会重新编译我们的FunctionApp1.dll文件,如下图。
How to change content dynamically after function is called in Azure function app
为什么会有这样的需求?
我猜你已经在Azure Portal上创建了一个Function App,所以你认为你可以通过修改function.json来修改配置,但事实并非如此。
因为在门户上创建的函数应用会生成一个 .csx
文件,所以它最终不会运行 .dll
,这是本质区别。