Getting started with dotnet CLI

Dotnet CLI is a command line interface used for working with .NET projects. It’s not something new in .NET world. It was established in 2015. Back then there was another try with DNX in 2013 – not very successful.

Why to bother CLI?

You do not need CLI if you work with .NET code only from perspective of Visual Studio. CLI is really needed if you want to setup build pipeline, because build agent does not have to have Visual Studio installed. But let’s not forget about .NET migrating from Windows to the world. From now on you can run it everywhere (far far away there are systems without *.exe files) and build it with notepad, VIM or emacs. And that’s when dotnet CLI comes in.

It’s also valuable in Windows – from time to time you may want to automate your job by running specific tests just before “git commit” or run the application simply, without knowing full “../bin/Debug/net461” location.

Solution file

When working with dotnet CLI you can see that the solution file is no longer needed. Actually now it is fully based on solution folder containing necessary projects. If you want to build/run some project, you need to run “dotnet run <path/to/project/folder>”. It should build all dependencies as well. You can also run “dotnet restore” command in “solution” folder which should restore dependencies for all the projects inside. It’s very useful when creating new solutions. The only thing to do is preparing folder structure for the new solution and running “dotnet new” in each of them.


New dotnet CLI can be downloaded from here:

While installing, I prefer to download *.zip package and extract it to my known place without affecting the whole system. Doing so remember about adding “dotnet” location to PATH or adding alias.

Finally you should be able to run the following commands:

# list all available project templates
dotnet new

# create new xunit test project
dotnet new xunit

# restore projects dependencies (can be run in solution folder)
dotnet restore

# build specific project (run without parameter when in project's folder)
dotnet build .\src\project1

# run tests in project (run without parameter when in project's folder)
dotnet test .\test\project1.Tests

# add package to project
dotnet add .\src\syncfiles\Syncfiles.csproj package Newtonsoft.Json

# add project reference
dotnet add .\test\Syncfiles.Tests\Syncfiles.Tests.csproj reference .\src\syncfiles\Syncfiles.csproj

# create deployment package
dotnet publish .\src\syncfiles

Other commands

There is a list of commands we can use when working with .NET projects:

new Creates a new project, configuration file or solution based on the specified template
migrate Migrates existing project from project.json to *.csproj version
restore Restores dependencies of a project.
run Runs the project. Alternative to running produced *.exe file in Windows. Unified way of running .NET project for all supporter operating systems. It runs “dotnet build” when needed.
build Builds the project. It does not run “dotnet restore” automatically – you have to run it manually prior to building the project
test Runs test project with specific test runner (restored with other dependencies). You don’t have to select anything.
publish Packs the application and all of its dependencies into a folder getting it ready for publishing. Such folder can then be deployed to desired environment.
pack Packs the code into a NuGet package.
clean Cleans build outputs
sln Add/remove projects in solution
add Add project reference or package from nuget repository
remove Remove project reference or package
list List project dependencies
nuget Publish package to nuget server or delete it
msbuild Wrapper for msbuild.exe
vstest Wrapper for vstest.console.exe
help Shows help screen

DSP2017 again – introducing my project

DSP2017 has just begun. Last year I started and sank like Titanic – I was not blogging, left the project. In general, I was finding excuses like having no time because of children etc. That was weak.

If you’re new to the topic – DSP2017 is a competition when in three months (March – May) you have to run OpenSource project and blog about it at least twice a week (ok, once a week you can blog about anything).

I started again because I still want to improve. And I know that if I would not start in this competition, I would not get myself together and not blog/code after hours. Frankly speaking I do not play to stand on the podium but rather kick off my after-hours activity.

Getting back to the topic, here’s my project.
I want to create an application for synchronising media files on my computer with external HDD. It comes with a real need. At home my disks are full of images/movies from camera and phones and I do not know which of these were already moved to external storage (usually they are not moved at all). Files are duplicated, unsorted, unnamed. The mess is growing in opposite to free disk space. I need a tool that could help me (or even clean it up for me). I know that there are different tools on the web, but I tried some of them and I was not satisfied (still if you like any of these tools, please leave a comment). I plan to implement the following features:

  • Building file index within selected location
  • Getting file metadata (like creation date of picture/video)
  • Moving files from local drive to external storage (or from one folder to another)
  • Organising files by dates / other criteria
  • Detecting and cleaning file duplicates
  • Rolling back changes (just in case)

About technologies and interesting stuff:

  • I want to use dotNetCore (newest possible)
  • I want to use new dotnet cli
  • As a console freak I do want it to work in terminal (Text mode). At the same time it must be useful and comfortable so it’s possible that I will implement some console widgets
  • I am a huge fun o vim and I will use it as my default editor. But I must admit that I want to try VSCode as well. I don’t want to use full Visual Studio but it’s not a rule.

