dotnethelper

Go Reference GitHub

Package dotnethelper contains .NET-related helpers for Go.

It provides small, dependency-free helpers that shell out to the dotnet command-line tool to inspect the local .NET installation.

Installation

go get github.com/solsw/dotnethelper

Usage

package main

import (
	"fmt"

	"github.com/solsw/dotnethelper"
)

func main() {
	if !dotnethelper.Installed() {
		fmt.Println(".NET is not installed")
		return
	}

	version, err := dotnethelper.Version()
	if err != nil {
		fmt.Println("failed to get .NET version:", err)
		return
	}
	fmt.Println(".NET version:", version)
}

API

func Installed() bool

Reports whether .NET is installed, by checking that dotnet --version runs successfully.

func Version() (string, error)

Returns the version of the installed .NET (as reported by dotnet --version).

If dotnet --version fails, the returned error will usually be of type *exec.ExitError, whose Stderr field contains the command’s error output.

Requirements

The .NET SDK or runtime must be installed and the dotnet executable must be available on the system PATH.