1+ # --- Magic Start ---
2+ Clear-Host
3+ Write-Host " --- Menyiapkan peluncuran project C# kamu ke awan! ---`n " - ForegroundColor Cyan - BackgroundColor DarkBlue
4+
5+ # 1. Cari file .csproj di folder saat ini
6+ $projectFiles = Get-ChildItem - Filter * .csproj
7+
8+ if ($projectFiles.Count -eq 0 ) {
9+ Write-Host " !!! Aduh! Gak ketemu file .csproj di sini. Coba cek lagi ya! !!!" - ForegroundColor Red
10+ exit 1
11+ }
12+
13+ # Jika ada lebih dari satu project, minta user pilih
14+ if ($projectFiles.Count -gt 1 ) {
15+ Write-Host " Wah, banyak project keren di sini! Pilih yang mana nih?:" - ForegroundColor Yellow
16+ for ($i = 0 ; $i -lt $projectFiles.Count ; $i ++ ) {
17+ Write-Host " [$i ] : $ ( $projectFiles [$i ].Name) " - ForegroundColor Gray
18+ }
19+ $choice = Read-Host " Ketik nomor pilihannya (default 0)"
20+ if ([string ]::IsNullOrWhiteSpace($choice )) { $choice = 0 }
21+ $selectedProject = $projectFiles [$choice ].FullName
22+ } else {
23+ $selectedProject = $projectFiles [0 ].FullName
24+ }
25+
26+ $projectName = [System.IO.Path ]::GetFileName($selectedProject )
27+ Write-Host " `n Project Terpilih: " - NoNewline; Write-Host " $projectName " - ForegroundColor Green - BackgroundColor Black
28+
29+ # 2. Minta input versi dari user
30+ Write-Host " `n Versi berapa yang mau kita rilis hari ini?" - ForegroundColor Yellow
31+ $newVersion = Read-Host " Masukkan versi (misal: 1.0.0)"
32+ if ([string ]::IsNullOrWhiteSpace($newVersion )) {
33+ Write-Host " Versi gak boleh kosong ya!" - ForegroundColor Red
34+ exit 1
35+ }
36+
37+ # 3. Update Versi di file XML .csproj 🛠️
38+ Write-Host " Sedang mengukir versi $newVersion ke dalam $projectName ..." - ForegroundColor DarkGray
39+ [xml ]$xml = Get-Content $selectedProject
40+ $propertyGroup = $xml.Project.PropertyGroup | Select-Object - First 1
41+
42+ if ($null -eq $propertyGroup.Version ) {
43+ $versionNode = $xml.CreateElement (" Version" )
44+ $versionNode.InnerText = [string ]$newVersion
45+ $propertyGroup.AppendChild ($versionNode )
46+ } else {
47+ # Perbaikan di sini: Tambahkan .#text atau .InnerText
48+ $propertyGroup.Version = [string ]$newVersion
49+ }
50+ $xml.Save ($selectedProject )
51+ Write-Host " Sip! Versi berhasil diupdate." - ForegroundColor Green
52+
53+ # 4. Proses Build & Pack
54+ Write-Host " `n Sedang membangun (Build) project... Tunggu bentar ya!" - ForegroundColor Cyan
55+ dotnet build $selectedProject -- configuration Release / nologo
56+ if ($LASTEXITCODE -ne 0 ) {
57+ Write-Host " Build-nya error! Cek kodenya lagi ya." - ForegroundColor Red
58+ exit 1
59+ }
60+
61+ Write-Host " Membungkus paket NuGet (Pack)..." - ForegroundColor Magenta
62+ $outputDir = " ./nupkg"
63+ if (! (Test-Path $outputDir )) { New-Item - ItemType Directory - Path $outputDir | Out-Null }
64+
65+ dotnet pack $selectedProject -- configuration Release -- output $outputDir -- no- build / p:PackageVersion= $newVersion / nologo
66+
67+ # 5. Konfirmasi Push ke NuGet
68+ Write-Host " `n Siap untuk terbang ke NuGet?" - ForegroundColor Yellow
69+ $confirmation = Read-Host " Kirim sekarang? (y/n)"
70+ if ($confirmation -eq ' y' ) {
71+ if ($null -eq $env: NUGET_API_KEY ) {
72+ Write-Host " Variabel `$ env:NUGET_API_KEY` belum ada di sistem kamu." - ForegroundColor Red
73+ exit 1
74+ }
75+
76+ $nupkgFile = Get-ChildItem " $outputDir /*$newVersion .nupkg" | Sort-Object LastWriteTime - Descending | Select-Object - First 1
77+
78+ if ($null -eq $nupkgFile ) {
79+ Write-Host " File paketnya nggak ketemu!" - ForegroundColor Red
80+ exit 1
81+ }
82+
83+ Write-Host " Mengirim paket ke NuGet..." - ForegroundColor DarkCyan
84+ dotnet nuget push $nupkgFile.FullName -- api- key $env: NUGET_API_KEY -- source " https://api.nuget.org/v3/index.json" -- skip-duplicate
85+
86+ if ($LASTEXITCODE -eq 0 ) {
87+ Write-Host " `n HOREEE! Paket kamu sudah mendarat di NuGet!" - ForegroundColor Green - BackgroundColor Black
88+ } else {
89+ Write-Host " `n Proses pengiriman gagal." - ForegroundColor Red
90+ }
91+ } else {
92+ Write-Host " Paket disimpan di folder ./nupkg." - ForegroundColor Yellow
93+ }
94+
95+ Write-Host " `n Happy Coding and Have a Great Day!`n " - ForegroundColor White - BackgroundColor DarkMagenta
0 commit comments