Skip to content

Commit aaa769f

Browse files
authored
Merge pull request #2 from Tirsvad/main
V0.1.1
2 parents 406ec05 + fc2f1be commit aaa769f

File tree

8 files changed

+195
-196
lines changed

8 files changed

+195
-196
lines changed

SECURITY.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Security Policy
2+
3+
## Supported Versions
4+
5+
This project is a collection of PowerShell scripts.
6+
We aim to support the latest PowerShell7.x and Windows PowerShell5.1 runtimes.
7+
Security fixes will be applied to the `main` branch and released as soon as practical.
8+
9+
| Version | Supported |
10+
| ------- | ------------------ |
11+
| 1.0.x | :white_check_mark: |
12+
| 0.1.x | :x: |
13+
14+
15+
## Reporting a Vulnerability
16+
17+
If you discover a security vulnerability, please report it privately so we can investigate and fix it before public disclosure.
18+
19+
Preferred reporting methods:
20+
21+
- Use GitHub's Security Advisories for this repository (recommended) so the maintainers can coordinate a fix and private disclosure. See: https://docs.github.com/en/code-security/security-advisories
22+
- If GitHub Security Advisories are not available for you, open a private communication to the repository maintainers (for example an email to the project maintainer) if such contact is published in the repository. Do not post security-sensitive information in public issues or PRs.
23+
24+
If you must use a public channel initially, avoid including exploit code or detailed reproduction steps until a private channel is established.
25+
26+
## What to Include in a Report
27+
28+
Please include as much of the following as possible:
29+
30+
- A clear description of the vulnerability and its impact (confidentiality, integrity, availability).
31+
- Step-by-step reproduction steps or a minimal proof-of-concept (in a private channel only).
32+
- Affected versions/files and the environment where the issue was observed (PowerShell version, OS).
33+
- Any relevant logs, stack traces or configuration snippets.
34+
- Contact information so the maintainers can follow up.
35+
36+
## Response Process and Timeline
37+
38+
- Acknowledgement: We will acknowledge receipt as soon as practicable.
39+
- Triage: We will triage and begin an investigation as soon as practicable.
40+
- Fix: We will work to provide a fix or mitigation as soon as practicable; timelines vary by severity and complexity.
41+
- Public disclosure: The project follows coordinated disclosure practices. We will coordinate any public disclosure with the reporter; if no agreement is reached, we may disclose after a reasonable period once a fix is available.
42+
43+
## Disclosure Policy
44+
45+
We prefer coordinated disclosure so that users can update safely.
46+
Please do not publicly disclose vulnerabilities until a maintainer has had a reasonable opportunity to respond and a fix is available.
47+
48+
## Credits
49+
50+
We appreciate security reports and will credit reporters in release notes or acknowledgements unless the reporter requests to remain anonymous.
51+
52+
---
53+
54+
If you have questions about this policy or need an alternate contact method, open an issue marked with the `security` label (avoid posting exploit details) or check the repository README for maintainer contact information.

src/Create-VSSolution.ps1

Lines changed: 82 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -126,29 +126,6 @@ function UnzipFileFromUrl {
126126
Remove-Item -Path $tempZip
127127
}
128128

129-
function Run {
130-
param (
131-
[string]$cmd,
132-
[object]$second = $null
133-
)
134-
135-
# If second argument provided, treat as executable path + args; otherwise treat first as a PowerShell command string
136-
if ($null -ne $second) {
137-
$argList = @()
138-
if ($second -is [System.Array]) { $argList = $second } else { $argList = @($second) }
139-
Write-Debug "Running: $cmd $($argList -join ' ')"
140-
$proc = Start-Process -FilePath $cmd -ArgumentList $argList -Wait -PassThru -WindowStyle Hidden
141-
}
142-
else {
143-
Write-Debug "Running: $cmd"
144-
$proc = Start-Process -FilePath "powershell" -ArgumentList @('-NoProfile', '-Command', $cmd) -Wait -PassThru -WindowStyle Hidden
145-
}
146-
if ($proc.ExitCode -ne 0) {
147-
Write-Err "Process $cmd $($argList -join ' ') failed with exit code $($proc.ExitCode)"
148-
}
149-
return $proc.ExitCode
150-
}
151-
152129
function CreateProjectPath {
153130
param (
154131
[string]$solutionPath,
@@ -168,14 +145,67 @@ function CreateCleanArchitectureProjects {
168145
[string]$projectPath = "src",
169146
[string]$targetFramework
170147
)
148+
149+
function Remove-DefaultClassFile {
150+
param (
151+
[string] $projectPath
152+
)
153+
$classFile = Join-Path -Path $projectPath -ChildPath "Class1.cs"
154+
if (Test-Path $classFile) {
155+
$cmd = "Remove-Item -Path `"$classFile`""
156+
$rc = Run $cmd
157+
Write-Debug "Removed default class file: $classFile"
158+
}
159+
}
160+
161+
function AddReferencesToProject {
162+
param (
163+
[string] $projectPath,
164+
[string[]] $references
165+
)
166+
# Find the project's .csproj file
167+
$projCsproj = Get-ChildItem -Path $projectPath -Filter '*.csproj' -File -ErrorAction SilentlyContinue | Select-Object -First 1
168+
if (-not $projCsproj) {
169+
Write-Warn "No .csproj found in project folder: $projectPath. Skipping reference addition."
170+
return
171+
}
172+
$projCsprojPath = $projCsproj.FullName
173+
174+
foreach ($ref in $references) {
175+
# Determine the sibling project directory (projects live under the same parent 'src' folder)
176+
$parentDir = Split-Path -Path $projectPath -Parent
177+
$refProjPath = Join-Path -Path $parentDir -ChildPath $ref
178+
$refProjFile = Join-Path -Path $refProjPath -ChildPath "$($ref).csproj"
179+
Write-Debug "Reference project file: $refProjFile"
180+
Write-Debug "Reference project path: $refProjPath"
181+
Write-Debug "projCsprojPath: $projCsprojPath"
182+
if (Test-Path $refProjFile) {
183+
Write-Debug "Adding reference to project: $refProjFile in $projCsprojPath"
184+
# Use dotnet CLI directly so we can check the exit code
185+
$cmd = "dotnet reference add `"$refProjFile`" --project `"$projCsprojPath`""
186+
$rc = Run $cmd
187+
if ($rc -ne 0) {
188+
Write-Warn "dotnet add returned exit code $rc when adding reference $refProjFile to $projCsprojPath"
189+
}
190+
else {
191+
Write-RunDone $true
192+
}
193+
}
194+
else {
195+
Write-Warn "Reference project file not found: $refProjFile"
196+
}
197+
}
198+
}
199+
171200
$projects = @(
172-
@{ Name = "Core"; Suffix = ".Core"; Type = "classlib" },
173-
@{ Name = "Infrastructure"; Suffix = ".Infrastructure"; Type = "classlib" },
174-
@{ Name = "Domain"; Suffix = ".Domain"; Type = "classlib" }
201+
@{ Name = "Domain"; Suffix = ".Domain"; Type = "classlib"; References = @() },
202+
@{ Name = "Core"; Suffix = ".Core"; Type = "classlib"; References = @("Domain") },
203+
@{ Name = "Infrastructure"; Suffix = ".Infrastructure"; Type = "classlib"; References = @("Core") }
175204
)
176205
foreach ($proj in $projects) {
177206
$projName = $proj.Name
178207
$projType = $proj.Type
208+
$projRefs = $proj.References
179209
# Build path as: $solutionPath\$projectPath\$projName
180210
$projPath = Join-Path -Path (Join-Path -Path $solutionPath -ChildPath $projectPath) -ChildPath $projName
181211
Write-Debug "Creating project: $projName at $projPath"
@@ -193,6 +223,17 @@ function CreateCleanArchitectureProjects {
193223
Write-Warning "Failed to add project $projName to solution."
194224
exit 2
195225
}
226+
227+
# Remove Class1.cs
228+
Remove-DefaultClassFile $projPath
229+
230+
if (-not $projRefs.Count -eq 0) {
231+
# Add references
232+
Write-Debug "project path $projPath"
233+
Write-Debug "project refs $projRefs"
234+
AddReferencesToProject -projectPath $projPath -references $projRefs
235+
}
236+
196237
CreateSubFolderForEachCleanArchitectureProjects -ProjectPath $projPath -projectName $projName
197238
}
198239
}
@@ -238,6 +279,7 @@ $ScriptDirectory = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
238279
$ScriptNamespace = "TirsvadScript.CreateVSSolution"
239280
# Path to the 'inc' directory for sourced libraries
240281
$ScriptDirectoryInc = Join-Path -Path $ScriptDirectory -ChildPath (Join-Path -Path $ScriptNamespace -ChildPath "inc")
282+
$ScriptDirectoryTemplates = Join-Path -Path $ScriptDirectory -ChildPath (Join-Path -Path $ScriptNamespace -ChildPath "templates")
241283

