Posts

Setup Continuous Integration and Deployment for dotnet library with Appveyor and FAKE

Setup Continuous Integration and Deployment for dotnet library with Appveyor and FAKELast week we saw a flow to manage versioning and releases. As a continuation of last week, today I will show how we can setup versioning and releases for open source projects by configuring Appveyor and using FAKE to setup a build script.Configure AppVeyorFAKE1. Configure AppVeyorConfiguring AppVeyor is done via a yaml file appveyor.yml at the root of the repository. Then from the site https://www.appveyor.com/, we can sign in with our GitHub credentials and add the repository to the AppVeyor projects. All the settings in the settings tab can be configured in the yaml file.appveyor.yml settings can be seen in multiple sections:global environmentbuildtestartifactdeployThe global configuration is where we configure the context of the build,# 1. version: '{build}' image: Visual Studio 2017 skip_branch_with_pr: true skip_commits: files: - docs/**/* - '**/*.md' - .gitignore pu…

Versioning for open source library

Versioning for open source libraryFew weeks ago I explained how Gitversion can be used to apply semantic versioning to projects based on commit and tag history.
Today I will dive deeper in the purpose of versioning and introduce a flow which can be followed to version open source project libraries by looking into four important parts in the lifecycle of an open source library.Version with Semantic versioningBranching strategy and CommitsContinuous Integration and Releases1. Version with Semantic versioningSemantic versioning is ideal for versioning libraries. It is formed by three numbers {major}.{minor}.{patch}. Each number is used to indicate to the user the level of safety for upgrading the library.Upgrade of the major is risky and has chances to contain breaking changes, therefore looking at release notes or looking for migration would be recommended.Upgrade of the minor has lesser risk and can be used to show availability of new features.Upgrade of the patch is not risky and is u…

Implement timeout and retry policies for HttpClient in ASP NET Core with Polly

Implement timeout and retry policies for HttpClient in ASP NET Core with PollyFew weeks ago I explained [how to use the new HttpClientFactory. This freed ourselves from managing the confusing lifecycle of a HttpClient and at the same time allowed us to setup commmon options like base address for all HttpClient injections in our classes. Today we will see how we can setup timeout and retry policies for the HttpClient in in ASP NET Core using Polly.Setup a simple service using HttpClientInstall Polly extensions for ASP NET CoreSetup Polly policies1. Setup a simple service using HttpClientIn the previous blog post we saw how we could setup a HttpClient and register it to the service collection.Here is a simple service client which will be injected throughout the application:public interface IMyApiClient { Task<HttpResponseMessage> Get(); } And here is the implementation:public class MyApiClient : IMyApiClient { private readonly HttpClient _client; public ApiClient(Http…

Continuously deploy infrastructure with GitLab Pipeline

Continuously deploy infrastructure with Gitlab PipelineFew weeks ago we saw how we could Setup continious integration and deployment to deploy an application using Gitlab Pipeline. We configured a service with systemd and had an ASP NET Core application automatically deployed when code was pushed to the repository. This automation allows us to reduce interaction with the server and reducing the manual work. The “infrastructure” configurations like systemd service files and nginx site files must also be created or edited on the server therefore it makes sense to also have them automatically deployed. On top of that, it makes even more sense to have them save in repository and source controlled. Today we will see how we can leverage Gitlab Pipeline to setup a continuous deployment for our infrastructure files in three parts:Setup the repositorySetup the runner jobDeploy the configurations1. Setup the repositoryWe start first by creating a repository with the same structure as our server…

Inspect proxied requests from Nginx to Kestrel with Mitmproxy

Image
Inspect proxied requests from Nginx to Kestrel with MitmproxyIn previous blog posts, we saw how to proxy requests to an ASP NET Core application using Nginx. We saw that request headers also can be proxied with proxy_set_header In order to ease development, we need to be able to debug the values to verify that they are what we expect.
Today we will see two methods to inspect the proxied requests. This post will be composed by two parts:Nginx location routingNginx variable debuggingNginx proxied request debug with Mitmproxy1 Nginx location routingConsidering the following configuration of our server:server { listen 80; location / { proxy_pass http://localhost:5000; } location /api/ { proxy_pass http://localhost:5001/; } } If we want to check whether our location routes are properly configured, we can short circuit the proxy_pass with return and use curl to check whether the location is properly selected.server { listen 80; location / { …

SDK-Style project and project.assets.json

SDK-Style project and project.assets.jsonLast week I encountered an issue with MSBuild while trying to run it from command line.
The issue did not appear when using VisualStudio right click + build but only appeared when using msbuild.exe CLI directly with a clean project.Assets file 'C:\[...]\obj\project.assets.json' not found. Run a NuGet package restore to generate this file. When I first saw the error, few questions came to my mind which I will share today in 3 points:Overview of project.assets.jsonSlim SDK-Style projectMixing SDK-Style project and old projectsSpecial shoutout to @enricosada who provided me with all the answers regarding the SDK-Style project.1. Overview of project.assets.jsonproject.assets.json lists all the dependencies of the project. It is created in the /obj folder when using dotnet restore or dotnet build as it implicitly calls restore before build, or msbuid.exe /t:restore with msbuild CLI.To simulate dotnet build (restore + build) for .NET Framewor…

ApiController attribute in ASP NET Core 2.1

ApiController attribute in ASP NET Core 2.1ASP NET Core 2.1 brings a set a enhacements for Web API development, Web API being a service accessible via HTTP and returning result in Json format. Those enhancements aim to simplify the composition of those APIs and also remove unecessary functionalities. Today we will explore those enhancements in five partsControllerBaseand ApiControllerAutomatic model validationInferred model bindingActionResult<T>1. ControllerBase and ApiControllerPrior everything, we should set the compatibility version of ASP NET Core by using the .SetCompatibilityVersion.services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); In the past, we used to inherit from Controller which was providing functions to return different HTTP status code results together with optional data like Ok(...) or Json(...), but it was also used to display Razor views like View(...) or PartialView(...).Starting from 2.1, it is now recommended to inherit from Contr…