feat: upgrade to .NET6.0/7.0 and latest lib versions

This commit is contained in:
Peter 2022-12-13 21:11:26 +01:00
parent 55d756cb08
commit 1aa2d76ca8
Signed by: prskr
GPG key ID: C1DB5D2E8DB512F9
30 changed files with 350 additions and 247 deletions

View file

@ -9,7 +9,7 @@
] ]
}, },
"nuke.globaltool": { "nuke.globaltool": {
"version": "5.3.0", "version": "6.2.1",
"commands": [ "commands": [
"nuke" "nuke"
] ]

7
.gitignore vendored
View file

@ -11,3 +11,10 @@ _site
.idea/ .idea/
*.Artifacts/ *.Artifacts/
**/artifacts/ **/artifacts/
.nuke/temp/
##############
# files #
##############
*.DotSettings.user

1
.nuke
View file

@ -1 +0,0 @@
Tand.sln

116
.nuke/build.schema.json Normal file
View file

@ -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"
]
}
}
}
}
}

4
.nuke/parameters.json Normal file
View file

@ -0,0 +1,4 @@
{
"$schema": "./build.schema.json",
"Solution": "Tand.sln"
}

View file

@ -4,13 +4,13 @@ using Nuke.Common.Execution;
using Nuke.Common.Git; using Nuke.Common.Git;
using Nuke.Common.IO; using Nuke.Common.IO;
using Nuke.Common.ProjectModel; using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.DotNet; using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.GitVersion; using Nuke.Common.Tools.GitVersion;
using Nuke.Common.Tools.BenchmarkDotNet;
using Nuke.Common.Utilities.Collections; using Nuke.Common.Utilities.Collections;
using static Nuke.Common.IO.FileSystemTasks; using static Nuke.Common.IO.FileSystemTasks;
using static Nuke.Common.Tools.BenchmarkDotNet.BenchmarkDotNetTasks;
using static Nuke.Common.Tools.DotNet.DotNetTasks; using static Nuke.Common.Tools.DotNet.DotNetTasks;
using static _build.benchmarks.DotNetBenchmarkExtensions;
[GitHubActions( [GitHubActions(
"dotnet", "dotnet",
@ -19,7 +19,6 @@ using static _build.benchmarks.DotNetBenchmarkExtensions;
On = new []{GitHubActionsTrigger.Push, GitHubActionsTrigger.PullRequest} On = new []{GitHubActionsTrigger.Push, GitHubActionsTrigger.PullRequest}
) )
] ]
[CheckBuildProjectConfigurations]
[UnsetVisualStudioEnvironmentVariables] [UnsetVisualStudioEnvironmentVariables]
class Build : NukeBuild class Build : NukeBuild
{ {
@ -34,8 +33,10 @@ class Build : NukeBuild
readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release; readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
[Solution] readonly Solution Solution; [Solution] readonly Solution Solution;
[GitRepository] readonly GitRepository GitRepository; [GitRepository]
[GitVersion] readonly GitVersion GitVersion; readonly GitRepository GitRepository;
[GitVersion(Framework = "net6.0", NoFetch = true)]
readonly GitVersion GitVersion;
AbsolutePath SourceDirectory => RootDirectory / "src"; AbsolutePath SourceDirectory => RootDirectory / "src";
AbsolutePath TestsDirectory => RootDirectory / "test"; AbsolutePath TestsDirectory => RootDirectory / "test";
@ -73,8 +74,7 @@ class Build : NukeBuild
.SetProjectFile(Solution) .SetProjectFile(Solution)
.SetConfiguration(Configuration) .SetConfiguration(Configuration)
.EnableNoRestore() .EnableNoRestore()
.EnableNoBuild() .EnableNoBuild()));
.EnableLogOutput()));
Target Pack => _ => _ Target Pack => _ => _
.DependsOn(Test) .DependsOn(Test)
@ -90,17 +90,16 @@ class Build : NukeBuild
.EnableIncludeSymbols() .EnableIncludeSymbols()
.EnableNoRestore() .EnableNoRestore()
.EnableNoBuild() .EnableNoBuild()
.EnableLogOutput()
))); )));
Target Benchmark => _ => _ Target Benchmark => _ => _
.DependsOn(Compile) .DependsOn(Compile)
.Requires(() => Configuration.Equals(Configuration.Release))
.Executes(() => TestsDirectory .Executes(() => TestsDirectory
.GlobFiles($"**/bin/{Configuration}/**/*Benchmark*.dll") .GlobFiles($"**/bin/{Configuration.ToString()}/**/*Benchmark*.dll")
.ForEach(benchmarkFile => DotNetBenchmark( .ForEach(benchmarkFile => BenchmarkDotNet(
s => s s => s
.WithFilter("*") .SetRuntimes("net7.0")
.WithDllPath(benchmarkFile))) .SetFilter("*")
.SetAssemblyFile(benchmarkFile)))
); );
} }

