Archive

Archive for the ‘vNext’ Category

Enabling CI for .net core using TFS Build

October 10, 2016 Leave a comment

At the moment there is no easy way to implement CI for .net core projects. Ideally it should be published and deployed to individual instances of nano servers, but that might be something beyond the capability of TFS Build.

Should you wish to implement CI for .net core projects on TFS 2015, here are the build steps and scripts that you need.

  1. Step 1: Install .net core
    Download https://docs.microsoft.com/en-us/dotnet/articles/core/tools/dotnet-install-script and either place it inside TFS or else in a central location. This will install and setup the .net Core CLI Runtime for the service account that is used by the build servers
    image
  2. Step 2: Run dotnet restore and dotnet publish
    Download and modify the powershell script found at http://pastebin.com/yyjbGDW9. It assumes that each folder is an individual .net core project that needs to be published. Modify accordingly to your environment

    It is important to add in the OutputDir argument as that defines where the published project goes
    image

    As this builds all the projects, you may also want to check “Continue on error”
    image

  3. Step 3: Deploy to the servers
    You can find the script I use at http://pastebin.com/8jBHz3Zf. Important thing to note is that you need to first stop IIS on the target server before copying the files over as running net core on IIS locks the dll files
    image

Dependency Injection in ASPNET VNext (RC1)

February 23, 2016 Leave a comment

This article will document how to do dependency injection for vNext

1. Create the class to be injected (https://gist.github.com/kwanann/a0363add23870a949334)

image

2. Configure startup.cs (https://gist.github.com/kwanann/7bced8e22fec229bd0be)

image

There are 4 methods of adding to services

AddTransient: It will create a new instance each time it is accessed. e.g when I call it from the MVC Controller and from frontend MVC code, I will get 2 independent instances

AddScoped: It will create a new instance for the particular request, e.g when I call it from MVC Controller and frontend MVC Code, it’s the same instance. However it does not survive across different OWIN middleware

AddSingleton: Creates a single instance for all requests

AddInstance: Creates a single instance for all requests, but the constructor is left to the developer

3. If you need to call it from within the MVC Controller (https://gist.github.com/kwanann/c987314e0eecdab20a7b)

image

Inject the interface you need into the constructor and then assign it to a local variable. You may then use it however you wish

Categories: 5.0, ASP.NET, vNext