From 1aa2d76ca89c1b29d8d1923f9e48e87d8f5775b9 Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Tue, 13 Dec 2022 21:11:26 +0100 Subject: [PATCH] feat: upgrade to .NET6.0/7.0 and latest lib versions --- .config/dotnet-tools.json | 2 +- .gitignore | 7 ++ .nuke | 1 - .nuke/build.schema.json | 116 ++++++++++++++++++ .nuke/parameters.json | 4 + build/Build.cs | 25 ++-- build/Configuration.cs | 14 +++ build/Directory.Build.props | 8 ++ build/Directory.Build.targets | 8 ++ build/_build.csproj | 10 +- build/benchmarks/BenchmarkToolSettings.cs | 47 ------- build/benchmarks/DotnetBenchmarkExtensions.cs | 21 ---- global.json | 5 + src/Tand.Core/Api/ITandTarget.cs | 18 +-- src/Tand.Core/Api/TandAttribute.cs | 30 +++-- src/Tand.Core/Models/CallEnterContext.cs | 29 +++-- src/Tand.Core/Models/CallLeaveContext.cs | 43 ++++--- src/Tand.Core/Models/MethodArgument.cs | 22 +--- src/Tand.Core/Tand.Core.csproj | 6 +- ...Tand.Extensions.DependencyInjection.csproj | 14 ++- .../Tand.Core.Benchmarks/RationalsProvider.cs | 2 +- .../Tand.Core.Benchmarks.csproj | 6 +- test/Tand.Core.Tests/Tand.Core.Tests.csproj | 18 ++- test/Tand.Core.Tests/TandSample.cs | 2 +- test/Tand.Core.Tests/TandTests.cs | 29 +++-- ...xtensions.DependencyInjection.Tests.csproj | 18 ++- .../TandServiceExtensionsTests.cs | 2 +- test/build.cmd | 5 +- test/build.ps1 | 47 +++---- test/build.sh | 38 +++--- 30 files changed, 350 insertions(+), 247 deletions(-) delete mode 100644 .nuke create mode 100644 .nuke/build.schema.json create mode 100644 .nuke/parameters.json create mode 100644 build/Configuration.cs create mode 100644 build/Directory.Build.props create mode 100644 build/Directory.Build.targets delete mode 100644 build/benchmarks/BenchmarkToolSettings.cs delete mode 100644 build/benchmarks/DotnetBenchmarkExtensions.cs create mode 100644 global.json diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 751279b..5736119 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -9,7 +9,7 @@ ] }, "nuke.globaltool": { - "version": "5.3.0", + "version": "6.2.1", "commands": [ "nuke" ] diff --git a/.gitignore b/.gitignore index 9cc6249..a826e9b 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,10 @@ _site .idea/ *.Artifacts/ **/artifacts/ +.nuke/temp/ + +############## +# files # +############## + +*.DotSettings.user \ No newline at end of file diff --git a/.nuke b/.nuke deleted file mode 100644 index 8c26cb1..0000000 --- a/.nuke +++ /dev/null @@ -1 +0,0 @@ -Tand.sln \ No newline at end of file diff --git a/.nuke/build.schema.json b/.nuke/build.schema.json new file mode 100644 index 0000000..1fe7c7a --- /dev/null +++ b/.nuke/build.schema.json @@ -0,0 +1,116 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "Build Schema", + "$ref": "#/definitions/build", + "definitions": { + "build": { + "type": "object", + "properties": { + "Configuration": { + "type": "string", + "description": "Configuration to build - Default is 'Debug' (local) or 'Release' (server)", + "enum": [ + "Debug", + "Release" + ] + }, + "Continue": { + "type": "boolean", + "description": "Indicates to continue a previously failed build attempt" + }, + "Help": { + "type": "boolean", + "description": "Shows the help text for this build assembly" + }, + "Host": { + "type": "string", + "description": "Host for execution. Default is 'automatic'", + "enum": [ + "AppVeyor", + "AzurePipelines", + "Bamboo", + "Bitbucket", + "Bitrise", + "GitHubActions", + "GitLab", + "Jenkins", + "Rider", + "SpaceAutomation", + "TeamCity", + "Terminal", + "TravisCI", + "VisualStudio", + "VSCode" + ] + }, + "NoLogo": { + "type": "boolean", + "description": "Disables displaying the NUKE logo" + }, + "Partition": { + "type": "string", + "description": "Partition to use on CI" + }, + "Plan": { + "type": "boolean", + "description": "Shows the execution plan (HTML)" + }, + "Profile": { + "type": "array", + "description": "Defines the profiles to load", + "items": { + "type": "string" + } + }, + "Root": { + "type": "string", + "description": "Root directory during build execution" + }, + "Skip": { + "type": "array", + "description": "List of targets to be skipped. Empty list skips all dependencies", + "items": { + "type": "string", + "enum": [ + "Benchmark", + "Clean", + "Compile", + "Pack", + "Restore", + "Test" + ] + } + }, + "Solution": { + "type": "string", + "description": "Path to a solution file that is automatically loaded" + }, + "Target": { + "type": "array", + "description": "List of targets to be invoked. Default is '{default_target}'", + "items": { + "type": "string", + "enum": [ + "Benchmark", + "Clean", + "Compile", + "Pack", + "Restore", + "Test" + ] + } + }, + "Verbosity": { + "type": "string", + "description": "Logging verbosity during build execution. Default is 'Normal'", + "enum": [ + "Minimal", + "Normal", + "Quiet", + "Verbose" + ] + } + } + } + } +} \ No newline at end of file diff --git a/.nuke/parameters.json b/.nuke/parameters.json new file mode 100644 index 0000000..b277e9c --- /dev/null +++ b/.nuke/parameters.json @@ -0,0 +1,4 @@ +{ + "$schema": "./build.schema.json", + "Solution": "Tand.sln" +} \ No newline at end of file diff --git a/build/Build.cs b/build/Build.cs index 495a011..ca0b3ff 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -4,13 +4,13 @@ using Nuke.Common.Execution; using Nuke.Common.Git; using Nuke.Common.IO; using Nuke.Common.ProjectModel; -using Nuke.Common.Tooling; using Nuke.Common.Tools.DotNet; using Nuke.Common.Tools.GitVersion; +using Nuke.Common.Tools.BenchmarkDotNet; using Nuke.Common.Utilities.Collections; using static Nuke.Common.IO.FileSystemTasks; +using static Nuke.Common.Tools.BenchmarkDotNet.BenchmarkDotNetTasks; using static Nuke.Common.Tools.DotNet.DotNetTasks; -using static _build.benchmarks.DotNetBenchmarkExtensions; [GitHubActions( "dotnet", @@ -19,7 +19,6 @@ using static _build.benchmarks.DotNetBenchmarkExtensions; On = new []{GitHubActionsTrigger.Push, GitHubActionsTrigger.PullRequest} ) ] -[CheckBuildProjectConfigurations] [UnsetVisualStudioEnvironmentVariables] class Build : NukeBuild { @@ -34,8 +33,10 @@ class Build : NukeBuild readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release; [Solution] readonly Solution Solution; - [GitRepository] readonly GitRepository GitRepository; - [GitVersion] readonly GitVersion GitVersion; + [GitRepository] + readonly GitRepository GitRepository; + [GitVersion(Framework = "net6.0", NoFetch = true)] + readonly GitVersion GitVersion; AbsolutePath SourceDirectory => RootDirectory / "src"; AbsolutePath TestsDirectory => RootDirectory / "test"; @@ -73,8 +74,7 @@ class Build : NukeBuild .SetProjectFile(Solution) .SetConfiguration(Configuration) .EnableNoRestore() - .EnableNoBuild() - .EnableLogOutput())); + .EnableNoBuild())); Target Pack => _ => _ .DependsOn(Test) @@ -90,17 +90,16 @@ class Build : NukeBuild .EnableIncludeSymbols() .EnableNoRestore() .EnableNoBuild() - .EnableLogOutput() ))); Target Benchmark => _ => _ .DependsOn(Compile) - .Requires(() => Configuration.Equals(Configuration.Release)) .Executes(() => TestsDirectory - .GlobFiles($"**/bin/{Configuration}/**/*Benchmark*.dll") - .ForEach(benchmarkFile => DotNetBenchmark( + .GlobFiles($"**/bin/{Configuration.ToString()}/**/*Benchmark*.dll") + .ForEach(benchmarkFile => BenchmarkDotNet( s => s - .WithFilter("*") - .WithDllPath(benchmarkFile))) + .SetRuntimes("net7.0") + .SetFilter("*") + .SetAssemblyFile(benchmarkFile))) ); } \ No newline at end of file diff --git a/build/Configuration.cs b/build/Configuration.cs new file mode 100644 index 0000000..9749190 --- /dev/null +++ b/build/Configuration.cs @@ -0,0 +1,14 @@ +using System.ComponentModel; +using Nuke.Common.Tooling; + +[TypeConverter(typeof(TypeConverter))] +public class Configuration : Enumeration +{ + public static Configuration Debug = new Configuration { Value = nameof(Debug) }; + public static Configuration Release = new Configuration { Value = nameof(Release) }; + + public static implicit operator string(Configuration configuration) + { + return configuration.Value; + } +} \ No newline at end of file diff --git a/build/Directory.Build.props b/build/Directory.Build.props new file mode 100644 index 0000000..e147d63 --- /dev/null +++ b/build/Directory.Build.props @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/build/Directory.Build.targets b/build/Directory.Build.targets new file mode 100644 index 0000000..2532609 --- /dev/null +++ b/build/Directory.Build.targets @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/build/_build.csproj b/build/_build.csproj index 88feea9..edfc6ae 100644 --- a/build/_build.csproj +++ b/build/_build.csproj @@ -2,17 +2,19 @@ Exe - netcoreapp3.1 CS0649;CS0169 .. ..\test - 8 + default enable + 1 + net7.0 - - + + + diff --git a/build/benchmarks/BenchmarkToolSettings.cs b/build/benchmarks/BenchmarkToolSettings.cs deleted file mode 100644 index ecb4655..0000000 --- a/build/benchmarks/BenchmarkToolSettings.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Collections.Generic; -using Nuke.Common.Tooling; -using Nuke.Common.Tools.DotNet; - -namespace _build.benchmarks -{ - public class BenchmarkToolSettings : ToolSettings - { - readonly IDictionary _arguments; - - public BenchmarkToolSettings() - { - _arguments = new Dictionary(); - } - - public override string ToolPath => base.ToolPath ?? DotNetTasks.DotNetPath; - - public string DllPath { get; private set; } - - public BenchmarkToolSettings WithDllPath(string path) - { - DllPath = path; - return this; - } - - public BenchmarkToolSettings WithFilter(string filter) - { - _arguments["filter"] = filter; - return this; - } - - public override Action CustomLogger => DotNetTasks.DotNetLogger; - - protected override Arguments ConfigureArguments(Arguments arguments) - { - arguments.Add("benchmark"); - arguments.Add(DllPath); - foreach (var (k, v) in _arguments) - { - arguments.Add($"--{k} {{value}}", v); - } - - return base.ConfigureArguments(arguments); - } - } -} \ No newline at end of file diff --git a/build/benchmarks/DotnetBenchmarkExtensions.cs b/build/benchmarks/DotnetBenchmarkExtensions.cs deleted file mode 100644 index 686c8a3..0000000 --- a/build/benchmarks/DotnetBenchmarkExtensions.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Collections.Generic; -using Nuke.Common.Tooling; - -namespace _build.benchmarks -{ - public static class DotNetBenchmarkExtensions - { - public static IReadOnlyCollection DotNetBenchmark(Configure configurator) - { - return DotNetBenchmark(configurator(new BenchmarkToolSettings())); - } - - public static IReadOnlyCollection DotNetBenchmark(BenchmarkToolSettings toolSettings = null) - { - toolSettings ??= new BenchmarkToolSettings(); - var process = ProcessTasks.StartProcess(toolSettings); - process.AssertZeroExitCode(); - return process.Output; - } - } -} \ No newline at end of file diff --git a/global.json b/global.json new file mode 100644 index 0000000..08585a2 --- /dev/null +++ b/global.json @@ -0,0 +1,5 @@ +{ + "sdk": { + "version": "7.0.100" + } +} \ No newline at end of file diff --git a/src/Tand.Core/Api/ITandTarget.cs b/src/Tand.Core/Api/ITandTarget.cs index 6c937f0..2411bc3 100644 --- a/src/Tand.Core/Api/ITandTarget.cs +++ b/src/Tand.Core/Api/ITandTarget.cs @@ -1,11 +1,15 @@ using Tand.Core.Models; -namespace Tand.Core.Api -{ - public interface ITandTarget - { - void OnEnterMethod(CallEnterContext enterContext); +namespace Tand.Core.Api; - void OnLeaveMethod(CallLeaveContext leaveContext); - } +public interface ITandTarget +{ + +} + +public interface ITandTarget : ITandTarget +{ + void OnEnterMethod(CallEnterContext enterContext); + + void OnLeaveMethod(CallLeaveContext leaveContext); } \ No newline at end of file diff --git a/src/Tand.Core/Api/TandAttribute.cs b/src/Tand.Core/Api/TandAttribute.cs index 7cf5bad..2d65323 100644 --- a/src/Tand.Core/Api/TandAttribute.cs +++ b/src/Tand.Core/Api/TandAttribute.cs @@ -1,16 +1,24 @@ using System; -namespace Tand.Core.Api +namespace Tand.Core.Api; + +[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] +public class TandAttribute : Attribute { - [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] - public class TandAttribute : Attribute + public TandAttribute(Type targetType) { - - public TandAttribute(Type targetType) - { - TargetType = targetType; - } - - public Type TargetType { get; } + TargetType = targetType; } -} \ No newline at end of file + + internal Type TargetType { get; } +} + +#if NET7_0 +[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] +public class TandAttribute : TandAttribute where TTandTarget : ITandTarget +{ + public TandAttribute() : base(typeof(TTandTarget)) + { + } +} +#endif \ No newline at end of file diff --git a/src/Tand.Core/Models/CallEnterContext.cs b/src/Tand.Core/Models/CallEnterContext.cs index 7fc2b91..e58e29c 100644 --- a/src/Tand.Core/Models/CallEnterContext.cs +++ b/src/Tand.Core/Models/CallEnterContext.cs @@ -2,22 +2,21 @@ using System.Collections.Generic; using System.Linq; using Tand.Core.Models; -namespace Tand.Core.Models +namespace Tand.Core.Models; + +public record CallEnterContext { - public readonly struct CallEnterContext + private readonly IDictionary _methodArgs; + + public CallEnterContext(T instance, IDictionary args) { - private readonly IDictionary _methodArgs; - - public CallEnterContext(T instance, IDictionary args) - { - Instance = instance; - _methodArgs = args; - } - - public T Instance { get; } - - public object? this[string argName] => _methodArgs.ContainsKey(argName) ? _methodArgs[argName] : null; - - public IEnumerable Arguments => _methodArgs.Select(kv => new MethodArgument(kv.Key, kv.Value)); + Instance = instance; + _methodArgs = args; } + + public T Instance { get; } + + public object? this[string argName] => _methodArgs.ContainsKey(argName) ? _methodArgs[argName] : null; + + public IEnumerable Arguments => _methodArgs.Select(kv => new MethodArgument(kv.Key, kv.Value)); } \ No newline at end of file diff --git a/src/Tand.Core/Models/CallLeaveContext.cs b/src/Tand.Core/Models/CallLeaveContext.cs index 5decb76..caf595a 100644 --- a/src/Tand.Core/Models/CallLeaveContext.cs +++ b/src/Tand.Core/Models/CallLeaveContext.cs @@ -1,29 +1,28 @@ using System.Collections.Generic; using System.Linq; -namespace Tand.Core.Models +namespace Tand.Core.Models; + +public record CallLeaveContext { - public readonly struct CallLeaveContext + private readonly IDictionary _methodArgs; + + public CallLeaveContext( + T instance, + IDictionary args, + object callResult + ) { - private readonly IDictionary _methodArgs; - - public CallLeaveContext( - T instance, - IDictionary args, - object callResult - ) - { - Instance = instance; - _methodArgs = args; - CallResult = callResult; - } - - public T Instance { get; } - - public object CallResult { get; } - - public object? this[string argName] => _methodArgs.ContainsKey(argName) ? _methodArgs[argName] : null; - - public IEnumerable Arguments => _methodArgs.Select(kv => new MethodArgument(kv.Key, kv.Value)); + Instance = instance; + _methodArgs = args; + CallResult = callResult; } + + public T Instance { get; } + + public object CallResult { get; } + + public object? this[string argName] => _methodArgs.ContainsKey(argName) ? _methodArgs[argName] : null; + + public IEnumerable Arguments => _methodArgs.Select(kv => new MethodArgument(kv.Key, kv.Value)); } \ No newline at end of file diff --git a/src/Tand.Core/Models/MethodArgument.cs b/src/Tand.Core/Models/MethodArgument.cs index 5c646a1..35e2061 100644 --- a/src/Tand.Core/Models/MethodArgument.cs +++ b/src/Tand.Core/Models/MethodArgument.cs @@ -1,21 +1,3 @@ -namespace Tand.Core.Models -{ - public readonly struct MethodArgument - { - public MethodArgument(string name, object value) - { - Name = name; - Value = value; - } +namespace Tand.Core.Models; - public string Name { get; } - - public object Value { get; } - - public void Deconstruct(out string name, out object value) - { - name = Name; - value = Value; - } - } -} \ No newline at end of file +public record MethodArgument(string Name, object Value); \ No newline at end of file diff --git a/src/Tand.Core/Tand.Core.csproj b/src/Tand.Core/Tand.Core.csproj index 7a53e42..e826b8b 100644 --- a/src/Tand.Core/Tand.Core.csproj +++ b/src/Tand.Core/Tand.Core.csproj @@ -2,12 +2,12 @@ Tand.Core - https://github.com/baez90/tand - netstandard2.1 + https://code.icb4dc0.de/prskr/tand 0.0.1 - 8 + default enable true + net6.0;net7.0 diff --git a/src/Tand.Extensions.DependencyInjection/Tand.Extensions.DependencyInjection.csproj b/src/Tand.Extensions.DependencyInjection/Tand.Extensions.DependencyInjection.csproj index d5b15f5..05bdaec 100644 --- a/src/Tand.Extensions.DependencyInjection/Tand.Extensions.DependencyInjection.csproj +++ b/src/Tand.Extensions.DependencyInjection/Tand.Extensions.DependencyInjection.csproj @@ -2,15 +2,19 @@ Tand.Extensions.DependencyInjection - netstandard2.1 + net6.0;net7.0 0.0.1 - https://github.com/baez90/tand - 8 + https://code.icb4dc0.de/prskr/tand + default enable - - + + + + + + diff --git a/test/Tand.Core.Benchmarks/RationalsProvider.cs b/test/Tand.Core.Benchmarks/RationalsProvider.cs index 0085e3c..5c23f4d 100644 --- a/test/Tand.Core.Benchmarks/RationalsProvider.cs +++ b/test/Tand.Core.Benchmarks/RationalsProvider.cs @@ -6,7 +6,7 @@ namespace Tand.Core.Benchmarks { public interface IRationalsProvider { - [Tand(typeof(ExecutionTimeTand))] + [Tand>] ICollection Generate(IEnumerable<(int n, int d)> input); } diff --git a/test/Tand.Core.Benchmarks/Tand.Core.Benchmarks.csproj b/test/Tand.Core.Benchmarks/Tand.Core.Benchmarks.csproj index f362315..301def7 100644 --- a/test/Tand.Core.Benchmarks/Tand.Core.Benchmarks.csproj +++ b/test/Tand.Core.Benchmarks/Tand.Core.Benchmarks.csproj @@ -1,14 +1,14 @@ - netstandard2.1 + net7.0 true - 8 + default enable - + diff --git a/test/Tand.Core.Tests/Tand.Core.Tests.csproj b/test/Tand.Core.Tests/Tand.Core.Tests.csproj index 8cc13a4..16ed0ee 100644 --- a/test/Tand.Core.Tests/Tand.Core.Tests.csproj +++ b/test/Tand.Core.Tests/Tand.Core.Tests.csproj @@ -1,17 +1,23 @@ - netcoreapp3.1 + net7.0 false - 8 + default enable - - - - + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/test/Tand.Core.Tests/TandSample.cs b/test/Tand.Core.Tests/TandSample.cs index 992b1cf..5c3b9b0 100644 --- a/test/Tand.Core.Tests/TandSample.cs +++ b/test/Tand.Core.Tests/TandSample.cs @@ -5,7 +5,7 @@ namespace Tand.Core.Tests public interface ITandSample { - [Tand(typeof(LogTarget))] + [Tand>] int LogMyParams(string s, int i); } diff --git a/test/Tand.Core.Tests/TandTests.cs b/test/Tand.Core.Tests/TandTests.cs index 717eeb3..121b947 100644 --- a/test/Tand.Core.Tests/TandTests.cs +++ b/test/Tand.Core.Tests/TandTests.cs @@ -1,22 +1,21 @@ using Xunit; -namespace Tand.Core.Tests +namespace Tand.Core.Tests; + +public class TandTests { - public class TandTests + + [Fact] + public void GenerateTand() { + var handleCallCounter = 0; + var resolver = new ResolverMock(new LogTarget(tandSample => handleCallCounter++)); + var tand = new Tand(resolver); - [Fact] - public void GenerateTand() - { - var handleCallCounter = 0; - var resolver = new ResolverMock(new LogTarget(tandSample => handleCallCounter++)); - var tand = new Tand(resolver); - - var sample = tand.DecorateWithTand(new TandSample()); - var result = sample.LogMyParams("Hello, World", 42); - Assert.Equal(1, result); - Assert.Equal(2, handleCallCounter); - Assert.Equal(1, resolver.ResolvingCounter); - } + var sample = tand.DecorateWithTand(new TandSample()); + var result = sample.LogMyParams("Hello, World", 42); + Assert.Equal(1, result); + Assert.Equal(2, handleCallCounter); + Assert.Equal(1, resolver.ResolvingCounter); } } \ No newline at end of file diff --git a/test/Tand.Extensions.DependencyInjection.Tests/Tand.Extensions.DependencyInjection.Tests.csproj b/test/Tand.Extensions.DependencyInjection.Tests/Tand.Extensions.DependencyInjection.Tests.csproj index 67c4386..c05e1e3 100644 --- a/test/Tand.Extensions.DependencyInjection.Tests/Tand.Extensions.DependencyInjection.Tests.csproj +++ b/test/Tand.Extensions.DependencyInjection.Tests/Tand.Extensions.DependencyInjection.Tests.csproj @@ -1,17 +1,23 @@ - netcoreapp3.1 + net7.0 false - 8 + default enable - - - - + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/test/Tand.Extensions.DependencyInjection.Tests/TandServiceExtensionsTests.cs b/test/Tand.Extensions.DependencyInjection.Tests/TandServiceExtensionsTests.cs index 2cf4b4c..96e9065 100644 --- a/test/Tand.Extensions.DependencyInjection.Tests/TandServiceExtensionsTests.cs +++ b/test/Tand.Extensions.DependencyInjection.Tests/TandServiceExtensionsTests.cs @@ -50,7 +50,7 @@ namespace Tand.Extensions.DependencyInjection.Tests public interface ISampleService { - [Tand(typeof(TestDecorator))] + [Tand] string Greet(); } diff --git a/test/build.cmd b/test/build.cmd index f9683e7..b08cc59 100755 --- a/test/build.cmd +++ b/test/build.cmd @@ -1,6 +1,7 @@ :; set -eo pipefail -:; ./build.sh "$@" +:; SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd) +:; ${SCRIPT_DIR}/build.sh "$@" :; exit $? @ECHO OFF -powershell -ExecutionPolicy ByPass -NoProfile %0\..\build.ps1 %* +powershell -ExecutionPolicy ByPass -NoProfile -File "%~dp0build.ps1" %* diff --git a/test/build.ps1 b/test/build.ps1 index 98d26de..eee9fea 100644 --- a/test/build.ps1 +++ b/test/build.ps1 @@ -6,7 +6,7 @@ Param( Write-Output "PowerShell $($PSVersionTable.PSEdition) version $($PSVersionTable.PSVersion)" -Set-StrictMode -Version 2.0; $ErrorActionPreference = "Stop"; $ConfirmPreference = "None"; trap { exit 1 } +Set-StrictMode -Version 2.0; $ErrorActionPreference = "Stop"; $ConfirmPreference = "None"; trap { Write-Error $_ -ErrorAction Continue; exit 1 } $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent ########################################################################### @@ -14,14 +14,15 @@ $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent ########################################################################### $BuildProjectFile = "$PSScriptRoot\..\build\_build.csproj" -$TempDirectory = "$PSScriptRoot\..\.tmp" +$TempDirectory = "$PSScriptRoot\..\.nuke\temp" $DotNetGlobalFile = "$PSScriptRoot\..\global.json" -$DotNetInstallUrl = "https://raw.githubusercontent.com/dotnet/cli/master/scripts/obtain/dotnet-install.ps1" +$DotNetInstallUrl = "https://dot.net/v1/dotnet-install.ps1" $DotNetChannel = "Current" $env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1 $env:DOTNET_CLI_TELEMETRY_OPTOUT = 1 +$env:DOTNET_MULTILEVEL_LOOKUP = 0 ########################################################################### # EXECUTION @@ -32,37 +33,37 @@ function ExecSafe([scriptblock] $cmd) { if ($LASTEXITCODE) { exit $LASTEXITCODE } } -# If global.json exists, load expected version -if (Test-Path $DotNetGlobalFile) { - $DotNetGlobal = $(Get-Content $DotNetGlobalFile | Out-String | ConvertFrom-Json) - if ($DotNetGlobal.PSObject.Properties["sdk"] -and $DotNetGlobal.sdk.PSObject.Properties["version"]) { - $DotNetVersion = $DotNetGlobal.sdk.version - } -} - -# If dotnet is installed locally, and expected version is not set or installation matches the expected version +# If dotnet CLI is installed globally and it matches requested version, use for execution if ($null -ne (Get-Command "dotnet" -ErrorAction SilentlyContinue) -and ` - (!(Test-Path variable:DotNetVersion) -or $(& dotnet --version) -eq $DotNetVersion)) { + $(dotnet --version) -and $LASTEXITCODE -eq 0) { $env:DOTNET_EXE = (Get-Command "dotnet").Path } else { - $DotNetDirectory = "$TempDirectory\dotnet-win" - $env:DOTNET_EXE = "$DotNetDirectory\dotnet.exe" - # Download install script $DotNetInstallFile = "$TempDirectory\dotnet-install.ps1" New-Item -ItemType Directory -Path $TempDirectory -Force | Out-Null + [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 (New-Object System.Net.WebClient).DownloadFile($DotNetInstallUrl, $DotNetInstallFile) - # Install by channel or version - if (!(Test-Path variable:DotNetVersion)) { - ExecSafe { & $DotNetInstallFile -InstallDir $DotNetDirectory -Channel $DotNetChannel -NoPath } - } else { - ExecSafe { & $DotNetInstallFile -InstallDir $DotNetDirectory -Version $DotNetVersion -NoPath } + # If global.json exists, load expected version + if (Test-Path $DotNetGlobalFile) { + $DotNetGlobal = $(Get-Content $DotNetGlobalFile | Out-String | ConvertFrom-Json) + if ($DotNetGlobal.PSObject.Properties["sdk"] -and $DotNetGlobal.sdk.PSObject.Properties["version"]) { + $DotNetVersion = $DotNetGlobal.sdk.version + } } + + # Install by channel or version + $DotNetDirectory = "$TempDirectory\dotnet-win" + if (!(Test-Path variable:DotNetVersion)) { + ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Channel $DotNetChannel -NoPath } + } else { + ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Version $DotNetVersion -NoPath } + } + $env:DOTNET_EXE = "$DotNetDirectory\dotnet.exe" } -Write-Output "Microsoft (R) .NET Core SDK version $(& $env:DOTNET_EXE --version)" +Write-Output "Microsoft (R) .NET SDK version $(& $env:DOTNET_EXE --version)" -ExecSafe { & $env:DOTNET_EXE build $BuildProjectFile /nodeReuse:false -nologo -clp:NoSummary --verbosity quiet } +ExecSafe { & $env:DOTNET_EXE build $BuildProjectFile /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet } ExecSafe { & $env:DOTNET_EXE run --project $BuildProjectFile --no-build -- $BuildArguments } diff --git a/test/build.sh b/test/build.sh index 0289f2e..7f32232 100755 --- a/test/build.sh +++ b/test/build.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -echo $(bash --version 2>&1 | head -n 1) +bash --version 2>&1 | head -n 1 set -eo pipefail SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd) @@ -10,53 +10,53 @@ SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd) ########################################################################### BUILD_PROJECT_FILE="$SCRIPT_DIR/../build/_build.csproj" -TEMP_DIRECTORY="$SCRIPT_DIR/../.tmp" +TEMP_DIRECTORY="$SCRIPT_DIR/../.nuke/temp" DOTNET_GLOBAL_FILE="$SCRIPT_DIR/../global.json" -DOTNET_INSTALL_URL="https://raw.githubusercontent.com/dotnet/cli/master/scripts/obtain/dotnet-install.sh" +DOTNET_INSTALL_URL="https://dot.net/v1/dotnet-install.sh" DOTNET_CHANNEL="Current" export DOTNET_CLI_TELEMETRY_OPTOUT=1 export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 +export DOTNET_MULTILEVEL_LOOKUP=0 ########################################################################### # EXECUTION ########################################################################### function FirstJsonValue { - perl -nle 'print $1 if m{"'$1'": "([^"]+)",?}' <<< ${@:2} + perl -nle 'print $1 if m{"'"$1"'": "([^"]+)",?}' <<< "${@:2}" } -# If global.json exists, load expected version -if [[ -f "$DOTNET_GLOBAL_FILE" ]]; then - DOTNET_VERSION=$(FirstJsonValue "version" $(cat "$DOTNET_GLOBAL_FILE")) - if [[ "$DOTNET_VERSION" == "" ]]; then - unset DOTNET_VERSION - fi -fi - -# If dotnet is installed locally, and expected version is not set or installation matches the expected version -if [[ -x "$(command -v dotnet)" && (-z ${DOTNET_VERSION+x} || $(dotnet --version 2>&1) == "$DOTNET_VERSION") ]]; then +# If dotnet CLI is installed globally and it matches requested version, use for execution +if [ -x "$(command -v dotnet)" ] && dotnet --version &>/dev/null; then export DOTNET_EXE="$(command -v dotnet)" else - DOTNET_DIRECTORY="$TEMP_DIRECTORY/dotnet-unix" - export DOTNET_EXE="$DOTNET_DIRECTORY/dotnet" - # Download install script DOTNET_INSTALL_FILE="$TEMP_DIRECTORY/dotnet-install.sh" mkdir -p "$TEMP_DIRECTORY" curl -Lsfo "$DOTNET_INSTALL_FILE" "$DOTNET_INSTALL_URL" chmod +x "$DOTNET_INSTALL_FILE" + # If global.json exists, load expected version + if [[ -f "$DOTNET_GLOBAL_FILE" ]]; then + DOTNET_VERSION=$(FirstJsonValue "version" "$(cat "$DOTNET_GLOBAL_FILE")") + if [[ "$DOTNET_VERSION" == "" ]]; then + unset DOTNET_VERSION + fi + fi + # Install by channel or version + DOTNET_DIRECTORY="$TEMP_DIRECTORY/dotnet-unix" if [[ -z ${DOTNET_VERSION+x} ]]; then "$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --channel "$DOTNET_CHANNEL" --no-path else "$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --version "$DOTNET_VERSION" --no-path fi + export DOTNET_EXE="$DOTNET_DIRECTORY/dotnet" fi -echo "Microsoft (R) .NET Core SDK version $("$DOTNET_EXE" --version)" +echo "Microsoft (R) .NET SDK version $("$DOTNET_EXE" --version)" -"$DOTNET_EXE" build "$BUILD_PROJECT_FILE" /nodeReuse:false -nologo -clp:NoSummary --verbosity quiet +"$DOTNET_EXE" build "$BUILD_PROJECT_FILE" /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet "$DOTNET_EXE" run --project "$BUILD_PROJECT_FILE" --no-build -- "$@"