-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
87 lines (78 loc) · 2.64 KB
/
Copy pathbuild.ps1
File metadata and controls
87 lines (78 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
[CmdletBinding()]
param()
$ErrorActionPreference = 'Stop'
$projectRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
$objectDirectory = Join-Path $projectRoot 'obj'
$outputDirectory = Join-Path $projectRoot 'dist'
$assetPath = Join-Path $projectRoot 'Assets\luoye-mark.png'
$iconPath = Join-Path $objectDirectory 'luoye.ico'
$outputPath = Join-Path $outputDirectory 'LuoyeCodexMeter.exe'
$compiler = Join-Path $env:WINDIR 'Microsoft.NET\Framework64\v4.0.30319\csc.exe'
$framework = Join-Path $env:WINDIR 'Microsoft.NET\Framework64\v4.0.30319'
$wpf = Join-Path $framework 'WPF'
if (-not (Test-Path -LiteralPath $compiler)) {
throw 'The .NET Framework C# compiler was not found.'
}
New-Item -ItemType Directory -Path $objectDirectory -Force | Out-Null
New-Item -ItemType Directory -Path $outputDirectory -Force | Out-Null
Add-Type -AssemblyName System.Drawing
if (-not ('LuoyeCodexMeterBuild.NativeIcon' -as [type])) {
Add-Type -TypeDefinition @'
using System;
using System.Runtime.InteropServices;
namespace LuoyeCodexMeterBuild {
public static class NativeIcon {
[DllImport("user32.dll")]
public static extern bool DestroyIcon(IntPtr icon);
}
}
'@
}
$bitmap = New-Object System.Drawing.Bitmap $assetPath
$iconHandle = $bitmap.GetHicon()
try {
$icon = [System.Drawing.Icon]::FromHandle($iconHandle)
$stream = [System.IO.File]::Create($iconPath)
try {
$icon.Save($stream)
}
finally {
$stream.Dispose()
$icon.Dispose()
}
}
finally {
$bitmap.Dispose()
[LuoyeCodexMeterBuild.NativeIcon]::DestroyIcon($iconHandle) | Out-Null
}
$references = @(
(Join-Path $framework 'System.dll'),
(Join-Path $framework 'System.Core.dll'),
(Join-Path $framework 'System.Drawing.dll'),
(Join-Path $framework 'System.Web.Extensions.dll'),
(Join-Path $framework 'System.Windows.Forms.dll'),
(Join-Path $framework 'System.Xaml.dll'),
(Join-Path $wpf 'WindowsBase.dll'),
(Join-Path $wpf 'PresentationCore.dll'),
(Join-Path $wpf 'PresentationFramework.dll')
)
$arguments = @(
'/nologo',
'/target:winexe',
'/platform:anycpu',
'/optimize+',
'/warn:4',
"/out:$outputPath",
"/win32manifest:$(Join-Path $projectRoot 'app.manifest')",
"/win32icon:$iconPath",
"/resource:$assetPath,LuoyeCodexMeter.Assets.luoye-mark.png"
)
$arguments += $references | ForEach-Object { "/reference:$_" }
$arguments += Get-ChildItem -LiteralPath (Join-Path $projectRoot 'src') -Filter '*.cs' |
Sort-Object Name |
ForEach-Object { $_.FullName }
& $compiler @arguments
if ($LASTEXITCODE -ne 0) {
throw "Build failed with exit code $LASTEXITCODE."
}
Write-Host "Built $outputPath"