242284
################################################################################
243285
# Include logging library early so helper functions (Write-Warn etc.) are available
@@ -246,7 +288,10 @@ $ScriptDirectoryInc = Join-Path -Path $ScriptDirectory -ChildPath (Join-Path -Pa
246288

247289
# Dependencies
248290
$dependenciesTupleList = New-Object 'System.Collections.Generic.List[System.Tuple[string,string,string]]'
249-
$dependenciesTupleList.Add([Tuple]::Create("TirsvadScript.Logging", "TirsvadScript.LoggingLoaded", "https://github.com/TirsvadScript/PS.Logging/releases/download/v0.1.0/TirsvadScript.Logging.zip"))
291+
# $dependenciesTupleList.Add([Tuple]::Create("TirsvadScript.Logging", "TirsvadScript.LoggingLoaded", "https://github.com/TirsvadScript/PS.Logging/releases/download/v0.1.0/TirsvadScript.Logging.zip"))
292+
293+
# internal include of dependencies
294+
. "$ScriptDirectoryInc\command-handler.ps1"
250295

251296
CheckDependencies
252297
# exit0
@@ -263,7 +308,7 @@ $startingLocation = Get-Location
263308
$solutionPath = Join-Path -Path $startingLocation -ChildPath $SolutionName
264309
if (-not (Test-Path $solutionPath)) {
265310
New-Item -ItemType Directory -Path $solutionPath | Out-Null
266-
Write-Ok "Created solution directory: $solutionPath"
311+
Write-Debug "Created solution directory: $solutionPath"
267312
}
268313

269314
# Check if solutionDirectory is empty
@@ -316,13 +361,21 @@ switch ($ProjectTemplate) {
316361
"wpf" {
317362
$projectType = "wpf"
318363
$ProjectPath = Join-Path -Path (Join-Path -Path $solutionPath -ChildPath "src") -ChildPath "WpfUI"
319-
Write-Info "Created WPF solution: $SolutionName"
320364
$cmd = "dotnet new $projectType -n `"WpfUI`" -o `"${ProjectPath}`" -f `"$targetFramework`""
321365
$rc = Run $cmd
322366
if ($rc -ne 0) {
323367
Write-Warn "'dotnet new' failed for project WpfUI (rc=$rc)."
324368
exit 2
325369
}
370+
# Add project to solution
371+
$slnFile = Join-Path -Path $solutionPath -ChildPath "$($SolutionName).sln"
372+
$projFile = Join-Path -Path $ProjectPath -ChildPath "WpfUI.csproj"
373+
$added = AddProjectToSolution -slnPath $slnFile -projPath $projFile
374+
if (-not $added) {
375+
Write-Warning "Failed to add project $projName to solution."
376+
exit 2
377+
}
378+
Write-Info "Created WPF solution: $SolutionName"
326379
}
327380
default {
328381
Write-Err "Unsupported project template: $ProjectTemplate"

src/TirsvadScript.CreateVSSolution/inc/TirsvadScript.Logging/TirsvadScript.Logging.ps1

Lines changed: 0 additions & 130 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Guard: this file is intended to be dot-sourced (included) by the main script.
2+
# If executed directly, warn and exit to avoid unintended behavior.
3+
if ($MyInvocation.InvocationName -ne '.') {
4+
Write-Host "This script is a library and must be dot-sourced from the main script (e.g. `. .\Create-VSSolution.ps1`). Exiting." -ForegroundColor Yellow
5+
exit 1
6+
}
7+
8+
function Run {
9+
param (
10+
[string]$cmd,
11+
[object]$second = $null
12+
)
13+
14+
# If second argument provided, treat as executable path + args; otherwise treat first as a PowerShell command string
15+
if ($null -ne $second) {
16+
$argList = @()
17+
if ($second -is [System.Array]) { $argList = $second } else { $argList = @($second) }
18+
Write-Run "Running: $cmd $($argList -join ' ')"
19+
$proc = Start-Process -FilePath $cmd -ArgumentList $argList -Wait -PassThru -WindowStyle Hidden
20+
}
21+
else {
22+
Write-Run "Running: $cmd"
23+
$proc = Start-Process -FilePath "powershell" -ArgumentList @('-NoProfile', '-Command', $cmd) -Wait -PassThru -WindowStyle Hidden
24+
}
25+
if ($proc.ExitCode -ne 0) {
26+
Write-RunDone $false
27+
Write-Err "Process $cmd $($argList -join ' ') failed with exit code $($proc.ExitCode)"
28+
}
29+
else {
30+
Write-RunDone $true
31+
}
32+
return $proc.ExitCode
33+
}

0 commit comments

Comments
 (0)