IIS addin for Cake
C# PowerShell Batchfile
Pull request Compare This branch is 10 commits ahead, 1 commit behind RagingKore:master.
Latest commit b427fb9 Nov 16, 2016 @SharpeRAD Few extra comments

README.md

Cake.IIS

Cake-Build addin that extends Cake with IIS extensions

Build status

cakebuild.net

Join the chat at https://gitter.im/cake-build/cake

Table of contents

  1. Implemented functionality
  2. Referencing
  3. Usage
  4. Example
  5. TroubleShooting
  6. Plays well with
  7. License
  8. Share the love

Implemented functionality

  • Create Website / Ftpsite
  • Delete Site
  • Start Site
  • Stop Site
  • Site Exists
  • Add site binding
  • Remove site binding
  • Create Application Pool
  • Delete Pool
  • Start Pool
  • Stop Pool
  • Pool Exists
  • Recycle Pool
  • Create site applications
  • Create WebFarm
  • Delete WebFarm
  • Add server to WebFarm
  • Delete server from WebFarm
  • Server exists
  • Set server Healthy
  • Set server Unhealthy
  • Set server Available
  • Set server Unavailable
  • Is server Healthy
  • Get server State
  • Create Virtual Directory
  • Delete Virtual Directory
  • Virtual Directory Exists

Referencing

NuGet Version NuGet Downloads

Cake.IIS is available as a nuget package from the package manager console:

Install-Package Cake.IIS

or directly in your build script via a cake addin directive:

#addin "Cake.IIS"

Usage

#addin "Cake.IIS"

Task("ApplicationPool-Create")
    .Description("Create a ApplicationPool")
    .Does(() =>
{
    CreatePool("remote-server-name", new ApplicationPoolSettings()
    {
        Name = "Production",

        Username = "Admin",
        Password = "pass1"
    });
});

Task("ApplicationPool-Stop")
    .Description("Stops a local ApplicationPool")
    .Does(() =>
{
    StopPool("Production");
});

Task("ApplicationPool-Start")
    .Description("Starts a remote ApplicationPool")
    .Does(() =>
{
    StartPool("remote-server-name", "Production");
});



Task("Website-Create")
    .Description("Create a Website")
    .Does(() =>
{
    CreateWebsite("remote-server-name", new WebsiteSettings()
    {
        Name = "MyBlog",
        Binding = IISBindings.Http
                    .SetHostName("blog.website.com")
                    .SetIpAddress("*")
                    .SetPort(80),
        PhysicalDirectory = "C:/Websites/Blog",

        ApplicationPool = new ApplicationPoolSettings()
        {
            Name = "Production"
        }
    });
});

Task("Website-Stop")
    .Description("Stops a remote Website")
    .Does(() =>
{
    StopSite("remote-server-name", "MyBlog");
});

Task("Website-Start")
    .Description("Starts a local Website")
    .Does(() =>
{
    StartSite("MyBlog");
});



Task("Binding-Add")
    .Description("Adds a binding to a website")
    .Does(() =>
{
    AddBinding("MyBlog", new BindingSettings(BindingProtocol.Http)
    {
        HostName = "myblog.com"
    });
});

Task("Binding-Add-Fluent")
    .Description("Adds a binding to a website using a fluent interface")
    .Does(() =>
{
    AddBinding("remote-server-name", "MyBlog", IISBindings.Http
                                                .SetIpAddress("127.0.0.1")
                                                .SetPort(8080));
});

Task("Binding-Remove")
    .Description("Removes a binding from a website")
    .Does(() =>
{
    RemoveBinding("remote-server-name", "MyBlog", new BindingSettings(BindingProtocol.Http)
    {
        HostName = "myblog.com"
    });
});



Task("Application-Create")
    .Description("Adds an application to a site")
    .Does(() =>
{
    AddSiteApplication(new ApplicationSettings()
    {
        SiteName = "Default Website",

        ApplicationPath = "/NestedApp",
        PhysicalDirectory = "C:/Apps/KillerApp/"
    });
});

Task("Application-Remove")
    .Description("Remove an application from a site")
    .Does(() =>
{
    RemoveSiteApplication(new ApplicationSettings()
    {
        SiteName = "Default Website",

        ApplicationPath = "/NestedApp",
        PhysicalDirectory = "C:/Apps/KillerApp/"
    });
});



Task("WebFarm-Create")
    .Description("Create a WebFarm")
    .Does(() =>
{
    CreateWebFarm("remote-server-name", new WebFarmSettings()
    {
        Name = "Batman",
        Servers = new string[] { "Gotham", "Metroplis" }
    });
});

Task("WebFarm-Server-Available")
    .Description("Sets a WebFarm server as available")
    .Does(() =>
{
    SetServerAvailable("remote-server-name", "Batman", "Gotham");
});

Task("WebFarm-Server-Unavailable")
    .Description("Sets a WebFarm server as unavailable")
    .Does(() =>
{
    SetServerUnavailable("remote-server-name", "Batman", "Gotham");
});

Task("VirtualDirectory-Create")
    .Description("Creates a Virtual Directory")
    .Does(() => 
{
    AddSiteVirtualDirectory("remote-server-name", new VirtualDirectorySettings(){
        PhysicalDirectory = "C:/Apps/Directory/",
        SiteName = "Default Website",
        ApplicationPath = "/",
        Path = "/Directory"
    });
});

Task("VirtualDirectory-Remove")
    .Description("Removes a Virtual Directory")
    .Does(() => 
{
    RemoveSiteVirtualDirectory("remote-server-name", new VirtualDirectorySettings(){
        SiteName = "Default Website",
        ApplicationPath = "/",
        Path = "/Directory"
    });
});

Task("VirtualDirectory-Exists")
    .Description("Checks if a Virtual Directory exists")
    .Does(() => 
{
    SiteVirtualDirectoryExists("remote-server-name", new VirtualDirectorySettings(){
        SiteName = "Default Website",
        ApplicationPath = "/",
        Path = "/Directory"
    });
});
RunTarget("Website-Create");

Example

A complete Cake example can be found here.

TroubleShooting

A few pointers for managing IIS can be found here.

Plays well with

If your looking to deploy to IIS its worth checking out Cake.WebDeploy or if your running a WebFarm inside AWS then check out Cake.AWS.ElasticLoadBalancing.

If your looking for a way to trigger cake tasks based on windows events or at scheduled intervals then check out CakeBoss.

License

Copyright (c) 2015 - 2016 Sergio Silveira, Phillip Sharpe

Cake.IIS is provided as-is under the MIT license. For more information see LICENSE.

Share the love

If this project helps you in anyway then please ⭐️ the repository.