Blog: Software Development

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 VSTS NuGet package feed with the .NET Core CLI

July 28, 2018, 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), 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, 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), 11 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

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: , , , ,

Aurelia JS: Detect dirty checked properties during development

March 29, 2017, (updated on October 6, 2017), 2 comments, Software Development

I am currently working on new single-page web application based on the Aurelia framework. To avoid performance problems, we want to completely avoid dirty checked properties and method calls. Bindings are dirty checked whenever the framework cannot use another mechanismn than regularly polling for changes. It is important to detect dirty checked properties as early as possible so that they can direcly be avoided and not too many depenencies have to be changed. I found a simple solution: Just intercept the dirty check subscription method and print the name of the dirty checked property name to the console. In your […] Read more...

Tags: , ,

Implement custom MSBuild tasks and distribute them via NuGet

January 31, 2017, (updated on May 15, 2018), 5 comments, Software Development

In this article describes how to implement MSBuild tasks with inline C# or in an external .NET assembly. After doing so, we will bundle these tasks in a NuGet package, so that they can easily be distributed and updated via NuGet and executed as part of the MSBuild compilation process. This is a powerfull technique to share and manage MSBuild tasks (e.g. build scripts, code generators, etc.) in bigger environments (enterprises, open-source libraries, common/shared tasks). Write simple task with inline C First we implement an MSBuild task with inline C# code. For the purpose of this article, a simple “Hello […] Read more...

Tags: , , ,


  Page 1 of 7 Next Page »