如何以编程方式将静态html网站上载到windows azure网站?

rggaifut  于 2021-06-20  发布在  Kudu
关注(0)|答案(4)|浏览(275)

我目前正在c#中构建一个本地静态站点生成器。它将一堆模板编译成一个普通的旧html文件的层次结构。我想将结果文件上传到我的windowsazure网站并实时反映更改,并且我希望能够通过我的脚本以编程方式执行此操作。
目前,我不得不使用webmatrix手动上传生成的文件,因为我还没有找到一个api或sdk可以让我直接将html上传到windowsazure网站。
当然,除了使用sftp库(因为它不使用webmatrix/iis协议,我认为它发送压缩的diff,如果可以避免的话,我也不想把生成的站点提交给源代码管理。在我看来,将某些东西仅仅作为部署的实现细节而放到源代码管理中,在概念上是错误的。
更新:webmatrix在内部使用webdeploy(msdeploy)。理论上,您应该能够使用api自己构建部署包,但是我能找到的99%的示例都是使用visualstudio中的命令行工具或gui工具。我需要构建包并从c#中以编程方式部署它。你有什么想法或指导吗?msdn上的文档并没有给出这种场景的任何示例。

klh5stk1

klh5stk11#

webmatrix使用webdeploy将文件上载到windows azure网站。

g6ll5ycj

g6ll5ycj2#

另一种方法是使用vfs restapi(https://github.com/projectkudu/kudu/wiki/rest-api#wiki-vfs)。诊断控制台现在使用它来处理文件系统。

lxkprmvk

lxkprmvk3#

最简单的方法可能是为您的网站设置git发布,并以编程方式执行git提交,然后执行git推送。你可以把它看作是一种部署机制而不是源代码控制,因为azure网站本机支持一个与你选择的scm解决方案无关的git存储库。

tjjdgumg

tjjdgumg4#

好吧,我在微软的几个友好人士的帮助下想出了办法(请参阅david的ebbo对我的论坛问题的回答,以及sayed hashimi提供的非常有用的信息,这些信息显示了如何从msdeploy.exe控制台应用程序中准确地执行我想执行的操作。
只需从azure web门户获取publishsettings文件。在文本编辑器中打开它,获取要粘贴到下面代码中的值。

var destinationOptions = new DeploymentBaseOptions()
{
    // userName from Azure Websites PublishSettings file
    UserName = "$msdeploytest",
    // pw from PublishSettings file
    Password = "ThisIsNotMyPassword",
    // publishUrl from PublishSettings file using https: protocol prefix rather than 443 port
    // and adding "/msdeploy.axd?site={msdeploySite-variable-from-PublishSettings}"
    ComputerName = "https://waws-prod-blu-003.publish.azurewebsites.windows.net/msdeploy.axd?site=msdeploytest",
    AuthenticationType = "Basic"
};
                                                             // This option says we're giving it a directory to deploy
using (var deploymentObject = DeploymentManager.CreateObject(DeploymentWellKnownProvider.ContentPath,
                                                             // path to root directory of source files 
                                                             @"C:\Users\ryan_000\Downloads\dummysite"))
{
    var syncOptions = new DeploymentSyncOptions();
    syncOptions.WhatIf = false;
                                                                                   // "msdeploySite" variable from PublishSettings file
    var changes = deploymentObject.SyncTo(DeploymentWellKnownProvider.ContentPath, "msdeploytest", destinationOptions, syncOptions);
    Console.WriteLine("BytesCopied:       " + changes.BytesCopied.ToString());
    Console.WriteLine("Added:             " + changes.ObjectsAdded.ToString());
    Console.WriteLine("Updated:           " + changes.ObjectsUpdated.ToString());
    Console.WriteLine("Deleted:           " + changes.ObjectsDeleted.ToString());
    Console.WriteLine("Errors:            " + changes.Errors.ToString());
    Console.WriteLine("Warnings:          " + changes.Warnings.ToString());
    Console.WriteLine("ParametersChanged: " + changes.ParameterChanges.ToString());
    Console.WriteLine("TotalChanges:      " + changes.TotalChanges.ToString());
}

您还可以在msdn上晦涩难懂的文档中摸索。有很多奇怪命名的options类被传递,但是只要稍微眯着眼睛,在文档中翻来覆去,就可以看到命令行选项(其中的示例在网上更容易找到)是如何Map到api调用的。

相关问题