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

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

import-module webadministration
param ($pool_name, $site_name, $packagepath)

#check if the app pool exists
if(!(Test-Path IIS:\AppPools\$pool_name ))
{
    #create the app pool
    New-WebAppPool -Name $pool_name -Force
}
else {
    echo "Pool exists"
}

#check if the site exists
if(!(Test-Path IIS:\Sites\$site_name  ))
{
   New-Website -Name $site_name -ApplicationPool $pool_name -Force -PhysicalPath $packagepath -Port 8083
}
else {
    echo "site exists"
}

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

HTML Parser

Are you looking for any HTML Parser?Want to traverse through HTML DOM elements?Want to read properti...

Read More >

Converting UserControl into a dll

User controls are containers into which you can put markup and Web server controls. You can then tre...

Read More >

Identifying Web Elements using Selenium Webdriver

What is Web Element?             &n...

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 >

How to download YouTube Videos using .NET

Are you interested in downloading YouTube Videos?Want to download YouTube Videos in device specific ...

Read More >

Windows 8 Shortcut Keys -Useful

HotkeysPressing the Windows key and some specific keys can make you life easier. Here are some usefu...

Read More >

DevOps with Visual Studio Team Services for Java

Hi All, if you are worrying how to do DevOps for Java in VSTS, here is the solution. I’m going to e...

Read More >

How to use AngularJS Services and Controllers

Here in this blog I am going to show some advanced and common functionalities of Angular JS which ca...

Read More >

New and Important things to know for better RDLC report design in NAV 2013 R2.

We are all learning new things about RDLC report design and we know that still there are lot of thin...

Read More >

Share

Post a Comment

  • Recent
  • Popular
  • Tag
Tags
Monthly Archive
Subscribe
Name

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