Skip to content

Commit

Permalink
GitHubSync update
Browse files Browse the repository at this point in the history
  • Loading branch information
GeertvanHorrik committed Jan 13, 2021
1 parent dd3a425 commit ce8c01c
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 16 deletions.
26 changes: 22 additions & 4 deletions deployment/cake/generic-tasks.cake
Expand Up @@ -125,13 +125,31 @@ Task("RestorePackages")
return;
}
var csharpProjects = GetFiles("./**/*.csproj");
//var csharpProjects = GetFiles("./**/*.csproj");
// var cProjects = GetFiles("./**/*.vcxproj");
var solutions = GetFiles("./**/*.sln");
var csharpProjects = new List<FilePath>();
foreach (var project in buildContext.AllProjects)
{
if (ShouldProcessProject(buildContext, project))
{
var projectFileName = GetProjectFileName(buildContext, project);
if (projectFileName.EndsWith(".csproj"))
{
Information("Adding '{0}' as C# specific project to restore", project);
csharpProjects.Add(projectFileName);
// Inject source link *before* package restore
InjectSourceLinkInProjectFile(buildContext, projectFileName);
}
}
}
var allFiles = new List<FilePath>();
allFiles.AddRange(solutions);
//allFiles.AddRange(csharpProjects);
//allFiles.AddRange(solutions);
allFiles.AddRange(csharpProjects);
// //allFiles.AddRange(cProjects);
foreach (var file in allFiles)
Expand Down
51 changes: 51 additions & 0 deletions deployment/cake/lib-logging.cake
@@ -0,0 +1,51 @@
// Note: code originally comes from https://stackoverflow.com/questions/50826394/how-to-print-tool-command-line-in-cake

/// <summary>
/// Temporary sets logging verbosity.
/// </summary>
/// <example>
/// <code>
/// // Temporary sets logging verbosity to Diagnostic.
/// using(context.UseVerbosity(Verbosity.Diagnostic))
/// {
/// context.DotNetCoreBuild(project, settings);
/// }
/// </code>
/// </example>
public static VerbosityChanger UseVerbosity(this ICakeContext context, Verbosity newVerbosity) =>
new VerbosityChanger(context.Log, newVerbosity);


/// <summary>
/// Temporary sets logging verbosity to Diagnostic.
/// </summary>
/// <example>
/// <code>
/// // Temporary sets logging verbosity to Diagnostic.
/// using(context.UseDiagnosticVerbosity())
/// {
/// context.DotNetCoreBuild(project, settings);
/// }
/// </code>
/// </example>
public static VerbosityChanger UseDiagnosticVerbosity(this ICakeContext context) =>
context.UseVerbosity(Verbosity.Diagnostic);

/// <summary>
/// Cake log verbosity changer.
/// Restores old verbosity on Dispose.
/// </summary>
public class VerbosityChanger : IDisposable
{
ICakeLog _log;
Verbosity _oldVerbosity;

public VerbosityChanger(ICakeLog log, Verbosity newVerbosity)
{
_log = log;
_oldVerbosity = log.Verbosity;
_log.Verbosity = newVerbosity;
}

public void Dispose() => _log.Verbosity = _oldVerbosity;
}
52 changes: 44 additions & 8 deletions deployment/cake/lib-nuget.cake
Expand Up @@ -50,12 +50,11 @@ public static List<NuGetServer> GetNuGetServers(string urls, string apiKeys)

