<i id='p1ftR'><tr id='p1ftR'><dt id='p1ftR'><q id='p1ftR'><span id='p1ftR'><b id='p1ftR'><form id='p1ftR'><ins id='p1ftR'></ins><ul id='p1ftR'></ul><sub id='p1ftR'></sub></form><legend id='p1ftR'></legend><bdo id='p1ftR'><pre id='p1ftR'><center id='p1ftR'></center></pre></bdo></b><th id='p1ftR'></th></span></q></dt></tr></i><div id='p1ftR'><tfoot id='p1ftR'></tfoot><dl id='p1ftR'><fieldset id='p1ftR'></fieldset></dl></div>
<legend id='p1ftR'><style id='p1ftR'><dir id='p1ftR'><q id='p1ftR'></q></dir></style></legend>

<small id='p1ftR'></small><noframes id='p1ftR'>

    <bdo id='p1ftR'></bdo><ul id='p1ftR'></ul>

    1. <tfoot id='p1ftR'></tfoot>

        从代码部署 Azure 函数 (c#)

        Deploy Azure function from code (c#)(从代码部署 Azure 函数 (c#))

          <tbody id='uB4nI'></tbody>
        1. <small id='uB4nI'></small><noframes id='uB4nI'>

            <legend id='uB4nI'><style id='uB4nI'><dir id='uB4nI'><q id='uB4nI'></q></dir></style></legend>
            • <i id='uB4nI'><tr id='uB4nI'><dt id='uB4nI'><q id='uB4nI'><span id='uB4nI'><b id='uB4nI'><form id='uB4nI'><ins id='uB4nI'></ins><ul id='uB4nI'></ul><sub id='uB4nI'></sub></form><legend id='uB4nI'></legend><bdo id='uB4nI'><pre id='uB4nI'><center id='uB4nI'></center></pre></bdo></b><th id='uB4nI'></th></span></q></dt></tr></i><div id='uB4nI'><tfoot id='uB4nI'></tfoot><dl id='uB4nI'><fieldset id='uB4nI'></fieldset></dl></div>

              1. <tfoot id='uB4nI'></tfoot>
                  <bdo id='uB4nI'></bdo><ul id='uB4nI'></ul>
                • 本文介绍了从代码部署 Azure 函数 (c#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何使用代码作为字符串(在 c# 中)将 azure 函数(按计划执行)部署到给定的 azure 函数应用程序?

                  我将使用 ARM 模板来部署 azure fund 应用程序(+ 所需的一切)

                  5.查看 Azure kudu 工具发布的结果(

                  packages.config

                  <?xml version="1.0" encoding="utf-8"?><包><package id="Microsoft.Azure.Management.AppService.Fluent" version="1.1.3" targetFramework="net452"/><package id="Microsoft.Azure.Management.Batch.Fluent" version="1.1.3" targetFramework="net452"/><package id="Microsoft.Azure.Management.Cdn.Fluent" version="1.1.3" targetFramework="net452"/><package id="Microsoft.Azure.Management.Compute.Fluent" version="1.1.3" targetFramework="net452"/><package id="Microsoft.Azure.Management.ContainerRegistry.Fluent" version="1.1.3" targetFramework="net452"/><package id="Microsoft.Azure.Management.Dns.Fluent" version="1.1.3" targetFramework="net452"/><package id="Microsoft.Azure.Management.DocumentDB.Fluent" version="1.1.3" targetFramework="net452"/><package id="Microsoft.Azure.Management.Fluent" version="1.1.3" targetFramework="net452"/><package id="Microsoft.Azure.Management.Graph.RBAC.Fluent" version="1.1.3" targetFramework="net452"/><package id="Microsoft.Azure.Management.KeyVault.Fluent" version="1.1.3" targetFramework="net452"/><package id="Microsoft.Azure.Management.Network.Fluent" version="1.1.3" targetFramework="net452"/><package id="Microsoft.Azure.Management.Redis.Fluent" version="1.1.3" targetFramework="net452"/><package id="Microsoft.Azure.Management.ResourceManager.Fluent" version="1.1.3" targetFramework="net452"/><package id="Microsoft.Azure.Management.ServiceBus.Fluent" version="1.1.3" targetFramework="net452"/><package id="Microsoft.Azure.Management.Sql.Fluent" version="1.1.3" targetFramework="net452"/><package id="Microsoft.Azure.Management.Storage.Fluent" version="1.1.3" targetFramework="net452"/><包 id="Microsoft.Azure.Management.TrafficManager.Fluent" 版本="1.1.3" targetFramework="net452"/><包 id="Microsoft.IdentityModel.Clients.ActiveDirectory" 版本="2.28.3" targetFramework="net452"/><package id="Microsoft.Rest.ClientRuntime" version="2.3.8" targetFramework="net452"/><package id="Microsoft.Rest.ClientRuntime.Azure" version="3.3.8" targetFramework="net452"/><package id="Microsoft.Rest.ClientRuntime.Azure.Authentication" version="2.3.0" targetFramework="net452"/><package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452"/></包>

                  How to deploy azure function (executed on schedule) with code as string (in c#) to given azure functions app?

                  I am going to use ARM template to deploy azure fund app (+ all it needs) https://github.com/Azure/azure-quickstart-templates/tree/master/101-function-app-create-dynamic, which can be deployed via code;

                  But I don't see ways to deploy function to function app via code.

                  + A little more context: deployment is going to happen from an app service, so it's preferred not to have any dependencies beyond NuGet. E.g. I don't like the idea to call azure cli from c#.

                  解决方案

                  As Jesse Carter mentioned that we could use Kudu Zip Api to do that. I do a demo for that. It works correctly on my side. The following is my detail steps:

                  Preparation:

                  Registry an AD application and assign role to applcation, more details please refer to Azure official tutorials. After that we can get tenantId, appId, secretKey from the Azure Portal.

                  1.Prepare an authentication file, we could get more information from github document.

                  subscription=########-####-####-####-############
                  client=########-####-####-####-############
                  tenant=########-####-####-####-############
                  managementURI=https://management.core.windows.net/
                  baseURL=https://management.azure.com/
                  authURL=https://login.windows.net/
                  graphURL=https://graph.windows.net/
                  

                  2.Zip the need to be published file

                  Steps:

                  1.Create a C# console project

                  2.Reference the Microsoft.Azure.Management.ResourceManager.Fluent and Microsoft.Azure.Management.AppService.Fluent, more detail info please refer to the packages.config file section.

                  3.Add the following code in the Program.cs file

                     var credentials = SdkContext.AzureCredentialsFactory.FromFile(@"authentication file path");
                     var azure = Azure
                                  .Configure()
                                  .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
                                  .Authenticate(credentials)
                                  .WithDefaultSubscription();
                     var webFunctionAppName = "azure function name";
                     var webFunctionApp = azure.AppServices.FunctionApps.List().Where(x => x.Name.Equals(webFunctionAppName))?.First();
                     var ftpUsername = azure.AppServices.FunctionApps.GetById(webFunctionApp.Id).GetPublishingProfile().FtpUsername;
                     var username = ftpUsername.Split('\').ToList()[1];
                     var password = azure.AppServices.FunctionApps.GetById(webFunctionApp.Id).GetPublishingProfile().FtpPassword;
                     var base64Auth = Convert.ToBase64String(Encoding.Default.GetBytes($"{username}:{password}"));
                     var file = File.ReadAllBytes(@"zip file path");
                     MemoryStream stream = new MemoryStream(file);
                  
                      using (var client = new HttpClient())
                      {
                          client.DefaultRequestHeaders.Add("Authorization", "Basic " + base64Auth);
                          var baseUrl = new Uri($"https://{webFunctionAppName}.scm.azurewebsites.net/");
                          var requestURl = baseUrl+ "api/zip/site/wwwroot";
                          var httpContent = new StreamContent(stream);
                          var response = client.PutAsync(requestURl, httpContent).Result;
                       }
                  

                  4.Test from the local

                  5.Check the published result from the Azure kudu tool(https://yourazurefunctionanme.scm.azurewebsites.net/)

                  packages.config

                  <?xml version="1.0" encoding="utf-8"?>
                  <packages>
                    <package id="Microsoft.Azure.Management.AppService.Fluent" version="1.1.3" targetFramework="net452" />
                    <package id="Microsoft.Azure.Management.Batch.Fluent" version="1.1.3" targetFramework="net452" />
                    <package id="Microsoft.Azure.Management.Cdn.Fluent" version="1.1.3" targetFramework="net452" />
                    <package id="Microsoft.Azure.Management.Compute.Fluent" version="1.1.3" targetFramework="net452" />
                    <package id="Microsoft.Azure.Management.ContainerRegistry.Fluent" version="1.1.3" targetFramework="net452" />
                    <package id="Microsoft.Azure.Management.Dns.Fluent" version="1.1.3" targetFramework="net452" />
                    <package id="Microsoft.Azure.Management.DocumentDB.Fluent" version="1.1.3" targetFramework="net452" />
                    <package id="Microsoft.Azure.Management.Fluent" version="1.1.3" targetFramework="net452" />
                    <package id="Microsoft.Azure.Management.Graph.RBAC.Fluent" version="1.1.3" targetFramework="net452" />
                    <package id="Microsoft.Azure.Management.KeyVault.Fluent" version="1.1.3" targetFramework="net452" />
                    <package id="Microsoft.Azure.Management.Network.Fluent" version="1.1.3" targetFramework="net452" />
                    <package id="Microsoft.Azure.Management.Redis.Fluent" version="1.1.3" targetFramework="net452" />
                    <package id="Microsoft.Azure.Management.ResourceManager.Fluent" version="1.1.3" targetFramework="net452" />
                    <package id="Microsoft.Azure.Management.ServiceBus.Fluent" version="1.1.3" targetFramework="net452" />
                    <package id="Microsoft.Azure.Management.Sql.Fluent" version="1.1.3" targetFramework="net452" />
                    <package id="Microsoft.Azure.Management.Storage.Fluent" version="1.1.3" targetFramework="net452" />
                    <package id="Microsoft.Azure.Management.TrafficManager.Fluent" version="1.1.3" targetFramework="net452" />
                    <package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="2.28.3" targetFramework="net452" />
                    <package id="Microsoft.Rest.ClientRuntime" version="2.3.8" targetFramework="net452" />
                    <package id="Microsoft.Rest.ClientRuntime.Azure" version="3.3.8" targetFramework="net452" />
                    <package id="Microsoft.Rest.ClientRuntime.Azure.Authentication" version="2.3.0" targetFramework="net452" />
                    <package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
                  </packages>
                  

                  这篇关于从代码部署 Azure 函数 (c#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Populate ListBox with a IEnumrable on another thread (winforms)(在另一个线程(winforms)上使用 IEnumrable 填充 ListBox)
                  listbox selected item give me quot; System.Data.DataRowViewquot; , C# winforms(列表框选择的项目给我quot;System.Data.DataRowView, C# Winforms)
                  Cannot remove items from ListBox(无法从列表框中删除项目)
                  Preventing ListBox scrolling to top when updated(更新时防止列表框滚动到顶部)
                  Drag and drop from list to canvas on windows phone with MVVM(使用 MVVM 在 Windows 手机上从列表拖放到画布)
                  Deselection on a WPF listbox with extended selection mode(具有扩展选择模式的 WPF 列表框上的取消选择)

                • <i id='PtD9A'><tr id='PtD9A'><dt id='PtD9A'><q id='PtD9A'><span id='PtD9A'><b id='PtD9A'><form id='PtD9A'><ins id='PtD9A'></ins><ul id='PtD9A'></ul><sub id='PtD9A'></sub></form><legend id='PtD9A'></legend><bdo id='PtD9A'><pre id='PtD9A'><center id='PtD9A'></center></pre></bdo></b><th id='PtD9A'></th></span></q></dt></tr></i><div id='PtD9A'><tfoot id='PtD9A'></tfoot><dl id='PtD9A'><fieldset id='PtD9A'></fieldset></dl></div>
                    <tbody id='PtD9A'></tbody>

                      • <bdo id='PtD9A'></bdo><ul id='PtD9A'></ul>

                        <tfoot id='PtD9A'></tfoot>

                          <small id='PtD9A'></small><noframes id='PtD9A'>

                          <legend id='PtD9A'><style id='PtD9A'><dir id='PtD9A'><q id='PtD9A'></q></dir></style></legend>