Setting up my development machine

Here's the configuration of my developer machine. I'm a .NET and web developper, so only the software relevant to these technologies are part of the list. I also add a few tools I use everyday, but are not directly related to dev. I'm sure I forgot some of the tools I used regularly. If you think I should add something (software/extension/configuration/services), feel free to comment.

Web browsers

Development

Others

Windows Configuration

Online services

How to publish a dotnet global tool with .NET Core 2.1

People doing web development are used to install tools using npm. For instance, you can install TypeScript using npm install -g TypeScript. Then you can use TypeScript directly from the command line. This is very convenient. .NET Core 2.1 allows to create tools that can be install the same way as nodejs. This feature provides a simple way to create and share cross-platform console tools.

.NET tools are packaged as NuGet packages, so you rely on processes that are well settle

Create the project

First, you need to download .NET Core 2.1 SDK. Then you need to create a console application that target .NET Core 2.1. You can use the command line or Visual Studio. Let's use the command line (it's very easy):

dotnet new console

This creates a basic console project that prints "Hello world" to the console.

Now, let's modify the project file to add the tool configuration. You need to add <PackAsTool> and ToolCommandName. The first one indicates that the NuGet package to create is not a library but a tool. The second one indicates the name of the command to run your tool from the command line.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.1</TargetFramework>

    <PackAsTool>true</PackAsTool>
    <ToolCommandName>MyDotNetCoreTool</ToolCommandName>
  </PropertyGroup>

</Project>

That all you need to create a .NET Core global tool, now we can publish it!

Publish the tool on NuGet

A tool is just a package NuGet, so to publish the tool and make it available to everyone, you just need to publish the NuGet package as any other NuGet package.

First, you need to get an API key on nuget.org: https://www.nuget.org/account/apikeys.

Create NuGet API Key

Copy NuGet API Key

Then, you can create the package and publish it to NuGet:

dotnet pack --configuration Release
dotnet nuget push .\bin\release\MyDotNetCoreTool.1.0.0.nupkg --source https://api.nuget.org/v3/index.json --api-key <Your NuGet API key>

It will take a few minutes for the package to be indexed and become available.

Package on NuGet.org

Install the tool

The command line to install the tool is visible on NuGet, so the following command is not a surprise 😉

dotnet tool install --global MyDotNetCoreTool

Install Tool

Then, you can use the tool using the name set in <ToolCommandName>:

MyDotNetCoreTool

Tool demo

List the .NET Core global tools installed on the machine

If you don't remember the tools you installed, you can run the following command to get the full list:

dotnet tool list -g

Update the tool

If you want to update the tool, you must publish a newer version of the NuGet package. You can set the version of the generated NuGet package in the csproj file using the <Version> element:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.1</TargetFramework>

    <PackAsTool>true</PackAsTool>
    <ToolCommandName>MyDotNetCoreTool</ToolCommandName>
    <Version>2.0.0</Version>
  </PropertyGroup>

</Project>

Then, you can use the same commands as to publish the first NuGet package:

dotnet pack --configuration Release
dotnet nuget push .\bin\release\MyDotNetCoreTool.2.0.0.nupkg --source https://api.nuget.org/v3/index.json --api-key <Your NuGet API key>

There is no auto-update functionality, so the users of you tool must update it manually when needed.

dotnet tool update --global MyDotNetCoreTool

Uninstall the tool

You can uninstall a tool using the following command:

dotnet tool uninstall --global MyDotNetCoreTool

The tool won't be available from the command line anymore. You can check the tool is well uninstall by running dotnet tool list -g

Test a tool without publishing it on NuGet

When you create a tool, you may want to test it on your computer without publishing it on NuGet.org or any NuGet server. The command line allows to specify the feed source. This source can be a local repository. So, you can use the following command lines:

dotnet pack --output ./
dotnet tool install -g MyDotNetCoreTool --add-source ./

If you want to try a new version, you first need to uninstall the tool or update it

dotnet tool uninstall -g MyDotNetCoreTool
dotnet tool install -g MyDotNetCoreTool --add-source ./

or

dotnet tool update -g MyDotNetCoreTool --add-source ./

Conclusion

.NET Core global tools provides a simple way to create and share cross-platform console tools. There are so easy to create. I think many tools will be created in the next months. Here's some tools:

Tip: Automatically create a crash dump file on error

Crash dumps are very useful to debug an application. Recently, I worked on a Visual Studio extension we use in my company. It's very easy to develop such kind of application. However, there are lots of reasons for your extension to crash. Of course you can add lots of try/catch, but you'll for sure forget the good one, so VS will crash. When it's happening, you would like to be able to attach a debugger and see the exception and the stack trace. Instead of attaching a debugger, you can automatically generate a crash dump that you can use to debug the application later.

In Windows, you can configure Windows Error Reporting (WER) to generate a dump when an application crashes.

  1. Open regedit.exe
  2. Open the key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps
  3. Set the value DumpFolder (REG_EXPAND_SZ) to the directory you want the dump to be created
  4. Optionally, you can prevent WER to keep lots of crash dumps by setting DumpCount (DWORD) to a low number

Maybe you prefer set the configuration using PowerShell:

New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting" -Name "LocalDumps"
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" -Name "DumpFolder" -Value "%LOCALAPPDATA%\CrashDumps" -PropertyType "ExpandString"
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" -Name "DumpCount" -Value 10 -PropertyType DWord

You can also configure WER per application. So, if you want to generate a full dump only for one application, you can create a key for your application under LocalDumps with the configuration you want. If you application is devenv.exe the key name is devenv.exe. This is very simple!

WER configuration

When you application crash, you can go to %LOCALAPPDATA%\CrashDumps:

WER configuration

Find the latest dump and open it using Visual Studio to start debugging the application. By default, it shows system information, the exception that crahes the application, and the list of modules. You can use the action section on the right to start the debugger and find more information about the exception.

Debug crash dump in Visual Studio

Documentation: https://msdn.microsoft.com/en-us/library/windows/desktop/bb787181.aspx