14
build/Configuration.cs Normal file
View file

@ -0,0 +1,14 @@
using System.ComponentModel;
using Nuke.Common.Tooling;
[TypeConverter(typeof(TypeConverter<Configuration>))]
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;
}
}

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- This file prevents unintended imports of unrelated MSBuild files -->
<!-- Uncomment to include parent Directory.Build.props file -->
<!--<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />-->
</Project>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- This file prevents unintended imports of unrelated MSBuild files -->
<!-- Uncomment to include parent Directory.Build.targets file -->
<!--<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.targets', '$(MSBuildThisFileDirectory)../'))" />-->
</Project>

View file

@ -2,17 +2,19 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<NoWarn>CS0649;CS0169</NoWarn> <NoWarn>CS0649;CS0169</NoWarn>
<NukeRootDirectory>..</NukeRootDirectory> <NukeRootDirectory>..</NukeRootDirectory>
<NukeScriptDirectory>..\test</NukeScriptDirectory> <NukeScriptDirectory>..\test</NukeScriptDirectory>
<LangVersion>8</LangVersion> <LangVersion>default</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<NukeTelemetryVersion>1</NukeTelemetryVersion>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Nuke.Common" Version="5.3.0" /> <PackageReference Include="Nuke.Common" Version="6.2.1" />
<PackageDownload Include="GitVersion.Tool" Version="[5.1.1]" /> <PackageDownload Include="benchmarkdotnet.tool" Version="[0.12.1]" />
<PackageDownload Include="GitVersion.Tool" Version="[5.11.1]" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View file

@ -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<string, string> _arguments;
public BenchmarkToolSettings()
{
_arguments = new Dictionary<string, string>();
}
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<OutputType, string> 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);
}
}
}

View file

@ -1,21 +0,0 @@
using System.Collections.Generic;
using Nuke.Common.Tooling;
namespace _build.benchmarks
{
public static class DotNetBenchmarkExtensions
{
public static IReadOnlyCollection<Output> DotNetBenchmark(Configure<BenchmarkToolSettings> configurator)
{
return DotNetBenchmark(configurator(new BenchmarkToolSettings()));
}
public static IReadOnlyCollection<Output> DotNetBenchmark(BenchmarkToolSettings toolSettings = null)
{
toolSettings ??= new BenchmarkToolSettings();
var process = ProcessTasks.StartProcess(toolSettings);
process.AssertZeroExitCode();
return process.Output;
}
}
}

5
global.json Normal file
View file

@ -0,0 +1,5 @@
{
"sdk": {
"version": "7.0.100"
}
}

View file

@ -1,11 +1,15 @@
using Tand.Core.Models; using Tand.Core.Models;
namespace Tand.Core.Api namespace Tand.Core.Api;
public interface ITandTarget
{ {
public interface ITandTarget<T>
}
public interface ITandTarget<T> : ITandTarget
{ {
void OnEnterMethod(CallEnterContext<T> enterContext); void OnEnterMethod(CallEnterContext<T> enterContext);
void OnLeaveMethod(CallLeaveContext<T> leaveContext); void OnLeaveMethod(CallLeaveContext<T> leaveContext);
} }
}

View file

@ -1,16 +1,24 @@
using System; using System;
namespace Tand.Core.Api namespace Tand.Core.Api;
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class TandAttribute : Attribute public class TandAttribute : Attribute
{ {
public TandAttribute(Type targetType) public TandAttribute(Type targetType)
{ {
TargetType = targetType; TargetType = targetType;
} }
public Type TargetType { get; } internal Type TargetType { get; }
}
#if NET7_0
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class TandAttribute<TTandTarget> : TandAttribute where TTandTarget : ITandTarget
{
public TandAttribute() : base(typeof(TTandTarget))
{
} }
} }
#endif

View file

@ -2,9 +2,9 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using Tand.Core.Models; using Tand.Core.Models;
namespace Tand.Core.Models namespace Tand.Core.Models;
{
public readonly struct CallEnterContext<T> public record CallEnterContext<T>
{ {
private readonly IDictionary<string, object> _methodArgs; private readonly IDictionary<string, object> _methodArgs;
@ -20,4 +20,3 @@ namespace Tand.Core.Models
public IEnumerable<MethodArgument> Arguments => _methodArgs.Select(kv => new MethodArgument(kv.Key, kv.Value)); public IEnumerable<MethodArgument> Arguments => _methodArgs.Select(kv => new MethodArgument(kv.Key, kv.Value));
} }
}

View file

@ -1,9 +1,9 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
namespace Tand.Core.Models namespace Tand.Core.Models;
{
public readonly struct CallLeaveContext<T> public record CallLeaveContext<T>
{ {
private readonly IDictionary<string, object> _methodArgs; private readonly IDictionary<string, object> _methodArgs;
@ -26,4 +26,3 @@ namespace Tand.Core.Models
public IEnumerable<MethodArgument> Arguments => _methodArgs.Select(kv => new MethodArgument(kv.Key, kv.Value)); public IEnumerable<MethodArgument> Arguments => _methodArgs.Select(kv => new MethodArgument(kv.Key, kv.Value));
} }
}

View file

@ -1,21 +1,3 @@
namespace Tand.Core.Models namespace Tand.Core.Models;
{
public readonly struct MethodArgument
{
public MethodArgument(string name, object value)
{
Name = name;
Value = value;
}
public string Name { get; } public record MethodArgument(string Name, object Value);
public object Value { get; }
public void Deconstruct(out string name, out object value)
{
name = Name;
value = Value;
}
}
}

View file

@ -2,12 +2,12 @@
<PropertyGroup> <PropertyGroup>
<PackageId>Tand.Core</PackageId> <PackageId>Tand.Core</PackageId>
<RepositoryUrl>https://github.com/baez90/tand</RepositoryUrl> <RepositoryUrl>https://code.icb4dc0.de/prskr/tand</RepositoryUrl>
<TargetFramework>netstandard2.1</TargetFramework>
<Version>0.0.1</Version> <Version>0.0.1</Version>
<LangVersion>8</LangVersion> <LangVersion>default</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View file

@ -2,15 +2,19 @@
<PropertyGroup> <PropertyGroup>
<PackageId>Tand.Extensions.DependencyInjection</PackageId> <PackageId>Tand.Extensions.DependencyInjection</PackageId>
<TargetFramework>netstandard2.1</TargetFramework> <TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<Version>0.0.1</Version> <Version>0.0.1</Version>
<RepositoryUrl>https://github.com/baez90/tand</RepositoryUrl> <RepositoryUrl>https://code.icb4dc0.de/prskr/tand</RepositoryUrl>
<LangVersion>8</LangVersion> <LangVersion>default</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View file

@ -6,7 +6,7 @@ namespace Tand.Core.Benchmarks
{ {
public interface IRationalsProvider public interface IRationalsProvider
{ {
[Tand(typeof(ExecutionTimeTand<IRationalsProvider>))] [Tand<ExecutionTimeTand<IRationalsProvider>>]
ICollection<Rational> Generate(IEnumerable<(int n, int d)> input); ICollection<Rational> Generate(IEnumerable<(int n, int d)> input);
} }

View file

@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework> <TargetFramework>net7.0</TargetFramework>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<LangVersion>8</LangVersion> <LangVersion>default</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.0" /> <PackageReference Include="BenchmarkDotNet" Version="0.13.2" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View file

@ -1,17 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFramework>net7.0</TargetFramework>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
<LangVersion>8</LangVersion> <LangVersion>default</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="xunit" Version="2.4.0" /> <PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" /> <PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="coverlet.collector" Version="1.0.1" /> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View file

@ -5,7 +5,7 @@ namespace Tand.Core.Tests
public interface ITandSample public interface ITandSample
{ {
[Tand(typeof(LogTarget<ITandSample>))] [Tand<LogTarget<ITandSample>>]
int LogMyParams(string s, int i); int LogMyParams(string s, int i);
} }

View file

@ -1,7 +1,7 @@
using Xunit; using Xunit;
namespace Tand.Core.Tests namespace Tand.Core.Tests;
{
public class TandTests public class TandTests
{ {
@ -19,4 +19,3 @@ namespace Tand.Core.Tests
Assert.Equal(1, resolver.ResolvingCounter); Assert.Equal(1, resolver.ResolvingCounter);
} }
} }
}

View file

@ -1,17 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFramework>net7.0</TargetFramework>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
<LangVersion>8</LangVersion> <LangVersion>default</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="xunit" Version="2.4.0" /> <PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" /> <PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="coverlet.collector" Version="1.0.1" /> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View file

@ -50,7 +50,7 @@ namespace Tand.Extensions.DependencyInjection.Tests
public interface ISampleService public interface ISampleService
{ {
[Tand(typeof(TestDecorator))] [Tand<TestDecorator>]
string Greet(); string Greet();
} }

View file

@ -1,6 +1,7 @@
:; set -eo pipefail :; set -eo pipefail
:; ./build.sh "$@" :; SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
:; ${SCRIPT_DIR}/build.sh "$@"
:; exit $? :; exit $?
@ECHO OFF @ECHO OFF
powershell -ExecutionPolicy ByPass -NoProfile %0\..\build.ps1 %* powershell -ExecutionPolicy ByPass -NoProfile -File "%~dp0build.ps1" %*

View file

