Skip to content

Commit

Permalink
(cake-archiveGH-75) Template PackAsTool & nuspec->csproj
Browse files Browse the repository at this point in the history
  • Loading branch information
devlead committed Jul 6, 2020
1 parent 3f3c3cf commit 42d4782
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 247 deletions.
4 changes: 0 additions & 4 deletions build/Lifetime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ public override void Setup(Context context)
context.IsPrimaryBranch = StringComparer.OrdinalIgnoreCase.Equals(context.PrimaryBranchName, buildSystem.AppVeyor.Environment.Repository.Branch);
context.BuildSystem = buildSystem;

// Install tools
context.Information("Installing tools...");
context.InstallNuGetExe("5.6.0");

// Install Global .Net Tools
context.Information("Installing .Net Global Tools...");
context.DotNetCoreToolInstall("GitReleaseManager.Tool", "0.11.0", "dotnet-gitreleasemanager");
Expand Down
19 changes: 10 additions & 9 deletions build/Tasks/PackageTemplate.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using Cake.Common.Tools.NuGet;
using Cake.Common.Tools.NuGet.Pack;
using Cake.Common.Tools.DotNetCore;
using Cake.Common.Tools.DotNetCore.Pack;
using Cake.Common.Xml;
using Cake.Core.IO;
using Cake.Frosting;

public class PackageTemplate : FrostingTask<Context>
Expand All @@ -11,17 +11,18 @@ public override void Run(Context context)
if (context.AppVeyor)
{
context.XmlPoke(
"./template/Build.csproj",
"./template/templates/cakefrosting/build/Build.csproj",
"/Project/ItemGroup/PackageReference[@Include = 'Cake.Frosting']/@Version",
context.Version.SemVersion
);
}

context.NuGetPack("./template/Cake.Frosting.Template.nuspec", new NuGetPackSettings
var path = new FilePath("./template/Cake.Frosting.Template.csproj");
context.DotNetCorePack(path.FullPath, new DotNetCorePackSettings
{
Version = context.Version.SemVersion,
OutputDirectory = context.Artifacts,
NoPackageAnalysis = true
Configuration = context.BuildConfiguration,
MSBuildSettings = context.MSBuildSettings,
OutputDirectory = context.Artifacts
});
}
}
}
79 changes: 0 additions & 79 deletions build/Utilities/ToolInstaller.cs
Original file line number Diff line number Diff line change
@@ -1,92 +1,13 @@
using System;
using System.IO;
using Cake.Common.Diagnostics;
using Cake.Common.IO;
using Cake.Common.Net;
using Cake.Common.Tools.DotNetCore;
using Cake.Common.Tools.DotNetCore.Tool;
using Cake.Common.Tools.NuGet;
using Cake.Common.Tools.NuGet.Install;
using Cake.Core;
using Cake.Core.IO;

public static class ToolInstaller
{
private static DirectoryPath ToolsPath { get; } = "./tools";

public static void InstallNuGetExe(this ICakeContext context, string version)
{

var toolsPath = context.MakeAbsolute(ToolsPath);

context.EnsureDirectoryExists(toolsPath);

var nugetExePath = toolsPath.CombineWithFilePath("nuget.exe");

if (context.FileExists(nugetExePath))
{
if (TryValidateVersion(version, nugetExePath, out var existingVersion))
{
context.Tools.RegisterFile(nugetExePath);
return;
}

context.Information(
"Found version {0} expected {1}, deleting {2}...",
existingVersion,
version,
toolsPath
);

context.DeleteFile(nugetExePath);
}

var address = $"https://dist.nuget.org/win-x86-commandline/v{Uri.EscapeDataString(version)}/nuget.exe";
context.Information("Downloading NuGet exe from {0} to {1}...", address, nugetExePath);
context.DownloadFile(
address,
nugetExePath
);

if (!context.FileExists(nugetExePath))
{
throw new Exception("Failed to install NuGet exe.");
}


if (!TryValidateVersion(version, nugetExePath, out var downloadedFileVersion))
{
throw new Exception($"Expected version {version} got {downloadedFileVersion}");
}

context.Tools.RegisterFile(nugetExePath);
context.Information("NuGet exe downloaded and registered successfully.");
}

private static bool TryValidateVersion(string expectedVersion, FilePath nugetExePath, out string foundVersion)
{
try
{
var fileVersion = System.Diagnostics.FileVersionInfo.GetVersionInfo(nugetExePath.FullPath);
foundVersion = FormattableString.Invariant($"{fileVersion.FileMajorPart}.{fileVersion.FileMinorPart}.{fileVersion.FileBuildPart}");
return foundVersion == expectedVersion;
}
catch(Exception ex)
{
foundVersion = ex.Message;
return false;
}
}

public static void Install(this ICakeContext context, string package, string version)
{
context.NuGetInstall(package, new NuGetInstallSettings {
Version = version,
ExcludeVersion = true,
OutputDirectory = ToolsPath
});
}

public static FilePath DotNetCoreToolInstall(
this ICakeContext context,
string package,
Expand Down
34 changes: 34 additions & 0 deletions template/Cake.Frosting.Template.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<PackageType>Template</PackageType>
<PackageId>Cake.Frosting.Template</PackageId>
<Title>Cake.Frosting templates for the .NET SDK.</Title>
<Description>Cake.Frosting templates for the .NET SDK.</Description>
<Authors>Patrik Svensson, Mattias Karlsson, Gary Ewan Park, Alistair Chapman, Martin Björkström and contributors</Authors>
<Copyright>Copyright (c) .NET Foundation and contributors</Copyright>
<PackageTags>Cake;Script;Build</PackageTags>
<PackageIcon>cake-medium.png</PackageIcon>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/cake-build/frosting</RepositoryUrl>
<TargetFramework>netcoreapp3.1</TargetFramework>

<IncludeContentInPack>true</IncludeContentInPack>
<IncludeBuildOutput>false</IncludeBuildOutput>
<ContentTargetFolders>content</ContentTargetFolders>
<NoWarn>NU5110;NU5111;NU5128</NoWarn>
</PropertyGroup>

<ItemGroup>
<Content Include="templates\**\*" Exclude="templates\**\bin\**;templates\**\obj\**" />
<Compile Remove="**\*" />
<Folder Include="images\" />
<None Include="../cake-medium.png" Link="images\cake-medium.png" Pack="true" PackagePath="/" />
<None Include="../LICENSE" Pack="true" PackagePath="/" />
<Content Include="../build.config" Link="templates/cakefrosting/build.config" PackagePath="/content/templates/cakefrosting/build.config" />
<Content Include="../build.ps1" Link="templates/cakefrosting/build.ps1" PackagePath="/content/templates/cakefrosting/build.ps1" />
<Content Include="../build.sh" Link="templates/cakefrosting/build.sh" PackagePath="/content/templates/cakefrosting/build.sh" />
</ItemGroup>

</Project>
31 changes: 0 additions & 31 deletions template/Cake.Frosting.Template.nuspec

This file was deleted.

120 changes: 0 additions & 120 deletions template/build.ps1

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>

<!-- Make sure start same folder .NET Core CLI and Visual Studio -->
<TargetFramework>netcoreapp3.1</TargetFramework>
<PackAsTool>true</PackAsTool>

<!-- Make sure start same folder .NET Core CLI and Visual Studio -->
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Cake.Frosting" Version="0.38.3" />
<PackageReference Include="Cake.Frosting" Version="0.38.2" />
</ItemGroup>

</Project>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 42d4782

Please sign in to comment.