Skip to content

Commit

Permalink
Fixes for using Build Agent nuget.exe
Browse files Browse the repository at this point in the history
  • Loading branch information
frozenskys committed Nov 2, 2016
1 parent a4f9bba commit 5832e4e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
22 changes: 15 additions & 7 deletions Task/Cake.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Param(
[string]$Target,
[string]$Verbosity,
[string]$Arguments,
[bool]$useBuildAgentNuGetExe,
[string]$useBuildAgentNuGetExe,
[string]$nugetExeDownloadLocation,
[string]$ToolFeedUrl
)
Expand All @@ -14,6 +14,12 @@ foreach($key in $PSBoundParameters.Keys)
Write-Verbose ($key + ' = ' + $PSBoundParameters[$key]);
}

try {
$useBuildAgentNuGetExeBool = [System.Convert]::ToBoolean($useBuildAgentNuGetExe)
} catch [FormatException] {
$useBuildAgentNuGetExeBool = $false
}

Import-Module "Microsoft.TeamFoundation.DistributedTask.Task.Internal";
Import-Module "Microsoft.TeamFoundation.DistributedTask.Task.Common";

Expand All @@ -40,21 +46,23 @@ if (!(Test-Path $ToolPath)) {
}
}

if($useBuildAgentNuGetExe)
if($useBuildAgentNuGetExeBool)
{
$NuGetPath = Get-ToolPath -Name 'NuGet.exe';
Write-Host "Using Build Agent nuget.exe";
$nugetExeDownloadLocation = Get-ToolPath -Name 'NuGet.exe';
}

# Make sure NuGet exist.
if (!(Test-Path $NuGetPath)) {
# Download NuGet.exe.
# Reset $NuGetPath incase we changed it above.
$NuGetPath = Join-Path $ToolPath "nuget.exe";
Write-Verbose "Downloading nuget.exe...";

# If we haven't been given a custom nuget.exe download location then download the latest version from nuget.org.
if($nugetExeDownloadLocation -ne "") {
if($nugetExeDownloadLocation -eq "") {
$nugetExeDownloadLocation = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
}
Write-Verbose "Getting nuget.exe from $nugetExeDownloadLocation"
(New-Object System.Net.WebClient).DownloadFile($nugetExeDownloadLocation, $NuGetPath);
# Make sure it was properly downloaded.
if (!(Test-Path $NuGetPath)) {
Expand All @@ -68,7 +76,7 @@ Set-Location $ToolPath;
if ((Test-Path $PackagePath)) {
# Install tools in packages.config.
Write-Host "Restoring packages...";
if($nugetFeedLocation -ne ""){
if($ToolFeedUrl -ne ""){
Invoke-Expression "$NuGetPath install `"$PackagePath`" -ExcludeVersion -OutputDirectory `"$ToolPath`" -Source $ToolFeedUrl";
}else{
Invoke-Expression "$NuGetPath install `"$PackagePath`" -ExcludeVersion -OutputDirectory `"$ToolPath`"";
Expand All @@ -77,7 +85,7 @@ if ((Test-Path $PackagePath)) {
if (!(Test-Path $CakePath)) {
# Install Cake if not part of packages.config.
Write-Host "Installing Cake...";
if($nugetFeedLocation -ne ""){
if($ToolFeedUrl -ne ""){
Invoke-Expression "$NuGetPath install Cake -ExcludeVersion -OutputDirectory `"$ToolPath`" -Source $ToolFeedUrl";
}else{
Invoke-Expression "$NuGetPath install Cake -ExcludeVersion -OutputDirectory `"$ToolPath`"";
Expand Down
20 changes: 10 additions & 10 deletions Task/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,25 @@
"name": "script",
"type": "filePath",
"label": "Cake Script",
"defaultValue":"build.cake",
"defaultValue": "build.cake",
"helpMarkDown": "The build script to execute.",
"required":true
"required": true
},
{
"name": "target",
"type": "string",
"label": "Target",
"defaultValue":"Default",
"defaultValue": "Default",
"helpMarkDown": "The build script target to run.",
"required":true
"required": true
},
{
"name": "verbosity",
"type": "pickList",
"label": "Verbosity",
"defaultValue":"Verbose",
"defaultValue": "Verbose",
"helpMarkDown": "Specifies the amount of information to be displayed.",
"required":true,
"required": true,
"options": {
"Quiet": "Quiet",
"Minimal": "Minimal",
Expand All @@ -61,15 +61,15 @@
"name": "arguments",
"type": "string",
"label": "Cake Arguments",
"defaultValue":"",
"defaultValue": "",
"helpMarkDown": "Additional arguments passed to Cake.",
"required":false
"required": false
},
{
"name": "useBuildAgentNuGetExe",
"type": "boolean",
"label": "Use the Build Agent Nuget",
"defaultValue": false,
"defaultValue": "false",
"required": false,
"helpMarkDown": "Use the nuget.exe installed with the build agent.",
"groupName": "advanced"
Expand Down Expand Up @@ -100,4 +100,4 @@
"workingDirectory": "$(currentDirectory)"
}
}
}
}

0 comments on commit 5832e4e

Please sign in to comment.