X
12Oct

Deploy .NET application on IIS using GitHub actions

In this blog I will be showing how to deploy a .net application on IIS server (self-hosted runner). Once the web application is developed and ready to be made available to the user. To enable the user to access the application, the web application needs to be deployed on a Web server, such as IIS.

What is IIS server??

IIS is a Web server that provides a complete platform, which helps you to host and manage web applications. IIS is a proprietary by Microsoft and is available as a package along with the Windows operating system. By default, IIS feature is turned off when Windows is installed. Hence, before deploying an application on IIS, you need to enable IIS on the Windows operating system.

Deployment using GitHub Action

Before we start with the deployment process, we must complete the build process and store the build artifact. Once we are done with the CI part, we will start with CD process.
There are 2 pre-requisites on the deployment machine
•    IIS should be enabled 
•    webadministration module should be imported using powershell
•    Make sure that the GitHub Action Runner agent uses Log on method as “local system account” for the agent service

 

To deploy the application, we will be using PowerShell script by passing certain values as argument to the script. The script required to deploy the application is stored as a .ps1 file in the repository and is made available as a part of the generated artifact in the CI process.

Below is a sample snippet which shows how to download the generated artifact using actions from marketplace and the execution of the PowerShell script along with the arguments.

jobs:
  Build:
    runs-on: windows-selfhosted
    needs: Build
    steps:
    
    - name: Download a Build Artifact
      uses: actions/download-artifact@v2.0.5
      with:
        name: Parts
        path: ${{github.workspace}}
   - name: Run Powershell
      run: |
        & '${{github.workspace}}\PartsUnlimited-aspnet45\app_pool.ps1' -pool_name ${{env.app_pool_name}} -site_name ${{env.site_name}} - packagepath ${{env.contentpath}}

In the above snippet I will be passing app_pool_name, site_name and contentpath as parameters to the PowerShell script. All the values to the parameters will be set using environment variables in workflow file.

Below are the contents of the powershell file

param ($pool_name, $site_name, $packagepath)
Reset-IISServerManager  -Confirm: $false 
#check if the app pool exists
if  ((Get-IISAppPool).name -eq $pool_name )
{
    echo "----------------------------"
    echo "|     Pool exists          |"
    echo "----------------------------"
}
else  {
    New-WebAppPool -Name $pool_name -Force
}

Reset-IISServerManager -Confirm:$false
#check if the site exists
if ((Get-IISSite).name -eq $site_name)
{
    echo "----------------------------"
    echo "|     Site exists          |"
    echo "----------------------------"
}
else {
    New-Website -Name $site_name -ApplicationPool $pool_name -Force -PhysicalPath $packagepath -Port 8083
}

Second line of the script accepts the values that we had passed from the RUN POWERSHEL action from the workflow file. Next, script will check whether the application pool and site exist and based on the condition it will create the pool and site respectively. Here I have hardcoded the port number instead you can also pass this value as parameter by adding one more argument.

Related

Excel Keyboard Shortcuts

Below are some of the Keyboard shortcuts I use on a daily basis. Maybe helpful to others Ctrl +...

Read More >

TFS 2013 Build Template Customization

How to enable logging verbosity process parameter in build definition?Verbosity for a build will hel...

Read More >

Entity Framework CodeFirst Approach

Entity Framework Code First Approach Entity Framework is an enhancement to an existing ADO.Net ...

Read More >

Uses of MS Dynamics NAV Query Object

Query is a new object in Microsoft Dynamics NAV 2013 that a programmer can use to define a set of da...

Read More >

Using Bootstrap Validation in Asp.net Applications

Bootstrap is a powerful mobile first front-end framework for faster and easier web development. It u...

Read More >

Telerik RAD (Rapid Application Development) Controls for ASP.NET AJAX

Introduction:Telerik provides a ultimate toolbox for developers which includes Web UI Controls, Desk...

Read More >

Memory Management in iOS

Memory Management iOS In this blog we will walk through very important thing which all iOS developer...

Read More >

How to upload documents to SharePoint 2013

IntroductionSharePoint is a browser-based collaboration, content management, and extensible platform...

Read More >

How to build a client side Repeater Using jQuery and ASP.NET AJAX

jTemplate is a template engine plug-in for jQuery and is commonly used to display tabular data ...

Read More >

Share

Post a Comment

Try DevOpSmartBoard Ultimate complete Azure DevOps End-to end reporting tool

Sign Up

  • Recent
  • Popular
  • Tag
Tags
Monthly Archive
Subscribe
Name

Text/HTML
Text/HTML
Contact Us
  • *
  • *