Skip to content

Commit 9c7627e

Browse files
committed
add build scripts(#7)
1 parent 934c2b9 commit 9c7627e

16 files changed

+430
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,3 +396,4 @@ FodyWeavers.xsd
396396

397397
# JetBrains Rider
398398
*.sln.iml
399+
dist/

.nuke/build.schema.json

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"$ref": "#/definitions/build",
4+
"title": "Build Schema",
5+
"definitions": {
6+
"build": {
7+
"type": "object",
8+
"properties": {
9+
"Configuration": {
10+
"type": "string"
11+
},
12+
"Continue": {
13+
"type": "boolean",
14+
"description": "Indicates to continue a previously failed build attempt"
15+
},
16+
"Help": {
17+
"type": "boolean",
18+
"description": "Shows the help text for this build assembly"
19+
},
20+
"Host": {
21+
"type": "string",
22+
"description": "Host for execution. Default is 'automatic'",
23+
"enum": [
24+
"AppVeyor",
25+
"AzurePipelines",
26+
"Bamboo",
27+
"Bitbucket",
28+
"Bitrise",
29+
"GitHubActions",
30+
"GitLab",
31+
"Jenkins",
32+
"Rider",
33+
"SpaceAutomation",
34+
"TeamCity",
35+
"Terminal",
36+
"TravisCI",
37+
"VisualStudio",
38+
"VSCode"
39+
]
40+
},
41+
"NoLogo": {
42+
"type": "boolean",
43+
"description": "Disables displaying the NUKE logo"
44+
},
45+
"Partition": {
46+
"type": "string",
47+
"description": "Partition to use on CI"
48+
},
49+
"Plan": {
50+
"type": "boolean",
51+
"description": "Shows the execution plan (HTML)"
52+
},
53+
"Profile": {
54+
"type": "array",
55+
"description": "Defines the profiles to load",
56+
"items": {
57+
"type": "string"
58+
}
59+
},
60+
"Root": {
61+
"type": "string",
62+
"description": "Root directory during build execution"
63+
},
64+
"Runtime": {
65+
"type": "string"
66+
},
67+
"Skip": {
68+
"type": "array",
69+
"description": "List of targets to be skipped. Empty list skips all dependencies",
70+
"items": {
71+
"type": "string",
72+
"enum": [
73+
"Archive",
74+
"Clean",
75+
"Compile",
76+
"NativeArchive",
77+
"NativePublish",
78+
"Publish",
79+
"Restore"
80+
]
81+
}
82+
},
83+
"Target": {
84+
"type": "array",
85+
"description": "List of targets to be invoked. Default is '{default_target}'",
86+
"items": {
87+
"type": "string",
88+
"enum": [
89+
"Archive",
90+
"Clean",
91+
"Compile",
92+
"NativeArchive",
93+
"NativePublish",
94+
"Publish",
95+
"Restore"
96+
]
97+
}
98+
},
99+
"Verbosity": {
100+
"type": "string",
101+
"description": "Logging verbosity during build execution. Default is 'Normal'",
102+
"enum": [
103+
"Minimal",
104+
"Normal",
105+
"Quiet",
106+
"Verbose"
107+
]
108+
}
109+
}
110+
}
111+
}
112+
}

.nuke/parameters.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"$schema": "./build.schema.json",
3+
"Solution": "WEventViewer.sln"
4+
}

WEventViewer.sln

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "package-licenses", "package
1313
LICENSE.txt = LICENSE.txt
1414
EndProjectSection
1515
EndProject
16+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "nukebuild", "build\nukebuild.csproj", "{4A68C488-E8DA-4D4E-A299-CC0C78EC5590}"
17+
EndProject
1618
Global
1719
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1820
Debug|Any CPU = Debug|Any CPU
1921
Release|Any CPU = Release|Any CPU
2022
EndGlobalSection
2123
GlobalSection(ProjectConfigurationPlatforms) = postSolution
24+
{4A68C488-E8DA-4D4E-A299-CC0C78EC5590}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25+
{4A68C488-E8DA-4D4E-A299-CC0C78EC5590}.Release|Any CPU.ActiveCfg = Release|Any CPU
2226
{8341A7C3-A124-45AC-88F3-943943A81854}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2327
{8341A7C3-A124-45AC-88F3-943943A81854}.Debug|Any CPU.Build.0 = Debug|Any CPU
2428
{8341A7C3-A124-45AC-88F3-943943A81854}.Release|Any CPU.ActiveCfg = Release|Any CPU