@ -6,7 +6,7 @@ Param(
Write-Output "PowerShell $($PSVersionTable.PSEdition) version $($PSVersionTable.PSVersion)" 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 $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
########################################################################### ###########################################################################
@ -14,14 +14,15 @@ $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
########################################################################### ###########################################################################
$BuildProjectFile = "$PSScriptRoot\..\build\_build.csproj" $BuildProjectFile = "$PSScriptRoot\..\build\_build.csproj"
$TempDirectory = "$PSScriptRoot\..\.tmp" $TempDirectory = "$PSScriptRoot\..\.nuke\temp"
$DotNetGlobalFile = "$PSScriptRoot\..\global.json" $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" $DotNetChannel = "Current"
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1 $env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1
$env:DOTNET_CLI_TELEMETRY_OPTOUT = 1 $env:DOTNET_CLI_TELEMETRY_OPTOUT = 1
$env:DOTNET_MULTILEVEL_LOOKUP = 0
########################################################################### ###########################################################################
# EXECUTION # EXECUTION
@ -32,6 +33,18 @@ function ExecSafe([scriptblock] $cmd) {
if ($LASTEXITCODE) { exit $LASTEXITCODE } if ($LASTEXITCODE) { exit $LASTEXITCODE }
} }
# If dotnet CLI is installed globally and it matches requested version, use for execution
if ($null -ne (Get-Command "dotnet" -ErrorAction SilentlyContinue) -and `
$(dotnet --version) -and $LASTEXITCODE -eq 0) {
$env:DOTNET_EXE = (Get-Command "dotnet").Path
}
else {
# 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)
# If global.json exists, load expected version # If global.json exists, load expected version
if (Test-Path $DotNetGlobalFile) { if (Test-Path $DotNetGlobalFile) {
$DotNetGlobal = $(Get-Content $DotNetGlobalFile | Out-String | ConvertFrom-Json) $DotNetGlobal = $(Get-Content $DotNetGlobalFile | Out-String | ConvertFrom-Json)
@ -40,29 +53,17 @@ if (Test-Path $DotNetGlobalFile) {
} }
} }
# If dotnet is installed locally, and expected version is not set or installation matches the expected version
if ($null -ne (Get-Command "dotnet" -ErrorAction SilentlyContinue) -and `
(!(Test-Path variable:DotNetVersion) -or $(& dotnet --version) -eq $DotNetVersion)) {
$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
(New-Object System.Net.WebClient).DownloadFile($DotNetInstallUrl, $DotNetInstallFile)
# Install by channel or version # Install by channel or version
$DotNetDirectory = "$TempDirectory\dotnet-win"
if (!(Test-Path variable:DotNetVersion)) { if (!(Test-Path variable:DotNetVersion)) {
ExecSafe { & $DotNetInstallFile -InstallDir $DotNetDirectory -Channel $DotNetChannel -NoPath } ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Channel $DotNetChannel -NoPath }
} else { } else {
ExecSafe { & $DotNetInstallFile -InstallDir $DotNetDirectory -Version $DotNetVersion -NoPath } 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 } ExecSafe { & $env:DOTNET_EXE run --project $BuildProjectFile --no-build -- $BuildArguments }

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
echo $(bash --version 2>&1 | head -n 1) bash --version 2>&1 | head -n 1
set -eo pipefail set -eo pipefail
SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd) 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" 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_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" DOTNET_CHANNEL="Current"
export DOTNET_CLI_TELEMETRY_OPTOUT=1 export DOTNET_CLI_TELEMETRY_OPTOUT=1
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
export DOTNET_MULTILEVEL_LOOKUP=0
########################################################################### ###########################################################################
# EXECUTION # EXECUTION
########################################################################### ###########################################################################
function FirstJsonValue { 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 dotnet CLI is installed globally and it matches requested version, use for execution
if [[ -f "$DOTNET_GLOBAL_FILE" ]]; then if [ -x "$(command -v dotnet)" ] && dotnet --version &>/dev/null; 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
export DOTNET_EXE="$(command -v dotnet)" export DOTNET_EXE="$(command -v dotnet)"
else else
DOTNET_DIRECTORY="$TEMP_DIRECTORY/dotnet-unix"
export DOTNET_EXE="$DOTNET_DIRECTORY/dotnet"
# Download install script # Download install script
DOTNET_INSTALL_FILE="$TEMP_DIRECTORY/dotnet-install.sh" DOTNET_INSTALL_FILE="$TEMP_DIRECTORY/dotnet-install.sh"
mkdir -p "$TEMP_DIRECTORY" mkdir -p "$TEMP_DIRECTORY"
curl -Lsfo "$DOTNET_INSTALL_FILE" "$DOTNET_INSTALL_URL" curl -Lsfo "$DOTNET_INSTALL_FILE" "$DOTNET_INSTALL_URL"
chmod +x "$DOTNET_INSTALL_FILE" 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 # Install by channel or version
DOTNET_DIRECTORY="$TEMP_DIRECTORY/dotnet-unix"
if [[ -z ${DOTNET_VERSION+x} ]]; then if [[ -z ${DOTNET_VERSION+x} ]]; then
"$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --channel "$DOTNET_CHANNEL" --no-path "$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --channel "$DOTNET_CHANNEL" --no-path
else else
"$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --version "$DOTNET_VERSION" --no-path "$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --version "$DOTNET_VERSION" --no-path
fi fi
export DOTNET_EXE="$DOTNET_DIRECTORY/dotnet"
fi 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 -- "$@" "$DOTNET_EXE" run --project "$BUILD_PROJECT_FILE" --no-build -- "$@"