Thursday, July 7, 2016

Microsoft's confusing dilemma with Project.json and .csproj: my experience with ASP.NET Core.

It's been quite a while since I posted here, but I'm in some kind of sweet pain and I really want to document it.

So after hanging out with Ifetayo yesterday and having a good dose of Guinness, we got back to his place at Surulere and it was pressed in my mind that I needed to continue work on the new Tiketmobile website.

Constance had designed a set of static web pages which I'm meant to add dynamic functionalities to. However, being caught between running Tiketmobile business (understanding and redesigning sales process with John, on-boarding Jacinta and intermittent phone discussions with Chijioke about business performance and the possibility of another pivot), I hadn't done much with the web pages for a couple of days. So when I got back yesterday and was watching the Portugal vs. Wales semi-final match, I was caught between dozing off and coding. Nature had its way and I passed out on the couch.

As my body is always prone to do, I awoke at 2AM and immediately reached for my computer. I had decided to use Slim framework + Twig to add PHP functionality to the static pages and invoke the original WCF service, which the back-end of Tiketmobile runs (as is the current architecture). But after having some 30 min battle with myself, I decided to re-write the back-end and eliminate WCF finally.

You see, when we first started the Tiketmobile project in 2011, REST-based Web APIs weren't quite as common place as they currently are. So we had built the back-end with WCF, a Microsoft technology closest to Web API then. I'd written the codes. However, as time went by, we'd tried out event ticketing for a very brief moment + pivoted to our current pick-up and drop-off service, on a poor architecture meant that a lot of technical debt had built up on, mainly because spaghetti codes. This is the perfect opportunity to fix it. So I'm going to rewrite the back-end.

Now, I faced another mild dilemma. Should I rewrite in the API in PHP using Slim or should I continue with C# .NET? (Yeah, I know that there's Rails and Node and Go, and all that new "cool kids" tech, but I'm not really about that life.) When I remembered all the things I take for granted in C# -- like static typing (compile-time type checking), easy multithreading, background activities, the fact that the database is SQL Server, etc -- I decided to continue with C#.

Decision was made easier when I discovered that .NET Core (Microsoft's cross-platform offering of .NET) is out. I shutdown my Visual Studio and opened up Sublime Text, downloaded the installer and everything was set-up in 15 to 30min. I created my first ASP.NET Core web application in Sublime, and ran it without IIS (ASP.NET Core ships with an in-built lightweight web server called Kestrel). I was excited that when I get that Mac, I can continue with the Tiketmobile dev whenever and on whatever platform I want to.

Time to integrate the Tiketmobile database with the current system, which meant a couple of NuGet package installations. Running everything on the command prompt, I whipped up the "nuget install" command and got all the packages I needed, but the new .NET Core project configuration (project.json) wasn't being made aware of the new packages. This meant that even though I'd installed them, I couldn't use them in my codes.

Usually, Visual Studio handles all that "bizniz", but I'd decided to stress myself about this. Hence I wasn't using VS, not even the cross-platform VS Code. So I had to worry about all the minutest settings. So I ran to Google to find out why this was happening, only to discover that Microsoft has decided to do away with Project.json and return to the traditional .csproj method of project configuration. Here's the post:

Many questions. Why did they not update the new project creation process of .NET core to not add project.json? I mean, when I run "dotnet new", it still creates a project.json. I still even had to manually create a nuget.config to tell the nuget where to search online for new packages and where to save the packages locally. Are you guys this confused?

OK, I've accepted that I still need the "supervision" of almighty Visual Studio to bootstrap the project. I'm just about to whip-up my VS and import my ASP.NET Core app into it. (They said it will automatically convert the Project.json to .csproj when I import).

Fair job so far though. But I guess Microsoft isn't quite as ready about cross-platform like I thought. Maybe they'll sort all these out in a few months and then actually give Node.js that challenge that they're aiming for with ASP.NET Core.


yayadavid said...

May be VS Code would have done a better job for you on core than sublime. You can run it on any OS as well.

Unknown said...

Issues like this occur when you try to develop outside of Visual Studio, I believe you should use VS Code which is the cross platform dev tool. I have not seen where you dev asp core outside of VS without having headaches.