build.ps1

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
[CmdletBinding()]
2+
Param(
3+
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
4+
[string[]]$BuildArguments
5+
)
6+
7+
Write-Output "PowerShell $($PSVersionTable.PSEdition) version $($PSVersionTable.PSVersion)"
8+
9+
Set-StrictMode -Version 2.0; $ErrorActionPreference = "Stop"; $ConfirmPreference = "None"; trap { Write-Error $_ -ErrorAction Continue; exit 1 }
10+
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
11+
12+
###########################################################################
13+
# CONFIGURATION
14+
###########################################################################
15+
16+
$BuildProjectFile = "$PSScriptRoot\build\nukebuild.csproj"
17+
$TempDirectory = "$PSScriptRoot\\.nuke\temp"
18+
19+
$DotNetGlobalFile = "$PSScriptRoot\\global.json"
20+
$DotNetInstallUrl = "https://dot.net/v1/dotnet-install.ps1"
21+
$DotNetChannel = "STS"
22+
23+
$env:DOTNET_CLI_TELEMETRY_OPTOUT = 1
24+
$env:DOTNET_NOLOGO = 1
25+
26+
###########################################################################
27+
# EXECUTION
28+
###########################################################################
29+
30+
function ExecSafe([scriptblock] $cmd) {
31+
& $cmd
32+
if ($LASTEXITCODE) { exit $LASTEXITCODE }
33+
}
34+
35+
# If dotnet CLI is installed globally and it matches requested version, use for execution
36+
if ($null -ne (Get-Command "dotnet" -ErrorAction SilentlyContinue) -and `
37+
$(dotnet --version) -and $LASTEXITCODE -eq 0) {
38+
$env:DOTNET_EXE = (Get-Command "dotnet").Path
39+
}
40+
else {
41+
# Download install script
42+
$DotNetInstallFile = "$TempDirectory\dotnet-install.ps1"
43+
New-Item -ItemType Directory -Path $TempDirectory -Force | Out-Null
44+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
45+
(New-Object System.Net.WebClient).DownloadFile($DotNetInstallUrl, $DotNetInstallFile)
46+
47+
# If global.json exists, load expected version
48+
if (Test-Path $DotNetGlobalFile) {
49+
$DotNetGlobal = $(Get-Content $DotNetGlobalFile | Out-String | ConvertFrom-Json)
50+
if ($DotNetGlobal.PSObject.Properties["sdk"] -and $DotNetGlobal.sdk.PSObject.Properties["version"]) {
51+
$DotNetVersion = $DotNetGlobal.sdk.version
52+
}
53+
}
54+
55+
# Install by channel or version
56+
$DotNetDirectory = "$TempDirectory\dotnet-win"
57+
if (!(Test-Path variable:DotNetVersion)) {
58+
ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Channel $DotNetChannel -NoPath }
59+
} else {
60+
ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Version $DotNetVersion -NoPath }
61+
}
62+
$env:DOTNET_EXE = "$DotNetDirectory\dotnet.exe"
63+
$env:PATH = "$DotNetDirectory;$env:PATH"
64+
}
65+
66+
Write-Output "Microsoft (R) .NET SDK version $(& $env:DOTNET_EXE --version)"
67+
68+
if (Test-Path env:NUKE_ENTERPRISE_TOKEN) {
69+
& $env:DOTNET_EXE nuget remove source "nuke-enterprise" > $null
70+
& $env:DOTNET_EXE nuget add source "https://f.feedz.io/nuke/enterprise/nuget" --name "nuke-enterprise" --username "PAT" --password $env:NUKE_ENTERPRISE_TOKEN > $null
71+
}
72+
73+
ExecSafe { & $env:DOTNET_EXE build $BuildProjectFile /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet }
74+
ExecSafe { & $env:DOTNET_EXE run --project $BuildProjectFile --no-build -- $BuildArguments }

build/.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[*.cs]
2+
dotnet_style_qualification_for_field = false:warning
3+
dotnet_style_qualification_for_property = false:warning
4+
dotnet_style_qualification_for_method = false:warning
5+
dotnet_style_qualification_for_event = false:warning
6+
dotnet_style_require_accessibility_modifiers = never:warning
7+
8+
csharp_style_expression_bodied_methods = true:silent
9+
csharp_style_expression_bodied_properties = true:warning
10+
csharp_style_expression_bodied_indexers = true:warning
11+
csharp_style_expression_bodied_accessors = true:warning

build/Build.cs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using System;
2+
using System.Linq;
3+
using Nuke.Common;
4+
using Nuke.Common.CI;
5+
using Nuke.Common.Execution;
6+
using Nuke.Common.IO;
7+
using Nuke.Common.ProjectModel;
8+
using Nuke.Common.Tooling;
9+
using Nuke.Common.Utilities.Collections;
10+
using Nuke.Common.Tools.DotNet;
11+
using static Nuke.Common.EnvironmentInfo;
12+
using static Nuke.Common.IO.FileSystemTasks;
13+
using static Nuke.Common.IO.PathConstruction;
14+
using static Nuke.Common.IO.CompressionTasks;
15+
using static Nuke.Common.Tools.DotNet.DotNetTasks;
16+
17+
partial class Build : NukeBuild, NativeBuild
18+
{
19+
/// Support plugins are available for:
20+
/// - JetBrains ReSharper https://nuke.build/resharper
21+
/// - JetBrains Rider https://nuke.build/rider
22+
/// - Microsoft VisualStudio https://nuke.build/visualstudio
23+
/// - Microsoft VSCode https://nuke.build/vscode
24+
25+
public static int Main () => Execute<Build>(x => x.Compile);
26+
27+
[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
28+
readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
29+
30+
Target Clean => _ => _
31+
.Before(Restore)
32+
.Executes(() =>
33+
{
34+
});
35+
36+
Target Restore => _ => _
37+
.Executes(() =>
38+
{
39+
});
40+
41+
Target Compile => _ => _
42+
.DependsOn(Restore)
43+
.Executes(() =>
44+
{
45+
});
46+
[Parameter]
47+
string Runtime = "win-x64";
48+
Target Publish => _ => _
49+
.Executes(() =>
50+
{
51+
var outdir = GetPublishOutputDirectory();
52+
var project = RootDirectory / "src" / "WEventViewer" / "WEventViewer.csproj";
53+
DotNetPublish(setting => setting.SetConfiguration(Configuration)
54+
.SetRuntime(Runtime)
55+
.SetPublishTrimmed(true)
56+
.SetSelfContained(true)
57+
.SetOutput(outdir)
58+
.SetProject(project)
59+
.SetPublishSingleFile(true)
60+
);
61+
});
62+
Target Archive => _ => _
63+
.DependsOn(Publish)
64+
.Executes(() =>
65+
{
66+
var outdir = GetPublishOutputDirectory();
67+
outdir.ZipTo(outdir.Parent / $"WEventViewer-{Runtime}.zip", fileMode: System.IO.FileMode.Create);
68+
});
69+
AbsolutePath GetPublishOutputDirectory()
70+
{
71+
return RootDirectory / "dist" / "publish" / Configuration / Runtime / "WEventViewer";
72+
}
73+
}

build/Configuration.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.ComponentModel;
3+
using System.Linq;
4+
using Nuke.Common.Tooling;
5+
6+
[TypeConverter(typeof(TypeConverter<Configuration>))]
7+
public class Configuration : Enumeration
8+
{
9+
public static Configuration Debug = new Configuration { Value = nameof(Debug) };
10+
public static Configuration Release = new Configuration { Value = nameof(Release) };
11+
12+
public static implicit operator string(Configuration configuration)
13+
{
14+
return configuration.Value;
15+
}
16+
}

build/Directory.Build.props

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
4+
<!-- This file prevents unintended imports of unrelated MSBuild files -->
5+
<!-- Uncomment to include parent Directory.Build.props file -->
6+
<!--<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />-->
7+
8+
</Project>

build/Directory.Build.targets

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
4+
<!-- This file prevents unintended imports of unrelated MSBuild files -->
5+
<!-- Uncomment to include parent Directory.Build.targets file -->
6+
<!--<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.targets', '$(MSBuildThisFileDirectory)../'))" />-->
7+
8+
</Project>

0 commit comments

Comments
 (0)