Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuget download location #30

Merged
merged 1 commit into from
Mar 14, 2017
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
Binary file added Images/configureadvanced.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 35 additions & 5 deletions Task/Cake.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ Param(
[string]$Script,
[string]$Target,
[string]$Verbosity,
[string]$Arguments
[string]$Arguments,
[string]$useBuildAgentNuGetExe,
[string]$nugetExeDownloadLocation,
[string]$ToolFeedUrl
)

Write-Verbose "Parameters:";
Expand All @@ -11,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 @@ -37,11 +46,24 @@ if (!(Test-Path $ToolPath)) {
}
}

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

# Make sure NuGet exist.
if (!(Test-Path $NuGetPath)) {
# Download NuGet.exe.
Write-Verbose "Downloading nuget.exe...";
(New-Object System.Net.WebClient).DownloadFile("https://nuget.org/nuget.exe", $NuGetPath);
# Reset $NuGetPath incase we changed it above.
$NuGetPath = Join-Path $ToolPath "nuget.exe";

# If we haven't been given a custom nuget.exe download location then download the latest version from nuget.org.
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)) {
Throw "Could not find nuget.exe";
Expand All @@ -54,12 +76,20 @@ Set-Location $ToolPath;
if ((Test-Path $PackagePath)) {
# Install tools in packages.config.
Write-Host "Restoring packages...";
Invoke-Expression "$NuGetPath install `"$PackagePath`" -ExcludeVersion -OutputDirectory `"$ToolPath`"";
if($ToolFeedUrl -ne ""){
Invoke-Expression "$NuGetPath install `"$PackagePath`" -ExcludeVersion -OutputDirectory `"$ToolPath`" -Source $ToolFeedUrl";
}else{
Invoke-Expression "$NuGetPath install `"$PackagePath`" -ExcludeVersion -OutputDirectory `"$ToolPath`"";
}
}
if (!(Test-Path $CakePath)) {
# Install Cake if not part of packages.config.
Write-Host "Installing Cake...";
Invoke-Expression "$NuGetPath install Cake -ExcludeVersion -OutputDirectory `"$ToolPath`"";
if($ToolFeedUrl -ne ""){
Invoke-Expression "$NuGetPath install Cake -ExcludeVersion -OutputDirectory `"$ToolPath`" -Source $ToolFeedUrl";
}else{
Invoke-Expression "$NuGetPath install Cake -ExcludeVersion -OutputDirectory `"$ToolPath`"";
}
}
Pop-Location;

Expand Down
52 changes: 43 additions & 9 deletions Task/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,37 @@
},
"minimumAgentVersion": "1.83.0",
"instanceNameFormat": "Cake $(message)",
"groups": [
{
"name": "advanced",
"displayName": "Advanced",
"isExpanded": false
}
],
"inputs": [
{
"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 @@ -54,9 +61,36 @@
"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",
"required": false,
"helpMarkDown": "Use the nuget.exe installed with the build agent.",
"groupName": "advanced"
},
{
"name": "nugetExeDownloadLocation",
"type": "string",
"label": "Nuget Exe Location",
"defaultValue": "",
"required": false,
"helpMarkDown": "Where to fetch the nuget executable from if not using the build agent nuget. Defaults to `https://dist.nuget.org/win-x86-commandline/latest/nuget.exe`",
"groupName": "advanced"
},
{
"name": "ToolFeedUrl",
"type": "string",
"label": "Tool Feed Url",
"defaultValue": "",
"required": false,
"helpMarkDown": "Use an alternate nuget package feed for cake and tools. Defaults to `nuget.org`",
"groupName": "advanced"
}
],
"execution": {
Expand All @@ -66,4 +100,4 @@
"workingDirectory": "$(currentDirectory)"
}
}
}
}
4 changes: 2 additions & 2 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

#addin "nuget:?package=MagicChunks&version=1.1.0.34"
#addin "nuget:?package=Cake.Tfx&version=0.4.2"
#addin "nuget:?package=Cake.Npm&version=0.7.1"
#addin "nuget:?package=Cake.Npm&version=0.7.2"

//////////////////////////////////////////////////////////////////////
// TOOLS
//////////////////////////////////////////////////////////////////////

#tool "nuget:?package=gitreleasemanager&version=0.6.0"
#tool "nuget:?package=GitVersion.CommandLine&version=3.4.1"
#tool "nuget:?package=GitVersion.CommandLine&version=3.6.4"

// Load other scripts.
#load "./build/parameters.cake"
Expand Down
15 changes: 15 additions & 0 deletions extension-details.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ By default, the Cake build step (when added to a build) will try to run the `bui

At the moment, only Windows build agents are supported, but we expect to add support for other build agents soon.

Advanced Settings
----------
There are several advanced settings that control where the Cake build step downloads tools from.

![Configure Advanced Settings](Images/configureadvanced.png)

### Use the Build Agent Nuget
This will use the version of `nuget.exe` shipped with the build agent `<AgentInstallFolder>\agent\Worker\Tools\Nuget.exe` if set. This is set to False by default.

### Nuget Exe Location
If not using the Build Agent copy of `nuget.exe` this setting specifies where to download the executable from. This can be a URL e.g. `https://nuget.org/nuget.exe` or a simple folder path such as `D:\Tools\Nuget.exe`. If nothing is set the task will download `nuget.exe` from `https://dist.nuget.org/win-x86-commandline/latest/nuget.exe`

### Tool Feed URL
The `cake.exe`, `#addin` and `#tool` packages are by default downloaded from the default nuget.org package feed. You can download these tools from an alternate feed by specifiying it here.

Learn more
----------

Expand Down