private static void RestoreNuGetPackages(BuildContext buildContext, Cake.Core.IO.FilePath solutionOrProjectFileName)
{
buildContext.CakeContext.Information("Restoring packages for {0}", solutionOrProjectFileName);
buildContext.CakeContext.LogSeparator("Restoring packages for '{0}'", solutionOrProjectFileName);

var sources = SplitSeparatedList(buildContext.General.NuGet.PackageSources, ';');
var runtimeIdentifiers = new List<string>(new []
{
"",
"win-x64",
"browser-wasm"
});
Expand All @@ -68,7 +67,7 @@ private static void RestoreNuGetPackages(BuildContext buildContext, Cake.Core.IO

private static void RestoreNuGetPackagesUsingNuGet(BuildContext buildContext, Cake.Core.IO.FilePath solutionOrProjectFileName, List<string> sources)
{
buildContext.CakeContext.Information("Restoring packages for {0} using 'NuGet'", solutionOrProjectFileName);
buildContext.CakeContext.LogSeparator("Restoring packages for '{0}' using 'NuGet'", solutionOrProjectFileName);

try
{
Expand All @@ -95,29 +94,66 @@ private static void RestoreNuGetPackagesUsingNuGet(BuildContext buildContext, Ca

private static void RestoreNuGetPackagesUsingDotnetRestore(BuildContext buildContext, Cake.Core.IO.FilePath solutionOrProjectFileName, List<string> sources, List<string> runtimeIdentifiers)
{
buildContext.CakeContext.Information("Restoring packages for {0} using 'dotnet restore'", solutionOrProjectFileName);
buildContext.CakeContext.LogSeparator("Restoring packages for '{0}' using 'dotnet restore'", solutionOrProjectFileName);

var projectFileContents = System.IO.File.ReadAllText(solutionOrProjectFileName.FullPath)?.ToLower();

var supportedRuntimeIdentifiers = new List<string>();

foreach (var runtimeIdentifier in runtimeIdentifiers)
{
if (!string.IsNullOrWhiteSpace(runtimeIdentifier))
{
if (!projectFileContents.Contains(runtimeIdentifier.ToLower()))
{
buildContext.CakeContext.Information("Project '{0}' does not support runtime identifier '{1}', skipping restore for this runtime identifier", solutionOrProjectFileName, runtimeIdentifier);
continue;
}
}

supportedRuntimeIdentifiers.Add(runtimeIdentifier);
}

if (supportedRuntimeIdentifiers.Count == 0)
{
// Default
supportedRuntimeIdentifiers.Add(string.Empty);
}

foreach (var runtimeIdentifier in supportedRuntimeIdentifiers)
{
try
{
buildContext.CakeContext.LogSeparator("Restoring packages for '{0}' using 'dotnet restore' using runtime identifier '{1}'", solutionOrProjectFileName, runtimeIdentifier);

var restoreSettings = new DotNetCoreRestoreSettings
{
DisableParallel = false,
Force = false,
ForceEvaluate = false,
IgnoreFailedSources = true,
NoCache = false,
NoDependencies = false, // use true to speed up things
Verbosity = DotNetCoreVerbosity.Normal
};

if (!string.IsNullOrWhiteSpace(runtimeIdentifier))
{
// This is a explicit supported runtime identifier, force re-evaluation
restoreSettings.Force = true;
restoreSettings.ForceEvaluate = true;
restoreSettings.Runtime = runtimeIdentifier;
}

if (sources.Count > 0)
{
restoreSettings.Sources = sources;
}

if (!string.IsNullOrWhiteSpace(runtimeIdentifier))
using (buildContext.CakeContext.UseDiagnosticVerbosity())
{
restoreSettings.Runtime = runtimeIdentifier;
buildContext.CakeContext.DotNetCoreRestore(solutionOrProjectFileName.FullPath, restoreSettings);
}

buildContext.CakeContext.DotNetCoreRestore(solutionOrProjectFileName.FullPath, restoreSettings);
}
catch (Exception)
{
Expand Down
18 changes: 15 additions & 3 deletions deployment/cake/lib-sourcelink.cake
@@ -1,5 +1,20 @@
public static bool IsSourceLinkSupported(BuildContext buildContext, string projectFileName)
{
if (buildContext.General.SourceLink.IsDisabled)
{
return false;
}

if (buildContext.General.IsLocalBuild)
{
return false;
}

if (string.IsNullOrWhiteSpace(buildContext.General.Repository.Url))
{
return false;
}

// Only support C# projects
if (!projectFileName.EndsWith(".csproj"))
{
Expand Down Expand Up @@ -69,7 +84,4 @@ public static void InjectSourceLinkInProjectFile(BuildContext buildContext, stri
projectElement.Add(sourceRootItemGroup);

xmlDocument.Save(projectFileName);

// Restore packages again for the dynamic package
RestoreNuGetPackages(buildContext, projectFileName);
}
1 change: 1 addition & 0 deletions deployment/cake/tasks.cake
@@ -1,4 +1,5 @@
#l "lib-generic.cake"
#l "lib-logging.cake"
#l "lib-msbuild.cake"
#l "lib-nuget.cake"
#l "lib-signing.cake"
Expand Down
7 changes: 6 additions & 1 deletion src/global.json
@@ -1,5 +1,10 @@
{
"msbuild-sdks": {
"MSBuild.Sdk.Extras": "2.1.2"
"MSBuild.Sdk.Extras": "3.0.23"
},
"sdk": {
"version": "5.0.0",
"rollForward": "latestMinor",
"allowPrerelease": false
}
}

0 comments on commit ce8c01c

Please sign in to comment.