Running the Microsoft .NET Stack on a Fresh MacBook Pro

Well, after parting ways with Flightdocs, one of the first things I needed to do was get my own laptop and get back to work. The days of spending $2,500–3000 on a nice machine under the generosity of the business were over, and I settled for a slightly smaller, less powerful, but still pricey little MacBook Pro for around $1,800. I suppose there are people in this world that dread setting up a new computer, but for me, it’s one of the best feelings. A brief pause of tranquility and then the rush of excitement that comes with a fresh start and new possibilities.

Since 2005, I’ve worked with .NET, and though at times I’ve cursed Microsoft for so many things, I always come back to C#. Yes, I proudly proclaim myself a polyglot developer who loves new languages, but there is comfort and confidence in the familiar. So, with that in mind, let’s get setup to build enterprise-grade .NET software on our sleek little budget-friendly-not-so-friendly MacBook Pro!

Installation Disclaimer

Not all of the following installations are required, but these are my recommendations for getting setup to be able to cover a variety of common development tasks.

Node.js and NPM

Package managers are fantastic, it’s weird to think that many of us didn’t use them hardly at all even a couple of years ago. I tend to use Node.js for a variety of web development tasks, but even if you’re not going down that route, having NPM is a great way to pull down web-frontend libraries now that bower is deprecated. Head to https://nodejs.orgto download a fresh copy.


Why XCode when installing Visual Studio? First, Visual Studio for Mac uses many of the Xamarin components which tied in to the development tools for XCode, creating a dependency. Second, you might as well sharpen those mobile skills or at least have a sandbox-knowledge of Swift/Objective C if you are a developer and own a Mac.

Microsoft Visual Studio for Mac

Look at that, I finally got to the part where we install Visual Studio. Head over to get the bits. There should be a Community Edition that you can start with before shelling out any money. Also, many developers may not realize, but Microsoft does now offer monthly MSDN subscriptions which includes licensing for Professional/Enterprise versions of Visual Studio. Of course, I’m in favor of not spending any money at all if possible.

If you’re not familiar with Visual Studio, it’s a fairly rich (bulky) IDE for development, but the Mac version is quite a bit lighter than it’s Windows counterpart. In my opinion, it’s not as powerful or stable on Mac, but has quite a bit of charm. Since we’re in the Visual Studio for Mac section of this post, let’s briefly talk about Visual Studio Code as well. I recommend also installing Visual Studio Code from https://code.visualstudio.comeven if you don’t write in C# or another similar Microsoft-dominated language. It’s a solid code editor that rivals Sublime, Atom, or Brackets. Visual Studio Code is lightweight, very stable, and extremely extensible. Also, I frequently write my complex API code in the full blown Visual Studio IDE while writing my web application code in Visual Studio Code. Personal preference, I’m sure but I don’t think I’m alone in this combination.

At this point, you’ve got most of what you need to develop .NET applications on a Mac. However, if you actually want to persist any data in your application, you’ll likely need to setup a database.

It is pretty amazing how database offerings have changed in the past five or so years. You’ve got so many options on Linux/Unix based operating systems such as Postgres, MySql, Mongo, and tons more. But, if you’ve been working in MSSQL for the past decade+, you may be blown away to know you can run MSSQL on your Mac as well! Now would be a good time to check outside your window and see if you actually spot pigs flying.

SQLite and MS SQL

SQLite DB is available to run locally on your machine and it’s straight forward. If you’re using Entity Framework, simply point your connection string to a local file and initialize the database. However, if you want an IDE for accessing the data I tried DB Browser for SQLiteand it worked well for me.

Now, onto the really fun stuff — MSSQL on your Mac. You’ll need to install Dockerand a specific image for SQL Server which you can pull using the following command:

docker pull microsoft/mssql-server-linux

Once you’ve got Docker up and running and pulled down this image, you will need to step through a bit of configuration. Microsoft did a nice job of documenting this in the following link: I’ll wait while you spend the next 15 minutes working it through.

… Intermission …

Done? Fantastic, at this point you should be able to debug a nice WebAPI through Visual Studio for Mac pointing to a full MSSQL database running on Docker, and call everything from your web application that you’re editing through the lightweight Visual Studio Code. Did a few of you cringe at how many Microsoft products you used? Don’t stress! In a few years, the young new developers will start telling all of their Ruby and Python friends about this hot new open source language called C#.

Happy coding my fellow evil-empire-turned-friendly-open-source-contributerfriends.

The Stored Procedure for Searching Challenge

The Problem

You have a table chock full of good business data. This data needs to be accessed by a host of potential search criteria and any combination of that search criteria. What’s the most elegant way to right a stored procedure which accepts multiple parameters as search criteria but only returns the records that relate to the combination of search criteria and accommodates for nulls and empty strings as well.

The Constraints

  • We want search criteria specified to match the record value in field
  • We want empty string to match empty or null records
  • We want null to not include the search criteria in the filter

The Setup

A very basic table to begin with (let’s call it TestingSqlSearchData for consistency):

ID Name
1 Nick
2 John
3 Mary
5 Casey

A Solution (hopefully not “the” solution)

declare @Name varchar(50) = null; --(or 'ni' or '')
select * from TestingSqlSearchData
where isnull(Name, '') LIKE 
	(case when @Name = '' then '' else '%' end) + 
	(case when @Name is null then isnull(Name, '') else @Name end) + 
	(case when @Name = '' then '' else '%' end);

This returns the following for each example:

@Name = null

ID Name
1 Nick
2 John
3 Mary
5 Casey

@Name = ‘ni’

ID Name
1 Nick

@Name = ”

ID Name

The Challenge

The challenge is quite simple; we want to demonstrate more elegant solutions to this SQL scenario. You can use any SQL-based approach to accomplish this. If anyone wants to take up the challenge you can submit your solutions (complete with an explanation as to why it is more elegant – as this is not always apparent to everyone else) in the comments below.

P.S. – I really hope to see some comments, so don’t be shy! And, if no one comments, I’ll still leave the post up for at least one solution to this scenario. Who’s going to win bragging rights?

Running SSMS Under Another Windows Authenticated User

Why do this?

Recently, I’ve been using Ubuntu as a host operating system and running virtual machines for my various development and sandbox server environments. This has led me to not particular want to register all of my client VM’s with our work domain and just pass my credentials when needed. For most applications this works fine; however, with SQL Server Management Studio to login to databases with Windows Authentication it appears you can only use the currently logged in user rather than prompting for credentials.

Can you do this for other applications?

Absolutely, this is basic functionality in the OS; however, since most applications simply prompt for AD credentials instead of binding you to the current logged in local user account, it’s less common than you would think.

Here is the command line:

runas /netonly /user:[domain]\[username] "[ssms_exe_path]"

For example:

runas /netonly /user:workdomain\nbarger "C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe"

P.S. – you can also add this to your Target in the property window of any SSMS icon for convenience.