Jun 272017
 
 June 27, 2017  Posted by at 8:19 am C# & F#, PowerShell  Add comments

I was going to do a longer writeup on this, but I’ll just share the script with a very simple explanation for now and do the writing later. I’m not pleased with my explanation below, its written in a hurry- so please let me know what is unclear and I’ll make sure to amend the text.

When you install .NET Core you will have several pieces that need to fit together- some of them optional. In a dev environment, you will most likely want to have the SDK- which is the development toolkit that contains the CLI (command line tool) which you use to build and run core projects with, and other things (such as language compilers).

Notice that when I talk about .NET Core I’m referring to one of the three main .NET runtimes, the other two are .NET Framework and Mono (for Xamarin).

The .NET Core runtime consists of a set of libraries- the framework libraries (foundation libraries), another bunch of libraries that are the Core CLR, and then there is also the SDK I talk about earlier, and the app host (I’ll write a separate post on that).

What might be a little bit confusing is the different releases. The SDK won’t match the runtime version, and you can install different releases of the SDK, and the runtime.

When you download the SDK, .NET Core runtime of a specific version will usually be installed with it. If you need additional releases you can download them separately.

I say ‘usually will be installed with the SDK’ because this depends. Regardless of whether you download the SDK from the MS downloads site, or GitHub, there will be some info somewhere letting you know if- and which- runtimes come with it. For older downloads take a look at the release notes if it’s unclear. You should see something like this:

The .NET Core SDK 1.0.4 includes .NET Core 1.0.5 and 1.1.2 runtimes so downloading the runtime packages separately is not needed when installing the SDK.

The commandline tool used to work with core projects is added to the path when you install the SDK, and can be ran by using the ‘dotnet’ alias for the executable. When you run dotnet –version you will get the SDK version (!), running dotnet my itself will print the host version as well. To get the runtime versions that you have downloaded and installed you need to look somewhere else.

I’ve noticed that there is some confusion in regards to getting the version numbers, and as we recently updated all our services and environments we had to verify we had the right version of the SDK and runtime on our servers and dev machines.

Here is a function I added to one of our PowerShell Core modules for the above purpose:

Function Get-CoreInfo {
    if(Test-Path "$env:programfiles/dotnet/"){
        try{

            [Collections.Generic.List[string]] $info = dotnet

            $versionLineIndex = $info.FindIndex( {$args[0].ToString().ToLower() -like "*version*:*"} )

            $runtimes = (ls "$env:programfiles/dotnet/shared/Microsoft.NETCore.App").Name | Out-String

            $sdkVersion = dotnet --version

            $fhVersion = (($info[$versionLineIndex]).Split(':')[1]).Trim()

            return "SDK version: `r`n$sdkVersion`r`n`r`nInstalled runtime versions:`r`n$runtimes`r`nFramework Host:`r`n$fhVersion"
        }
        catch{
            $errorMessage = $_.Exception.Message

            Write-Host "Something went wrong`r`nError: $errorMessage"
        }
    }
    else{
    
        Write-Host 'No SDK installed'
        return ""
    }
}

2017-06-28_18-47-13

  2 Responses to “.NET Core: Finding out SDK-, installed runtime-, and Framework Host versions”

  1. For .NET Core Preview2 I think you need to need to modify a couple of lines, to include “–info” and change the search string to have a space after “*version”.

    [Collections.Generic.List[string]] $info = dotnet –info

    $versionLineIndex = $info.FindIndex( {$args[0].ToString().ToLower() -like “*version *:*”} )

  2. Thank you for making it more clear. Versions are bothering me. How do I run this command in my own poweshell? Do I need to install some module?

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

What is 14 + 9 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)