import * as vscode from 'vscode' ; import { DialogResponses , IActionContext } from "vscode-azureextensionui" ; import { localize } from "../localize" ; import { cpUtils } from "./cpUtils" ; import { openUrl } from './openUrl' ; export namespace dotnetUtils { export async function isDotnetInstalled ( ) { try { await cpUtils . executeCommand ( undefined , undefined , 'dotnet' , '--version' ) ; return true ; } catch ( error ) { return false ; } } export async function validateDotnetInstalled ( actionContext ) { if ( ! await isDotnetInstalled ( ) ) { const message = localize ( 'dotnetNotInstalled' , 'You must have the .NET CLI installed to perform this operation.' ) ; if ( ! actionContext . errorHandling . suppressDisplay ) { vscode . window . showErrorMessage ( message , DialogResponses . learnMore ) . then ( async ( result ) => { if ( result === DialogResponses . learnMore ) { await openUrl ( 'https://aka.ms/AA4ac70' ) ; } } ) ; actionContext . errorHandling . suppressDisplay = true ; } throw new Error ( message ) ; } } export async function checkDotnetInstalled ( ) { if ( ! await isDotnetInstalled ( ) ) { const message = localize ( 'dotnetNotInstalled' , 'You must have a .NET Core SDK v2.1.x CLI installed to perform this operation.' ) ; vscode . window . showErrorMessage ( message , DialogResponses . learnMore ) . then ( async ( result ) => { if ( result === DialogResponses . learnMore ) { await openUrl ( 'https://aka.ms/AA4ac70' ) ; } } ) ; throw new Error ( message ) ; } } export async function checkDotnetVersionInstalled ( targetVersion ) { const response = await cpUtils . executeCommand ( undefined , undefined , 'dotnet' , '--list-sdks' ) ; const versions = response . split ( /\r?\n/ ) ; for ( const version of versions ) { if ( version . startsWith ( targetVersion ) ) { return true ; } } return false ; } }