About Me

My photo
I am an MCSE in Data Management and Analytics, specializing in MS SQL Server, and an MCP in Azure. With over 19+ years of experience in the IT industry, I bring expertise in data management, Azure Cloud, Data Center Migration, Infrastructure Architecture planning, as well as Virtualization and automation. I have a deep passion for driving innovation through infrastructure automation, particularly using Terraform for efficient provisioning. If you're looking for guidance on automating your infrastructure or have questions about Azure, SQL Server, or cloud migration, feel free to reach out. I often write to capture my own experiences and insights for future reference, but I hope that sharing these experiences through my blog will help others on their journey as well. Thank you for reading!

Deploy .NET Application using CI/CD

using YAML files to define the build environment is a common approach when setting up a build pipeline for a .NET project. This can be done using a tool like Azure DevOps, which allows you to define your build pipeline using a YAML file called azure-pipelines.yml.

Here is an example of a YAML file that sets up the build environment for a .NET Core project:

# define the build environment

pool:

  vmImage: 'windows-latest'

# define the build steps

steps:

- task: UseDotNet@2

  inputs:

    version: '3.1.x'

- script: dotnet build --configuration Release

  displayName: 'dotnet build'


# define the build environment

pool:

  vmImage: 'windows-latest'


# define the build steps

steps:

- task: UseDotNet@2

  inputs:

    version: '3.1.x'

- script: dotnet build --configuration Release --framework netcoreapp3.1

  displayName: 'dotnet build'


you can use YAML files to configure the build process for a .NET project in Azure DevOps.

In this example, the dotnet build command is run with the --configuration Release and --framework netcoreapp3.1 flags. 


The --configuration flag specifies the build configuration (e.g. Release or Debug), and the --framework flag specifies the target framework for the project (e.g. netcoreapp3.1, net5.0, netstandard2.0 etc).


You can also use the YAML file to configure other build options as well. For example, if you are using a specific version of a library, you can install that version by adding a step for nuget install command.


It's important to note that you can customize the pipeline to meet your requirements, and you can add more steps to your pipeline as per your project requirements.



# define the build environment

pool:

  vmImage: 'windows-latest'

# define the build steps

steps:

- task: NuGetCommand@2

  inputs:

    command: 'install'

    packagesToInstall: 'Newtonsoft.Json'

    version: '12.0.3'

- task: UseDotNet@2

  inputs:

    version: '3.1.x'

- script: dotnet build --configuration Release --framework netcoreapp3.1

  displayName: 'dotnet build'


In this example, the NuGetCommand@2 task is used to install the Newtonsoft.Json package with version 12.0.3. This is added as the first step in the pipeline, before the dotnet build command is run.

It's important to note that, you can install multiple packages by providing comma separated package names. Also, you can use wildcard (*) to install packages with specific version pattern.

It's worth noting that the above example is just one way to install NuGet packages, you can use other alternatives as well such as Nuget.exe command line.

It's also worth noting that you can customize the pipeline to meet your requirements and you can add more steps to your pipeline as per your project requirements.

No comments: