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

How Microsoft Dynamics CRM workflow definitions are stored in the SQL Database

Microsoft Dynamics CRM, is one of the prominent offerings from the Microsoft Dynamics family of ERP ...

Read More >

THE RAZOR VIEW ENGINE IN MVC

View Engine is responsible for rendering the view into html form to the browser.ASP.NET MVC includes...

Read More >

Microsoft VSTS Consulting

At a time when businesses are attempting to attain the highest possible degree of standardization an...

Read More >

How to write custom code in NAV 2013 R2 Report layout design?

You may want to add custom code to the RDLC report to do more actions than what's already provid...

Read More >

Data Mining for Supply Chain Management

IntroductionMarket turbulence arising from factors such as rapid introduction and customization of p...

Read More >

Create a simple Chatbot App using Botframework & Xamarin.Forms

We can integrate Chatbot API with Xamarin.Forms App using two methods, Embed Code with Web View or N...

Read More >

Handling Radio buttons and Checkboxes using Selenium Webdriver

The main difference between Radio button and Checkbox is that, using radio button we will be able to...

Read More >

Microsoft Azure : Machine Learning - Price Prediction

We'll create linear regression model that predicts price of automobile based on different variab...

Read More >

Unit testing in .NET

Unit Testing – ExplainedA process which involves writing code to verify a system at a lower an...

Read More >

How to Create a Provisioning profile for iOS

To Run an app on iOS device,you must have a Provisioning Profile installed on your device. ...

Read More >

Share

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

Sign Up

  • Recent
  • Popular
  • Tag
Monthly Archive
Subscribe
Name

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