SHIFT

--- Sjoerd Hooft's InFormation Technology ---

User Tools

Site Tools


Sidebar

Sponsor:


Recently Changed Pages:

View All Pages


View All Tags







WIKI Disclaimer: As with most other things on the Internet, the content on this wiki is not supported. It was contributed by me and is published “as is”. It has worked for me, and might work for you.
Also note that any view or statement expressed anywhere on this site are strictly mine and not the opinions or views of my employer.


Pages with comments

PageDateDiscussionTags
2019/11/18 13:52 1 Comment

View All Comments

dotnetsampleapp

Starting with .Net in Azure DevOps

In this article I'll create an Azure VM with Visual Studio Community installed, and use that to generate a sample .Net Core application so we can test builds and deployments with Azure DevOps.

Create Azure VM with Visual Studio

Create the Virtual Machine

  • In the azure portal, create a new resource group az400 in the West Europe region
  • Create a new virtual machine az400-vsc, in the same resource group and region, based on Windows Server 2019
    • sjoerd - xxx
    • allow selected inbound ports on 80, 3389
    • Standard HDD disks
    • Enable Auto Shutdown every evening on 17:30

Enable Bastion

  • Go to the just created VM, go to Connect, Go to Bastion
  • Click Use Bastion, Create a Bastion Subnet, Create a new Public IP address called az400-vnet-bastion-ip
Note: Bastion is expensive, disable and recreate the Bastion service every time you need it.

Install Visual Studio Community

From the links below download and install Edge Chromium (optional) and Visual Studio Community. During the installation of Visual Studio make sure to install the “ASP.NET and web development” workload. After the installation, Visual Studio starts, and asks to sign in, which you can also skip.

Note that during the installation you have plenty of time, so continue with the configuration of Azure DevOps and repository below

Configure Azure DevOps Project and Repository

In your Azure DevOps Organization create a new project:

  • Click New project and name the project az400, and click create
  • Once the project is created, go to Repos and click on the automatically created repo name in the top to expand the option to create a new repository
  • Name the repo DotNetCoreSampleApp and click create
  • In the newly created repo, click Clone and copy the origin url:
    • https://getshiftingcom@dev.azure.com/getshiftingcom/az400/_git/DotNetCoreSampleApp

Create a .Net Sample App

In the newly installed Visual Studio, click “Create a new project”

  • In the Search bar, search for the “asp.net core web app” template, select it from the list and click next
  • Name it DotNetCoreSampleApp, select to “place solution and project in the sam directory” and click Next
  • Select .Net Core 3.1 (long-term support) as the target framework and click create

Push to Azure DevOps

Once the project is created, go to Git and click Create Git Repository

  • Select Existing Remote and enter the url you got from the repo
  • Click Create and Push
  • You now get a login screen for the Azure DevOps service
  • Inside Azure DevOps you can now refresh the repository to see the sample app files
Note that you might have to commit the new files to the repository before they get pushed to azure devops.

Run a Build

Now the files are in Azure DevOps we can create a build. From the repository you can directly click “Set up build”. This will already setup the build to use the repository from where you are, so you can start with configuring the pipeline immediately. Select the ASP.NET Core pipeline, which will automatically create a YAML pipeline

  • From the pipeline, remove the last VSTest task from the pipeline
  • Add the “Publish build artifacts” tash to the pipeline
    • Keep all the default settings
  • Click “Save und run”.

asp.net pipeline

# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core
trigger:
- master
pool:
  vmImage: 'windows-latest'
variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'
- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: PublishBuildArtifacts@1 
  inputs: 
    PathtoPublish: '$(Build.ArtifactStagingDirectory)' 
    ArtifactName: 'drop' 
    publishLocation: 'Container'

Create Azure Web App

To deploy the web app we need to have an Azure Web App.

  • In the azure portal, click Create a Resource and select Web App from the list
    • Use the already created resource group az400, and name the web app az400
    • Set the runtime to .Net core 3.1 and the operating system to Windows
    • Set the region to West Europe
    • Create a new Service Plan, named az400-serviceplan and based on the Dev/Test F1 plan (60 minutes of runtime per day)
    • Review and create the web app.
Note that if you'd go to the Web App website, in this case, https://az400.azurewebsites.net/ , you'll now see the default deployment page telling you to upload you code.

Create a Release

Now that we have a successful build and an Azure Web App we can deploy the web application to Azure. In Azure DevOps, go to Releases and click “New Pipeline”

  • From the template list, select the “Azure App Service deployment” and click apply
  • Name the stage, for example “Dev”
  • Name the pipeline (hover over the current name), for example “AZ400 web app deployment”
  • Add an artifact, and select the DotNetCoreSampleApp build pipeline as the source
  • Configure the stage by clicking the “i job, 1 task” link
    • From the stage properties, configure the Azure Subscription and authorize it
      • If you need to create a new service connection, make sure to select Azure Resource Manager as the connection type
    • Set App type to “Web App on Windows”
    • Select he az400 App Service Name from the dropdown list
    • Click Save to save the release pipeline
  • Go back to the pipeline and click “Create Release” and click create to keep all the settings default

Once the release is finished you can go to the url of the web app, https://az400.azurewebsites.net/ , and see your .net web application running.

Resources

Discussion

Enter your comment. Wiki syntax is allowed:
E​ V Y Z V
 
dotnetsampleapp.txt · Last modified: 2021/07/13 14:40 by sjoerd