Blog

Azure DevOps: Create a Web App for Containers CI/Release pipeline for an ASP.NET Core app

October 17, 2018, Software Development

In this tutorial we will: Step 1: Build an ASP.NET Core app and push the sources to a Git repository Step 2: Setup the required Azure resources (Web App for Containers, etc.) Step 3: Setup an Azure DevOps CI build which builds a Docker image and pushes it to a private Azure Container registry (ACR) Step 4: Create an Azure DevOps release pipeline which deploys the new Docker image to a Linux based Web App for Containers (App Service) Important: The tutorial is using the name DockerDemo for the demo project and Azure resources. It is recommended to use a […] Read more...

Tags: , , , , , , ,

C# 8: The output of Nullable Reference Types and how to reflect it

September 28, 2018, (updated on October 15, 2018), 2 comments, Software Development

After reading some articles about the new C# 8 feature Nullable Reference Types, one question still was unanswered: How does a compiled assembly with nullable types enabled look like and how can I access the nullability information via reflection? Because I couldn’t find an article with an answer, I had to figure it out myself. First I wrote a simple class which I wanted to analyze: [module: System.Runtime.CompilerServices.NonNullTypes(true)] class Test { public string? Foo {get; set;} public void Bar(string? baz, string buz) { } } With the help of sharplab.io I compiled it with C# 8 and looked at the […] Read more...

Tags: , , ,

Missing SDK when using the Microsoft.Build package in .NET Core

August 31, 2018, (updated on September 1, 2018), Software Development

When I tried to use the Microsoft.Build package in my DNT CLI to read .NET .csproj files in a .NET Core app, I got the following error: Microsoft.Build.Exceptions.InvalidProjectFileException: The SDK 'Microsoft.NET.Sdk' specified could not be found. at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args) at Microsoft.Build.Evaluation.Evaluator`4.ExpandAndLoadImportsFromUnescapedImportExpressionConditioned(String directoryOfImportingFile, It seems that the problem can be fixed by manually setting the MSBUILD_EXE_PATH environment variable. I wrote a simple method which loads the latest installed binary and sets the variable: static void Main(string[] args) { SetMsBuildExePath(); // TODO: Add code } private static void SetMsBuildExePath() { try { var startInfo = new […] Read more...

Tags: ,

Use a private Azure DevOps/VSTS NuGet package feed with the .NET Core CLI

July 28, 2018, (updated on October 22, 2018), 1 comment, Software Development

If you have a .NET Core project which references a NuGet package from a private VSTS package feed, you cannot just build the project in CLI because you are not authorized to access the feed: When running dotnet restore, you’ll end up with this error message: error: Response status code does not indicate success: 401 (Unauthorized). To fix this problem, you can register the private NuGet feed with a VSTS personal access token (PAT). This article shows how to do that. 1. Create personal access token (PAT) on VSTS Navigate to your VSTS site, go to the “Security” settings (top […] Read more...

Tags: , , , ,

How to publish an NPM package in AppVeyor

June 17, 2018, (updated on July 14, 2018), 2 comments, Software Development

For some open-source projects I need to publish NPM packages during the CI release on AppVeyor. Unlike with NuGet packages, you have to do that manually by installing NodeJS and NPM, creating an .npmrc file with your NPM credentials and publishing the package. This blog post describes this procedure in detail. Retrieve auth token To authenticate with the npmjs.org NPM feed, you have to manually retrieve the npmjs.org auth token. To do so, you have to first login to NPM via CLI: npm login This command creates or updates the .npmrc file in your local user directory (‪C:\Users\MyUser\.npmrc). The file […] Read more...

Tags: , , , , , ,

Automatically migrate your Entity Framework Core managed database on ASP.NET Core application start

March 20, 2018, (updated on September 20, 2018), Software Development

If you use Entity Framework Core with migrations in your ASP.NET Core application and want to ensure that the database structure always matches the currently running application, you can simply migrate the database on application startup. This way you just have to redeploy your application and everything like migrating the data, change the schemas, etc. is done when the application is restarted. To do an automatic migration, register your DbContext implementation in the ASP.NET Core’s dependency injection system – the same way as it is already recommended by Microsoft. Because there is no active injection scope in the Configure() method, […] Read more...

Tags: , , ,

Advanced Newtonsoft.Json: Dynamically rename or ignore properties without changing the serialized class

November 2, 2017, (updated on July 27, 2018), 13 comments, Software Development

This article describes how to implement a custom contract resolver, so that you can ignore or rename serialized JSON properties where the serialization happens and without changing the serialized classes. I use this resolver in my project NSwag, a Swagger/Open API toolchain: A Swagger specification uses JSON Schemas to describe types, but it is not exactly the same model – some properties of a schema are not allowed and some must be renamed. Because I cannot change the JSON Schema implementation, I had to ignore or rename properties in the Swagger serializer. Another use case of this contract resolver is, […] Read more...

Tags: , , ,

NSwag Tutorial: Implement a custom operation processor to define ReDoc code samples

November 1, 2017, (updated on November 2, 2017), Software Development

With NSwag you can implement custom operation processors and apply them to ASP.NET Core MVC or Web API controller operations. These processors then get picked up by NSwag and are applied to the given operation in the Swagger specification. This article shows how to implement a custom operation processor using the example of adding code samples to the ReDoc UI. The ReDoc UI processes the x-code-samples property on operations. Here is a sample Swagger specification: { ... "paths": { "/person": { "post": { "summary": "Adds a new person.", "operationId": "addPerson", "x-code-samples": { "lang": "CSharp", "source": "console.log('Hello World');" } ... } […] Read more...

Tags: , , , ,

How to instantiate a generic type in TypeScript

August 1, 2017, (updated on October 12, 2018), 8 comments, Software Development

In C# we can define a generic type argument and instantiate this type at runtime: public class Factory { public T Create<T>() where T: new() { return new T(); } } var factory = new Factory(); var person = factory.Create<Person>(); But how would you write such a method in TypeScript? The main problem is, that the generic type argument T is not available at runtime because TypeScript generics are only used at compile time for type checking and removed in the transpiled JavaScript code. The best solution I came up with, is to pass the generic type as method argument […] Read more...

Tags:

Use T4 TextTemplatingFilePreprocessor in .NET Standard or PCL libraries

For my projects NJsonSchema and NSwag I wanted to use T4 templates to programmatically generate code generating code (TextTemplatingFilePreprocessor). Adding the .tt file with its generated C# class works, even if the files are added to a PCL (Portable Class Library) or .NET Standard 1.0 project. The problem is, that the produced code does not compile because the used PCL Profile 259 (same as .NET Standard 1.0) is missing some required classes and reflection methods. To fix the compiler errors, you have to provide the missing types and methods in your assembly. To avoid name collisions with potential client assemblies […] Read more...

Tags: , , , ,


  Page 1 of 7 Next Page »