Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion resources/Microsoft.DotNet.Dsc/Microsoft.DotNet.Dsc.psd1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@{
RootModule = 'Microsoft.DotNet.Dsc.psm1'
ModuleVersion = '0.1.0'
ModuleVersion = '0.2.0'
GUID = '2e883e78-1d91-4d08-9fc1-2a968e31009d'
Author = 'Microsoft Corporation'
CompanyName = 'Microsoft Corporation'
Expand Down
37 changes: 22 additions & 15 deletions resources/Microsoft.DotNet.Dsc/Microsoft.DotNet.Dsc.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,26 @@ function Get-DotNetToolArguments {

# mapping table of command line arguments
$mappingTable = @{
Version = '--version {0}'
Version = '--version'
PreRelease = '--prerelease'
ToolPathDirectory = '--tool-path {0}'
ToolPathDirectory = '--tool-path'
Downgrade = '--allow-downgrade'
}

$valueArguments = @('Version', 'ToolPathDirectory')

$PSBoundParameters.GetEnumerator() | ForEach-Object {
if ($mappingTable.ContainsKey($_.Key)) {
if ($_.Value -ne $false -and -not (([string]::IsNullOrEmpty($_.Value)))) {
$arguments += ($mappingTable[$_.Key] -f $_.Value)
$arguments += $mappingTable[$_.Key]
if ($valueArguments -contains $_.Key) {
$arguments += [string]$_.Value
}
}
}
}

return ($arguments -join ' ')
return , [string[]]$arguments
}

# TODO: when https://github.com/dotnet/sdk/pull/37394 is documented and version is released with option simple use --format=JSON
Expand Down Expand Up @@ -141,11 +146,11 @@ function Get-InstalledDotNetToolPackages {
)

$resultSet = [System.Collections.Generic.List[DotNetToolPackage]]::new()
$listCommand = 'tool list --global'
$listCommand = @('tool', 'list', '--global')
$installDir = Join-Path -Path $env:USERPROFILE '.dotnet' 'tools'

if ($PSBoundParameters.ContainsKey('ToolPathDirectory')) {
$listCommand = "tool list --tool-path $ToolPathDirectory"
$listCommand = @('tool', 'list', '--tool-path', $ToolPathDirectory)
$installDir = $ToolPathDirectory
}

Expand Down Expand Up @@ -226,8 +231,8 @@ function Install-DotNetToolPackage {
)

$installArgument = Get-DotNetToolArguments @PSBoundParameters
$arguments = "tool install $installArgument --ignore-failed-sources"
Write-Verbose -Message "Installing dotnet tool package with arguments: $arguments"
$arguments = @('tool', 'install') + $installArgument + @('--ignore-failed-sources')
Write-Verbose -Message "Installing dotnet tool package with arguments: $($arguments -join ' ')"

Invoke-DotNet -Command $arguments
}
Expand All @@ -244,8 +249,8 @@ function Update-DotNetToolPackage {
)

$installArgument = Get-DotNetToolArguments @PSBoundParameters
$arguments = "tool update $installArgument --ignore-failed-sources"
Write-Verbose -Message "update dotnet tool package with arguments: $arguments"
$arguments = @('tool', 'update') + $installArgument + @('--ignore-failed-sources')
Write-Verbose -Message "update dotnet tool package with arguments: $($arguments -join ' ')"

Invoke-DotNet -Command $arguments
}
Expand All @@ -269,22 +274,24 @@ function Uninstall-DotNetToolPackage {
)

$installArgument = Get-DotNetToolArguments @PSBoundParameters
$arguments = "tool uninstall $installArgument"
Write-Verbose -Message "Uninstalling dotnet tool package with arguments: $arguments"
$arguments = @('tool', 'uninstall') + $installArgument
Write-Verbose -Message "Uninstalling dotnet tool package with arguments: $($arguments -join ' ')"

Invoke-DotNet -Command $arguments
}

function Invoke-DotNet {
param (
[Parameter(Mandatory = $true)]
[string] $Command
[string[]] $Command
)

$argList = @($Command | Where-Object { -not [string]::IsNullOrEmpty($_) })

try {
Invoke-Expression "& `"$DotNetCliPath`" $Command"
& $DotNetCliPath @argList
} catch {
throw "Executing dotnet.exe with {$Command} failed."
throw "Executing dotnet.exe with {$($argList -join ' ')} failed."
}
}

Expand Down
Loading