Wish me luck!


git console: changing brach interactively

Some time ago I wrote about some helpful script that let me copy branch name without mouse. Later on I wrote about some simple console menu in Powershell. The second one seems to be a far better option here. Here’s the code:

#uncomment if you don't have ps-menu (powershellget is needed)
#install-module ps-menu -scope currentuser

$selection = menu (iex "git branch")
if ($selection -ne $null)
    $branch = $selection.Trim(" ", "*")
    iex "git checkout $branch"

Here is how it works:



Console aliases in Windows – the better approach

A big advantage of working in console mode is ability to create aliases. First you can easily shorten a command with a lot of switches. You can also automate your job by creating a script file and then set an alias for that script.

The default way of creating aliases in Windows is DOSKEY:

doskey np=notepad++.exe $*

The weak point of it is that you have to reassign them after restarting console window. There are ways for automating that using cmd.exe /k switch or using system
registry (see both article and comments).

There is also a buil-in option for ConEmu:

But all in all this is weak, as always you have to do two things: establish an
alias and then save it in some file for future use.

Alternative (better!) solution

I can sell you my way of dealing with aliases. I don’t use DOSKEY. Instead, I have a folder, i.e. C:\Tools\Aliases and there. I have a lot of *.cmd or *.ps1 files. The trick is that the folder is in my PATH variable.
Let’s say I have there a !notes.cmd command that runs:

vim c:\documents\notes01.txt

Then I can type ‘!notes’ and it runs “!notes.cmd” file that results in openning my temporary notes file. Obviously TAB autocompletion works fine. ‘!’ in the beginning lets me filter out my own aliases. I have also “!editaliases.cmd” for editing my aliases:

vim c:\tools\aliases\

Aliases are ready to use just after adding/editing them.
Other advantages:

  • no fancy escape characters (doskey defines its own list)
  • I can assing a whole script to an alias with one file
  • works in every console and emulator

Circular-style TAB behaviour in Cmder (like in cmd.exe)

For a long time I was addicted to ConEmu terminal-replacement. Nowadays I use
amazing cmder that is simply preconfigured Conemu + extensions. Nevertheless there is one very annoying thing that I didn’t like: TAB behavior. Instead of
simple circular-style autocompletion (like in cmd.exe) it stopped on the last
common character and then showed the list of matches (like in Linux).
It turned out that it is all because of clink – one of ConEmu’s extensions. As
it is very customizable, you can easily override it to behave just like in
the default Windows terminal. Authors predicted that and the configuration is already there, ready to uncomment.

In order to do that:
1. Find \vendor\clink folder in CMDER installation path
2. Open clink_inputrc_base file for editing
3. Uncomment lines 67 & 68 as following


Powershell, tools

Simple interactive console menu in Powershell

Personally I am a kind of console-freak. If possible, I would do everything in terminal. But in my case loving terminal is not about remembering all the different switches and options of console commands, but rather presenting things in a simple, readable manner, without fireworks. And most of all, navigation must be fast and comfortable. That’s why I prefer choosing options from simple menu than getting through command documentation and juggling with switches/parameters. That’s the course set out by yeoman for example.

I tried to find an easy way of building command-line menus but I couldn’t so I ended up with my own solution. It’s based on Powershell. I’m sharing it here in case you wanted to use it as well.

As we all know a picture is worth a thousand words:

You can still find the code on github:

The script is really short but the best way you can use it is to install it
with PowerShellGet from

install-module -name ps-menu

You can also copy-paste the code from ps-menu.psm1 file in case you wanted to have everything in one place.

tools, Web

Go to recent tab in Chrome

For a long time I have been searching for such feature in Chrome, but I could not find anything default. And it was difficult to understand, as it is so obvious for a developer. Windows has it (Alt + Tab), Resharper has it (Ctrl + ,), visual studio without plugins has it, same to Sublime Text, vim etc. But not Chrome, a default development tool for most of web developers. At the same time there are extensions, but most of them work far from what I expect. Below I would like to share what useful I have found. Both are fine, but for sure not flawless.

Ctrl + Tab MRU


This is the one I like the most. I have it bound to Ctrl + comma. That means that a combination Ctrl + comma, comma take me to the second recently used tab. It’s obvious, but actually this is the first extension I have found, that supports it.

The bad? Several times it had problems to render the list correctly. On the other hand I tried to reproduce it while writing this blog post and I couldn’t.

Quick Tabs


This one is more advanced, as it allows to search in usage history, recently closed and bookmarks. Unfortunately Ctrl + comma, comma, comma does not work as expected (but still it’s worth to have because of searching functionality).

What about you?

Do you have your own solution for that? I would really like to know if there is something better or at least if there is another useful alternative.