C# 能吃蛋糕吗http://cakebuild.net)用于部署Azure Web应用程序

C# 能吃蛋糕吗http://cakebuild.net)用于部署Azure Web应用程序,c#,azure,continuous-integration,cakebuild,C#,Azure,Continuous Integration,Cakebuild,一直在查看Cake(at),我想知道它是否可以用于部署webapps和/或通过部署发布包访问虚拟服务器 我喜欢将cake作为C#中的部署框架的想法,因此与核心开发使用相同的语言 是否有我可以访问的azure部署示例?有几种方法可以使用Cake部署azure,可以通过使用某些CI服务(如VSTS/AppVeyor)预构建站点,然后使用web deploy、git或ftp发布工件(有一些Cake插件可以帮助实现这一点,或者使用Azure内置部署引擎Kudu和使用Cake的自定义部署脚本 要帮助使用K

一直在查看Cake(at),我想知道它是否可以用于部署webapps和/或通过部署发布包访问虚拟服务器

我喜欢将cake作为C#中的部署框架的想法,因此与核心开发使用相同的语言


是否有我可以访问的azure部署示例?

有几种方法可以使用Cake部署azure,可以通过使用某些CI服务(如VSTS/AppVeyor)预构建站点,然后使用web deploy、git或ftp发布工件(有一些Cake插件可以帮助实现这一点,或者使用Azure内置部署引擎Kudu和使用Cake的自定义部署脚本

要帮助使用Kudu部署/构建环境,可以使用加载项

第一步是告诉Kudu您有一个自定义部署脚本,您可以通过向存储库的根目录中添加一个“.deployment”文件来实现,该文件的内容为

[config]
command = deploy.cmd
deploy.cmd在安装和启动Cake时可能看起来像这样

@echo off

IF NOT EXIST "Tools" (md "Tools")

IF NOT EXIST "Tools\Addins" (MD "Tools\Addins")

nuget install Cake -ExcludeVersion -OutputDirectory "Tools" -Source https://www.nuget.org/api/v2/

Tools\Cake\Cake.exe deploy.cake -verbosity=Verbose
deploy.cake的外观可能如下所示:

#tool "nuget:https://www.nuget.org/api/v2/?package=xunit.runner.console"

#tool "nuget:https://www.nuget.org/api/v2/?package=KuduSync.NET"

#addin "nuget:https://www.nuget.org/api/v2/?package=Cake.Kudu"

///////////////////////////////////////////////////////////////////////////////

// ARGUMENTS

///////////////////////////////////////////////////////////////////////////////


var target = Argument<string>("target", "Default");

var configuration = Argument<string>("configuration", "Release");

///////////////////////////////////////////////////////////////////////////////

// GLOBAL VARIABLES

///////////////////////////////////////////////////////////////////////////////

var webRole = (EnvironmentVariable("web_role") ?? string.Empty).ToLower();

var solutionPath = MakeAbsolute(File("./src/MultipleWebSites.sln"));

string outputPath = MakeAbsolute(Directory("./output")).ToString();

string testsOutputPath = MakeAbsolute(Directory("./testsOutputPath")).ToString();


DirectoryPath websitePath,

                websitePublishPath,

                testsPath;


FilePath projectPath,

            testsProjectPath;

switch(webRole)

{

    case "api":

        {

            websitePath = MakeAbsolute(Directory("./src/Api"));

            projectPath = MakeAbsolute(File("./src/Api/Api.csproj"));

            testsPath = MakeAbsolute(Directory("./src/Api.Tests"));

            testsProjectPath = MakeAbsolute(File("./src/Api.Tests/Api.Tests.csproj"));

            websitePublishPath = MakeAbsolute(Directory("./output/_PublishedWebsites/Api"));

            break;

        }

    case "frontend":

        {

            websitePath = MakeAbsolute(Directory("./src/Frontend"));

            projectPath = MakeAbsolute(File("./src/Frontend/Frontend.csproj"));

            testsPath = MakeAbsolute(Directory("./src/Frontend.Tests"));

            testsProjectPath = MakeAbsolute(File("./src/Frontend.Tests/Frontend.Tests.csproj"));

            websitePublishPath = MakeAbsolute(Directory("./output/_PublishedWebsites/Frontend"));

            break;

        }

    case "backoffice":

        {

            websitePath = MakeAbsolute(Directory("./src/Backoffice"));

            projectPath = MakeAbsolute(File("./src/Backoffice/Backoffice.csproj"));

            testsPath = MakeAbsolute(Directory("./src/Backoffice.Tests"));

            testsProjectPath = MakeAbsolute(File("./src/Backoffice.Tests/Backoffice.Tests.csproj"));

            websitePublishPath = MakeAbsolute(Directory("./output/_PublishedWebsites/Backoffice"));

            break;

        }

    default:

        {

            throw new Exception(

            string.Format(

                    "Unknown web role {0}!",

                    webRole

                )

            );

        }

}


if (!Kudu.IsRunningOnKudu)

{

    throw new Exception("Not running on Kudu");

}


var deploymentPath = Kudu.Deployment.Target;

if (!DirectoryExists(deploymentPath))

{

    throw new DirectoryNotFoundException(

        string.Format(

            "Deployment target directory not found {0}",

            deploymentPath

            )

        );

}


///////////////////////////////////////////////////////////////////////////////

// SETUP / TEARDOWN

///////////////////////////////////////////////////////////////////////////////


Setup(() =>

{

    // Executed BEFORE the first task.

    Information("Running tasks...");

});


Teardown(() =>

{

    // Executed AFTER the last task.

    Information("Finished running tasks.");

});


///////////////////////////////////////////////////////////////////////////////

// TASK DEFINITIONS

///////////////////////////////////////////////////////////////////////////////


Task("Clean")

    .Does(() =>

{

    //Clean up any binaries

    Information("Cleaning {0}", outputPath);

    CleanDirectories(outputPath);


    Information("Cleaning {0}", testsOutputPath);

    CleanDirectories(testsOutputPath);


    var cleanWebGlobber = websitePath + "/**/" + configuration + "/bin";

    Information("Cleaning {0}", cleanWebGlobber);

    CleanDirectories(cleanWebGlobber);


    var cleanTestsGlobber = testsPath + "/**/" + configuration + "/bin";

    Information("Cleaning {0}", cleanTestsGlobber);

    CleanDirectories(cleanTestsGlobber);

});


Task("Restore")

    .Does(() =>

{

    // Restore all NuGet packages.

    Information("Restoring {0}...", solutionPath);

    NuGetRestore(solutionPath);

});


Task("Build")

    .IsDependentOn("Clean")

    .IsDependentOn("Restore")

    .Does(() =>

{

    // Build target web & tests.

    Information("Building web {0}", projectPath);

    MSBuild(projectPath, settings =>

        settings.SetPlatformTarget(PlatformTarget.MSIL)

            .WithProperty("TreatWarningsAsErrors","true")

            .WithProperty("OutputPath", outputPath)

            .WithTarget("Build")

            .SetConfiguration(configuration));


    Information("Building tests {0}", testsProjectPath);

    MSBuild(testsProjectPath, settings =>

        settings.SetPlatformTarget(PlatformTarget.MSIL)

            .WithProperty("TreatWarningsAsErrors","true")

            .WithProperty("ReferencePath", outputPath)

            .WithProperty("OutputPath", testsOutputPath)

            .WithTarget("Build")

            .SetConfiguration(configuration));

});


Task("Run-Unit-Tests")

    .IsDependentOn("Build")

    .Does(() =>

{

    XUnit2(testsOutputPath + "/**/*.Tests.dll", new XUnit2Settings {

        NoAppDomain = true

        });

});


Task("Publish")

    .IsDependentOn("Run-Unit-Tests")

    .Does(() =>

{

    Information("Deploying web from {0} to {1}", websitePublishPath, deploymentPath);

    Kudu.Sync(websitePublishPath);

});



Task("Default")

    .IsDependentOn("Publish");



///////////////////////////////////////////////////////////////////////////////

// EXECUTION

///////////////////////////////////////////////////////////////////////////////


RunTarget(target);
#工具“nuget:https://www.nuget.org/api/v2/?package=xunit.runner.console"
#工具“nuget:https://www.nuget.org/api/v2/?package=KuduSync.NET"
#addin“nuget:https://www.nuget.org/api/v2/?package=Cake.Kudu"
///////////////////////////////////////////////////////////////////////////////
//论据
///////////////////////////////////////////////////////////////////////////////
var target=参数(“目标”、“默认”);
变量配置=参数(“配置”、“发布”);
///////////////////////////////////////////////////////////////////////////////
//全局变量
///////////////////////////////////////////////////////////////////////////////
var webRole=(环境变量(“web_-role”)??string.Empty.ToLower();
var solutionPath=MakeAbsolute(文件(“./src/MultipleWebSites.sln”);
字符串outputPath=MakeAbsolute(目录(“./output”)。ToString();
字符串testsOutputPath=MakeAbsolute(目录(“./testsOutputPath”)).ToString();
DirectoryPath网站路径,
网站PublishPath,
testsPath;
文件路径项目路径,
测试项目路径;
交换机(webRole)
{
案例“api”:
        {
websitePath=MakeAbsolute(目录(“./src/Api”);
projectPath=MakeAbsolute(文件(“./src/Api/Api.csproj”);
testsPath=MakeAbsolute(目录(“./src/Api.Tests”);
testsProjectPath=MakeAbsolute(文件(“./src/Api.Tests/Api.Tests.csproj”);
websitePublishPath=MakeAbsolute(目录(“./output/_PublishedWebsites/Api”);
中断;
        }
案例“前端”:
        {
websitePath=MakeAbsolute(目录(“./src/Frontend”);
projectPath=MakeAbsolute(文件(“./src/Frontend/Frontend.csproj”);
testsPath=MakeAbsolute(目录(“./src/Frontend.Tests”);
testsProjectPath=MakeAbsolute(文件(“./src/Frontend.Tests/Frontend.Tests.csproj”);
websitePublishPath=MakeAbsolute(目录(“./output/_PublishedWebsites/Frontend”);
中断;
        }
案例“后台办公室”:
        {
websitePath=MakeAbsolute(目录(“./src/Backoffice”);
projectPath=MakeAbsolute(文件(“./src/Backoffice/Backoffice.csproj”);
testsPath=MakeAbsolute(目录(“./src/Backoffice.Tests”);
testsProjectPath=MakeAbsolute(文件(“./src/Backoffice.Tests/Backoffice.Tests.csproj”);
websitePublishPath=MakeAbsolute(目录(“./output/_PublishedWebsites/Backoffice”);
中断;
        }
默认值:
        {
抛出新异常(
字符串格式(
“未知的web角色{0}!”,
网络角色
                )
            );
        }
}
如果(!Kudu.IsRunningOnKudu)
{
抛出新异常(“未在Kudu上运行”);
}
var deploymentPath=Kudu.Deployment.Target;
如果(!DirectoryExists(deploymentPath))
{
抛出新的DirectoryNotFoundException(
字符串格式(
“未找到部署目标目录{0}”,
部署路径
            )
        );
}
///////////////////////////////////////////////////////////////////////////////
//安装/拆卸
///////////////////////////////////////////////////////////////////////////////
设置(()=>
{
//在第一个任务之前执行。
信息(“正在运行的任务…”);
});
拆卸(()=>
{
//在最后一个任务之后执行。
信息(“已完成的运行任务”);
});
///////////////////////////////////////////////////////////////////////////////
//任务定义
///////////////////////////////////////////////////////////////////////////////
任务(“清洁”)
.是否(()=>
{
//清除所有二进制文件
信息(“清理{0}”,输出路径);
清除目录(outputPath);
信息(“清理{0}”,testsOutputPath);
清除目录(testsOutputPath);
var cleanWebGlobber=websitePath+“/**/”+configuration+“/bin”;
信息(“清理{0}”,cleanWebGlobber);
CleanDirectory(cleanWebGlobber);
var cleanTestsGlobber=testsPath+“/**/”+configuration+“/bin”;
信息(“正在清理{0}”,cleanTestsGlobber);
CleanDirectory(cleanTestsGlobber);
});
任务(“恢复”)
.是否(()=>
{
//还原所有NuGet包。
信息(“R