14/05/2018

How to use Roslyn with .NET Core?


Title: Baths of Caracalla in Rome, Source: own resources, Authors: Agnieszka and Michał Komorowscy

When we started PlatformX project, we were using full .NET Framework and it was natural to use Roslyn in order to read and analyse C# code. I have to admit that Roslyn, despite some initial problems (see other posts about Roslyn), managed to do the job. However, later on we decided to migrate PlatformX to .NET Core. There were a few reasons behind this decision:
  • We anticipated that in future we may want move to Linux server for example to reduce costs.
  • .NET Core is faster. To give you an example. After migration builds turned out to be 1.7 times faster and tests 2.6 times faster!
  • Before migration we had to support 2 versions of our infrastructure libraries (.NET Framework + .NET Core) what was a little bit cumbersome. Now we support only one.
  • If we had waited, we would have spent more time on the migration later.
Despite all these advantages the migration to .NET Core meant a problem with using Roslyn. This problem is called MsBuildWorkspace. It is the class that allows you to point a solution or a project, read it and then analyse it a file after a file. Unfortunately MsBuildWorkspace is not supported in .NET Core. I think that the main issue is that under the hood it uses MS Build which is not cross-platform.

Because nowadays .NET Core projects can actually reference full .NET Framework libraries (of course it kills portability), firstly we simply tried to do so. But without much success. MsBuildWorkspace simply cannot handle .NET Core projects. The actual effect was that according to MsBuildWorkspace there were no files in a project being analysed.

Fortunately, the rescue came from Buildalyzer project which does exactly what MsBuildWorkspace should do and it works like a charm. Here is how we use Buildalyzer:
var sb = new StringBuilder();
var writer = new StringWriter(sb);

var manager = new AnalyzerManager(solutionPath,
   new AnalyzerManagerOptions
   {
      LogWriter = writer
   });

foreach (var prj in manager.Projects.Values)
{
   // GetWorkspace returns Microsoft.CodeAnalysis.AdhocWorkspace which can be used with Roslyn
   var workspace = prj.GetWorkspace();

   // Starting from here the code does not depend on Buildalyzer
   var sln = workspace.CurrentSolution;

   await AnalyzeProject(sln.Projects.First());
}

writer.Close();

_logger.Write(sb.ToString());
As to AnalyzeProject method, it is responsible for analyzing all files in the project. What is important it DOES NOT depend on Buildalyzer at all. I really didn't have to change a line after switching from MsBuildWorkspace to Buildalyzer and it is amazing. Just a few lines of extra code and you can take all advantages of Roslyn in .NET Core projects in order to analyse other .NET Core projects.

*The picture at the beginning of the post comes from own resources and shows Baths of Caracalla in Rome.

20/04/2018

CareerCon 2018 - The best mix in history - DDD, CQRS, Event Sourcing and others




For years I was designing and developing "classical" applications. Then I entered the new world of DDD, CQRS, Event Sourcing... and it was an extremely refreshing experience. It wasn't easy all the time but I do not regret and I decided to share my experiences.

On 24th March I gave a presentation under the title "The best mix in the history - DDD, CQRS, Event Sourcing and others?" at CareerCon 2018 conference. I tried to show benefits but also drawbacks of using DDD, CQRS and Event Sourcing.

I'm glad with this presentation. It took as much time as I assumed and there were really many questions at the end. Majority of them were about Event Sourcing. It looks like a very hot topic nowadays.

The results of the surveys also confirm that the presentation was well received :) Thanks, it really motivates me.


If you are interested in DDD, CQRS and Event Sourcing and you would like to hear about that at another conference or in your company, do not hesitate to ask me.

And here you can find the presenation:



*The picture at the beginning of the post comes was provided by organizers of the conference.

19/11/2017

Will Artificial Intelligence replace developers (part 2)?


Anatomy-1751201 1280


This is a part 2 of the overview of different AI solutions automating the programming process. The part 1 can be found here. Today I will describe another 5 "virtual developers".

13/11/2017

Will Artificial Intelligence replace developers (part 1)?


Anatomy-1751201 1280


After 10 years of working for smaller and bigger companies I decided to join as Chief Scientific Officer a start-up called PlatformX. I'll not exaggerate saying that it's the most interesting and challenging project I've ever worked in. Our goal is to automate the process of developing software. In other words we want to create an artifical intelligence a.k.a. "virtual developer" that will be able to communicate with a human being in order to collect requirements and then will write, test and deploy a program according to these requirements. Nice, isn't it?

30/10/2017

Never ever update an event. But why?




I heard and read a lot about Event Sourcing (ES) but earlier I hadn't had occasion to use it in the real-life system. This year I got this opportunity :) For many years I was working with traditional architectures so ES + CQRS + DDD is like a new world to me. Very refreshing experience! I've already learned a lot but I'm still learning and discovering new things. For example, not so long ago the versioning of events was "mysterious" for me.