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

How to enable Lync Addin and create Lync Meetings using the Outlook 2013

 How to enable Lync Addin and create Lync Meetings using the Outlook 20131.   &n...

Read More >

Authorize access to VSTS REST APIs with OAuth 2.0

Visual Studio Team Services uses the OAuth 2.0 protocol to authorize your app for a user and generat...

Read More >

TFS Build for .Net 2.0 Projects

Clients have strange requirements. The other day I had been to a client for a discussion. These guys...

Read More >

Quality is Our Mantra – Successful Completion of the Surveillance Audit

Canarys has successfully completed the Surveillance Audit and has been certified for ISO 9001:2008. ...

Read More >

New Tools in NAV 2013 (the less talked about ones) - Part 1

For some time now, I have been thinking about compiling on a list of new features and subtle tools i...

Read More >

How to run NAV 2015 and NAV 2016 Administration tool side by side

Everyone would have installed NAV 2016 RTM and would have faced the same problem, i.e, you couldn...

Read More >

Database deployment using GitHub Actions

In this blog, I will be showing how to export the database file from SQL Server and import the same ...

Read More >

Creating an RDLC report in Asp.Net

Step 1.  Create a new website and Add DataSet to the WebsiteRight Click on the project, Add new...

Read More >

Don’t Postpone Digital Transformation, but Firm up on the Strategy during COVID-19 pandemic

Trust you and your teams are safe!The recent outbreak of COVID-19 has affected lives around the worl...

Read More >

Share

Post a Comment

  • Recent
  • Popular
  • Tag
Monthly Archive
Subscribe
Name

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