Deploying Dotnet Core web app to Azure using Github workflow
Published: 2020-01-29 12:39:06

If you need your application in a Docker container in azure you can visit this [post](https://dev.to/mkokabi/deploying-dotnet-core-to-a-container-in-azure-using-github-workflow-4gfk)

## step 1
Creating web site in Azure.
![creating web app in Azure](https://github.com/mkokabi/githubdeploy/blob/master/images/image1.png?raw=true)

## step 2
Creating a dotnet core web application
![Creating a dotnet core web application](https://github.com/mkokabi/githubdeploy/blob/master/images/image2.png?raw=true)
For this sample I named the web application *github*

## step 3
Pushing the web application to github.
![Getting the remote URL](https://github.com/mkokabi/githubdeploy/blob/master/images/image3.png?raw=true)

```shell
cd github
git init
git remote add origin https://github.com/mkokabi/githubdeploy.git
git pull origin master
git add .
git commit -m "First commit"
git push --set-upstream origin master
```
### step 4
Get the publish profile of your Azure web app.
![Get the publish profile](https://github.com/mkokabi/githubdeploy/blob/master/images/image6.png?raw=true)

### step 5
Store the contents of the publish profile in the repository secret with a name such as *azureWebAppPublishProfile*.
![Creating repository secret](https://github.com/mkokabi/githubdeploy/blob/master/images/image7.png?raw=true)


### step 6
Creating workflow
![Switching to actions tab](https://github.com/mkokabi/githubdeploy/blob/master/images/image4.png?raw=true)

### step 7
Select Setup a workflow yourself
![Start a new workflow](https://github.com/mkokabi/githubdeploy/blob/master/images/image5.png?raw=true)

### step 8
Replace the steps with
```yaml
      - uses: actions/checkout@v2
        name: checkout
      - uses: actions/setup-dotnet@v1
        with:
          dotnet-version: '3.1.100' # SDK Version to use.
      - run: dotnet build --configuration Release

      - name: dotnet publish
        run: |
          dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/github 
      - name: 'Run Azure webapp deploy action using publish profile credentials'
        uses: azure/webapps-deploy@v1
        with: 
          app-name: GithubDotNetCore  # Replace with your app name
          publish-profile: ${{ secrets.azureWebAppPublishProfile }} 
          package: ${{env.DOTNET_ROOT}}/github 
```
- The *github* in dotnet publish command is the name of my web application. You can replace it with your project name. 
- The *GithubDotNetCore* in the app-name parameter is the name of my Azure Web App. 

### step 9
Commit your changes in the yaml file (mail.yml). You can either create a new branch or directly commit it in master.

### step 10
The workflow is set to trigger on the push. As the yaml file has been pushed the worflow would be triggered. Review the Actions tab and all the steps of the workflow should get completed after a few minutes.
![The workflow complete](https://github.com/mkokabi/githubdeploy/blob/master/images/image8.png?raw=true)

Now your application should be deployed to your Azure web site.
![Perfect result](https://github.com/mkokabi/githubdeploy/blob/master/images/image9.png?raw=true)