-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.ps1
More file actions
122 lines (102 loc) · 4.24 KB
/
setup.ps1
File metadata and controls
122 lines (102 loc) · 4.24 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# setup.ps1
# Automates scaffolding for the FocusFlow solution and projects using .NET 9
# Run this script from the repository root or the directory where you want the solution created.
# Stop on first error
$ErrorActionPreference = 'Stop'
# Resolve script directory and set it as current location to make paths predictable
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
if (-not $ScriptDir) { $ScriptDir = Get-Location }
Set-Location $ScriptDir
Write-Host "Working directory: $PWD"
# Check that dotnet CLI is available
if (-not (Get-Command dotnet -ErrorAction SilentlyContinue)) {
Write-Error "dotnet CLI not found. Please install .NET 9 SDK and ensure 'dotnet' is on PATH."
exit 1
}
# Verify .NET SDK major version is 9 or greater
$dotnetVersion = (& dotnet --version) -split '\r?\n' | Select-Object -First 1
if (-not $dotnetVersion) {
Write-Error "Unable to determine dotnet SDK version."
exit 1
}
try {
$major = [int]($dotnetVersion.Split('.')[0])
} catch {
Write-Error "Unexpected dotnet version format: $dotnetVersion"
exit 1
}
if ($major -lt 9) {
Write-Error "This script requires .NET SDK 9 or newer. Current SDK version: $dotnetVersion"
exit 1
}
# Configuration
$solutionName = 'FocusFlow'
$solutionFile = "$solutionName.sln"
$projects = @(
@{ Name = 'FocusFlow.Core'; Type = 'classlib' },
@{ Name = 'FocusFlow.UI'; Type = 'wpf' }
)
# Helper to run dotnet commands and fail fast on error
function Run-DotNet {
param(
[Parameter(Mandatory=$true)]
[string[]] $DotNetArgs
)
Write-Host "dotnet $($DotNetArgs -join ' ')"
& dotnet @DotNetArgs
if ($LASTEXITCODE -ne 0) {
throw "Command 'dotnet $($DotNetArgs -join ' ')' failed with exit code $LASTEXITCODE"
}
}
# If a solution already exists, back it up (do not delete silently)
if (Test-Path $solutionFile) {
$timestamp = Get-Date -Format 'yyyyMMddHHmmss'
$backup = "$solutionFile.bak_$timestamp"
Write-Host "Existing solution '$solutionFile' found. Backing up to '$backup'"
Rename-Item -Path $solutionFile -NewName $backup -Force
}
# Create the solution
Write-Host "Creating solution '$solutionName'"
Run-DotNet -DotNetArgs @('new', 'sln', '-n', $solutionName)
# Create projects (skip creation if project file already exists)
foreach ($p in $projects) {
$projName = $p.Name
$projDir = Join-Path $ScriptDir $projName
$csproj = Join-Path $projDir "$projName.csproj"
if (Test-Path $csproj) {
Write-Host "Project '$projName' already exists at '$csproj' - skipping creation."
} else {
Write-Host "Creating project '$projName' (type: $($p.Type))"
if ($p.Type -eq 'classlib') {
Run-DotNet -DotNetArgs @('new', 'classlib', '-n', $projName, '-o', $projDir, '-f', 'net9.0')
} elseif ($p.Type -eq 'wpf') {
Run-DotNet -DotNetArgs @('new', 'wpf', '-n', $projName, '-o', $projDir, '-f', 'net9.0')
} else {
throw "Unknown project type: $($p.Type)"
}
}
# Add project to solution (dotnet will ignore duplicates)
Write-Host "Adding '$projName' to solution"
Run-DotNet -DotNetArgs @('sln', $solutionFile, 'add', $csproj)
}
# Add project reference: add FocusFlow.Core reference to FocusFlow.UI
$coreProj = Join-Path $ScriptDir 'FocusFlow.Core\FocusFlow.Core.csproj'
$uiProj = Join-Path $ScriptDir 'FocusFlow.UI\FocusFlow.UI.csproj'
if ((Test-Path $coreProj) -and (Test-Path $uiProj)) {
Write-Host "Adding project reference: '$coreProj' -> '$uiProj'"
# Fix: Ensure FocusFlow.UI references FocusFlow.Core
Run-DotNet -DotNetArgs @('add', $uiProj, 'reference', $coreProj)
} else {
Write-Warning "One or both project files not found. Skipping project reference step."
}
# Add CommunityToolkit.Mvvm package to FocusFlow.UI
if (Test-Path $uiProj) {
Write-Host "Adding NuGet package 'CommunityToolkit.Mvvm' to FocusFlow.UI"
Run-DotNet -DotNetArgs @('add', $uiProj, 'package', 'CommunityToolkit.Mvvm')
} else {
Write-Warning "FocusFlow.UI project file not found. Skipping NuGet package installation."
}
Write-Host "Setup completed successfully."
Write-Host "Solution file: $(Join-Path $ScriptDir $solutionFile)"
Write-Host "Projects created/added: $($projects | ForEach-Object { $_.Name } -join ', ')"
# End of script