From 455084d97e57a4ed5850e5d8a7dd59bb064dcf13 Mon Sep 17 00:00:00 2001 From: Gerardo Grignoli Date: Sat, 26 Nov 2022 11:22:49 -0300 Subject: [PATCH 1/9] Installer: Change manufacturer name (shown in Add/Remove Programs) --- src/gsudo.Installer/Product.wxs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gsudo.Installer/Product.wxs b/src/gsudo.Installer/Product.wxs index 1b94c31c..1adab137 100644 --- a/src/gsudo.Installer/Product.wxs +++ b/src/gsudo.Installer/Product.wxs @@ -3,7 +3,7 @@ + UpgradeCode="567b5616-d362-484e-b6ff-7c1875cf0aee" Manufacturer="Gerardo Grignoli"> Date: Fri, 17 Feb 2023 16:01:55 -0300 Subject: [PATCH 2/9] Publish to NuGet --- .github/workflows/release.yml | 4 ++- build/05-release-Chocolatey.ps1 | 18 +++++++--- build/Nuget/gsudo.nuspec.template | 55 +++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 build/Nuget/gsudo.nuspec.template diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1bc4046a..99b76d61 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -30,7 +30,7 @@ jobs: contents: write steps: - name: Install dependencies - run: choco install GitVersion.Portable wixtoolset --confirm --no-progress + run: choco install NuGet.CommandLine GitVersion.Portable wixtoolset --confirm --no-progress - uses: actions/checkout@v2 with: fetch-depth: 0 @@ -110,6 +110,8 @@ jobs: path: ./artifacts - name: Import Chocolatey Api Key run: choco apikey --key ${{ secrets.CHOCOLATEY_APIKEY }} --source https://push.chocolatey.org/ + - name: Import Nuget Api Key + run: nuget setapikey ${{ secrets.NUGET_APIKEY }} - name: Build Package for Chocolatey & Upload run: ./build/05-release-Chocolatey.ps1 - name: Upload build artifacts diff --git a/build/05-release-Chocolatey.ps1 b/build/05-release-Chocolatey.ps1 index 09793bdf..55a91951 100644 --- a/build/05-release-Chocolatey.ps1 +++ b/build/05-release-Chocolatey.ps1 @@ -6,9 +6,9 @@ if (! (Test-IsAdmin)) { throw "Must be admin to properly test generated package" } -Get-Item .\artifacts\x64\gsudo.exe > $null || $(throw "Missing binaries/artifacts") +pushd $PSScriptRoot\.. -pushd $PSScriptRoot\.. +Get-Item .\artifacts\x64\gsudo.exe > $null || $(throw "Missing binaries/artifacts") if ($env:version) { "- Getting version from env:version" @@ -21,8 +21,9 @@ if ($env:version) { } "- Using version number v$version / v$version_MajorMinorPatch" -"- Cleaning Choco template folder" +"- Cleaning Choco & Nuget template folder" git clean .\Build\Chocolatey\gsudo -xf +git clean .\Build\Nuget\gsudo -xf "- Adding Artifacts" cp artifacts\x?? .\Build\Chocolatey\gsudo\tools -Recurse -Force -Exclude *.pdb @@ -33,6 +34,8 @@ Get-ChildItem .\build\Chocolatey\gsudo\tools\ -Recurse -Filter *.exe | % { ni "$ # Generate Tools\VERIFICATION.txt Get-Content .\Build\Chocolatey\verification.txt.template | Out-File -encoding UTF8 .\Build\Chocolatey\gsudo\Tools\VERIFICATION.txt +(Get-Content Build\Nuget\gsudo.nuspec.template) -replace '#VERSION#', "$version" | Out-File -encoding UTF8 .\Build\Nuget\gsudo.nuspec + "- Calculating Hashes " @" @@ -47,7 +50,11 @@ Get-childitem *.bak -Recurse | Remove-Item mkdir Artifacts\Chocolatey -Force > $null & choco pack .\Build\Chocolatey\gsudo\gsudo.nuspec -outdir="$((get-item Artifacts\Chocolatey).FullName)" || $(throw "Choco pack failed.") -"- Testing package" +"- Packing v$version to nuget" +mkdir Artifacts\Nuget -Force > $null +& nuget pack .\Build\Nuget\gsudo.nuspec -OutputDirectory "$((get-item Artifacts\Nuget).FullName)" || $(throw "Nuget pack failed.") + +"- Testing choco package" if (choco list -lo | Where-object { $_.StartsWith("gsudo") }) { choco upgrade gsudo --failonstderr -s Artifacts\Chocolatey -f -pre --confirm || $(throw "Choco upgrade failed.") } else { @@ -57,7 +64,8 @@ if (choco list -lo | Where-object { $_.StartsWith("gsudo") }) { if($(choco apikey).Count -lt 2) { throw "Missing Chocolatey ApiKey. Use: choco apikey -k -s https://push.chocolatey.org/" } "`n- Uploading v$version to chocolatey" -choco push artifacts\Chocolatey\gsudo.$($version).nupkg || $(throw "Choco push failed.") +:: choco push artifacts\Chocolatey\gsudo.$($version).nupkg || $(throw "Choco push failed.") + "- Success" popd \ No newline at end of file diff --git a/build/Nuget/gsudo.nuspec.template b/build/Nuget/gsudo.nuspec.template new file mode 100644 index 00000000..5bd21a2c --- /dev/null +++ b/build/Nuget/gsudo.nuspec.template @@ -0,0 +1,55 @@ + + + + + + + + + gsudo + + + + #VERSION# + Gerardo Grignoli + + + + + gsudo - a sudo for windows + Gerardo Grignoli & GitHub contributors + + + 2023 Gerardo Grignoli + https://opensource.org/licenses/MIT + +`gsudo` allows to run commands with elevated permissions within the current console. +It is a `sudo` equivalent for Windows, with a similar user-experience as the original *nix sudo. + +Elevated commands are shown in the caller (non-elevated) console, no switching to another console required. + +http://github.com/gerardog/gsudo + +### Usage + +```gsudo [command] [arguments]``` +Executes the specified command, elevated, and returns. + +Examples + +```gsudo notepad c:\Windows\System32\drivers\etc\hosts``` +```gsudo cmd``` + + + http://github.com/gerardog/gsudo/releases/v#VERSION# + + + + + + + + + + + From 7b645570b4c8c7c78f2d110d2e9b5a7b1179b1fc Mon Sep 17 00:00:00 2001 From: Gerardo Grignoli Date: Fri, 17 Feb 2023 16:38:21 -0300 Subject: [PATCH 3/9] Publish to NuGet --- .github/workflows/release.yml | 26 ++++++++++++++++++++++++++ build/05-release-Chocolatey.ps1 | 16 ++++------------ build/06-release-Nuget.ps1 | 32 ++++++++++++++++++++++++++++++++ build/06-release-Scoop.ps1 | 1 - 4 files changed, 62 insertions(+), 13 deletions(-) create mode 100644 build/06-release-Nuget.ps1 delete mode 100644 build/06-release-Scoop.ps1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 99b76d61..25a12b68 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -126,6 +126,32 @@ jobs: identifier: gerardog.gsudo installers-regex: '\.msi$' # Only .msi files + publishNuget: + name: Push to Nuget + #if: github.ref == 'refs/heads/master' && github.repository == 'gerardog/gsudo' + if: github.repository == 'gerardog/gsudo' + runs-on: windows-latest + needs: [build, release] + permissions: + contents: write + environment: + name: release-nuget + env: + version: ${{ needs.build.outputs.version }} + version_MajorMinorPatch: ${{ needs.build.outputs.version_MajorMinorPatch }} + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - uses: actions/download-artifact@v3 + with: + name: Binaries + path: ./artifacts + - name: Import Nuget Api Key + run: nuget setapikey ${{ secrets.NUGET_APIKEY }} + - name: Build Package for Nuget & Upload + run: ./build/06-release-Nuget.ps1 + docs: needs: publish uses: ./.github/workflows/docs.yml diff --git a/build/05-release-Chocolatey.ps1 b/build/05-release-Chocolatey.ps1 index 55a91951..6aea2c8c 100644 --- a/build/05-release-Chocolatey.ps1 +++ b/build/05-release-Chocolatey.ps1 @@ -6,7 +6,7 @@ if (! (Test-IsAdmin)) { throw "Must be admin to properly test generated package" } -pushd $PSScriptRoot\.. +pushd $PSScriptRoot\.. Get-Item .\artifacts\x64\gsudo.exe > $null || $(throw "Missing binaries/artifacts") @@ -21,9 +21,8 @@ if ($env:version) { } "- Using version number v$version / v$version_MajorMinorPatch" -"- Cleaning Choco & Nuget template folder" +"- Cleaning Choco template folder" git clean .\Build\Chocolatey\gsudo -xf -git clean .\Build\Nuget\gsudo -xf "- Adding Artifacts" cp artifacts\x?? .\Build\Chocolatey\gsudo\tools -Recurse -Force -Exclude *.pdb @@ -34,8 +33,6 @@ Get-ChildItem .\build\Chocolatey\gsudo\tools\ -Recurse -Filter *.exe | % { ni "$ # Generate Tools\VERIFICATION.txt Get-Content .\Build\Chocolatey\verification.txt.template | Out-File -encoding UTF8 .\Build\Chocolatey\gsudo\Tools\VERIFICATION.txt -(Get-Content Build\Nuget\gsudo.nuspec.template) -replace '#VERSION#', "$version" | Out-File -encoding UTF8 .\Build\Nuget\gsudo.nuspec - "- Calculating Hashes " @" @@ -50,11 +47,7 @@ Get-childitem *.bak -Recurse | Remove-Item mkdir Artifacts\Chocolatey -Force > $null & choco pack .\Build\Chocolatey\gsudo\gsudo.nuspec -outdir="$((get-item Artifacts\Chocolatey).FullName)" || $(throw "Choco pack failed.") -"- Packing v$version to nuget" -mkdir Artifacts\Nuget -Force > $null -& nuget pack .\Build\Nuget\gsudo.nuspec -OutputDirectory "$((get-item Artifacts\Nuget).FullName)" || $(throw "Nuget pack failed.") - -"- Testing choco package" +"- Testing package" if (choco list -lo | Where-object { $_.StartsWith("gsudo") }) { choco upgrade gsudo --failonstderr -s Artifacts\Chocolatey -f -pre --confirm || $(throw "Choco upgrade failed.") } else { @@ -64,8 +57,7 @@ if (choco list -lo | Where-object { $_.StartsWith("gsudo") }) { if($(choco apikey).Count -lt 2) { throw "Missing Chocolatey ApiKey. Use: choco apikey -k -s https://push.chocolatey.org/" } "`n- Uploading v$version to chocolatey" -:: choco push artifacts\Chocolatey\gsudo.$($version).nupkg || $(throw "Choco push failed.") - +choco push artifacts\Chocolatey\gsudo.$($version).nupkg || $(throw "Choco push failed.") "- Success" popd \ No newline at end of file diff --git a/build/06-release-Nuget.ps1 b/build/06-release-Nuget.ps1 new file mode 100644 index 00000000..87895be9 --- /dev/null +++ b/build/06-release-Nuget.ps1 @@ -0,0 +1,32 @@ +pushd $PSScriptRoot\.. + +Get-Item .\artifacts\x64\gsudo.exe > $null || $(throw "Missing binaries/artifacts") + +if ($env:version) { + "- Getting version from env:version" + $version = $env:version + $version_MajorMinorPatch=$env:version_MajorMinorPatch +} else { + "- Getting version using GitVersion" + $version = $(gitversion /showvariable LegacySemVer) + $version_MajorMinorPatch=$(gitversion /showvariable MajorMinorPatch) +} +"- Using version number v$version / v$version_MajorMinorPatch" + +"- Cleaning Nuget template folder" +git clean .\Build\Nuget\gsudo -xf + +"- Generate gsudo.nuspec" +(Get-Content Build\Nuget\gsudo.nuspec.template) -replace '#VERSION#', "$version" | Out-File -encoding UTF8 .\Build\Nuget\gsudo.nuspec + + +"- Packing v$version to nuget" +mkdir Artifacts\Nuget -Force > $null +& nuget pack .\Build\Nuget\gsudo.nuspec -OutputDirectory "$((get-item Artifacts\Nuget).FullName)" || $(throw "Nuget pack failed.") + +"`n- Uploading v$version to Nuget" +nuget push artifacts\nuget\gsudo.$($version).nupkg -Source https://api.nuget.org/v3/index.json || $(throw "Nuget push failed.") + + +"- Success" +popd \ No newline at end of file diff --git a/build/06-release-Scoop.ps1 b/build/06-release-Scoop.ps1 deleted file mode 100644 index 8d1c8b69..00000000 --- a/build/06-release-Scoop.ps1 +++ /dev/null @@ -1 +0,0 @@ - From 01ab586a03946ff3cc192dc7be37bd47a452375b Mon Sep 17 00:00:00 2001 From: Gerardo Grignoli Date: Fri, 17 Feb 2023 17:23:05 -0300 Subject: [PATCH 4/9] Re added net46-anycpu build/01-build.ps1 --- build/01-build.ps1 | 4 +++- build/03-sign.ps1 | 2 ++ build/04-release-GitHub.ps1 | 2 +- build/Nuget/gsudo.nuspec.template | 3 ++- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/build/01-build.ps1 b/build/01-build.ps1 index 9e6526f9..286036fc 100644 --- a/build/01-build.ps1 +++ b/build/01-build.ps1 @@ -7,9 +7,11 @@ dotnet publish .\src\gsudo\gsudo.csproj -c Release -o .\artifacts\arm64 -f net7 dotnet publish .\src\gsudo\gsudo.csproj -c Release -o .\artifacts\x64 -f net7.0 -r win-x64 --sc -p:PublishAot=true -p:IlcOptimizationPreference=Size -v minimal -p:WarningLevel=0 || $(exit $LASTEXITCODE) "-- Building net7.0 win-x86" dotnet publish .\src\gsudo\gsudo.csproj -c Release -o .\artifacts\x86 -f net7.0 -r win-x86 --sc -p:PublishReadyToRun=true -p:PublishSingleFile=true -v minimal -p:WarningLevel=0 || $(exit $LASTEXITCODE) - +"-- Building net4.6 AnyCpu" +dotnet publish .\src\gsudo\gsudo.csproj -c Release -o .\artifacts\net46-AnyCpu\unmerged -f net46 -p:Platform=AnyCpu -v minimal -p:WarningLevel=0 || $(exit $LASTEXITCODE) cp .\src\gsudo.Wrappers\* .\artifacts\x86 cp .\src\gsudo.Wrappers\* .\artifacts\x64 cp .\src\gsudo.Wrappers\* .\artifacts\arm64 +cp .\src\gsudo.Wrappers\* .\artifacts\net46-AnyCpu popd \ No newline at end of file diff --git a/build/03-sign.ps1 b/build/03-sign.ps1 index 801cc942..948e1e3b 100644 --- a/build/03-sign.ps1 +++ b/build/03-sign.ps1 @@ -30,6 +30,8 @@ $files = @( "artifacts\x64\*.p*1" "artifacts\x86\*.exe", "artifacts\x86\*.p*1", +"artifacts\net46-AnyCpu\*.exe", +"artifacts\net46-AnyCpu\*.p*1", "artifacts\arm64\*.exe", "artifacts\arm64\*.p*1" ) -join " " diff --git a/build/04-release-GitHub.ps1 b/build/04-release-GitHub.ps1 index 86f469e0..efa19834 100644 --- a/build/04-release-GitHub.ps1 +++ b/build/04-release-GitHub.ps1 @@ -16,7 +16,7 @@ if ($env:version) { Get-ChildItem .\artifacts\ -File | Remove-Item # Remove files on artifacts root Get-ChildItem .\artifacts\ -Filter *.pdb -Recurse | Remove-Item # Remove *.pdb on subfolders -Compress-Archive -Path ./artifacts/x86,./artifacts/x64,./artifacts/arm64 -DestinationPath "artifacts/gsudo.v$($version).zip" -force -CompressionLevel Optimal +Compress-Archive -Path ./artifacts/x86,./artifacts/x64,./artifacts/arm64,./artifacts/net46-AnyCpu -DestinationPath "artifacts/gsudo.v$($version).zip" -force -CompressionLevel Optimal (Get-FileHash artifacts\gsudo.v$($version).zip).hash > artifacts\gsudo.v$($version).zip.sha256 $msbuild = &"${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -prerelease -products * -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe diff --git a/build/Nuget/gsudo.nuspec.template b/build/Nuget/gsudo.nuspec.template index 5bd21a2c..55fe298c 100644 --- a/build/Nuget/gsudo.nuspec.template +++ b/build/Nuget/gsudo.nuspec.template @@ -50,6 +50,7 @@ Examples - + + From 0d34315c341c86b8473864067f2e4b5d90b3ecb0 Mon Sep 17 00:00:00 2001 From: Gerardo Grignoli Date: Fri, 17 Feb 2023 19:02:41 -0300 Subject: [PATCH 5/9] gsudo nuget package --- build/00-prerequisites.ps1 | 4 ++-- build/Nuget/gsudo.nuspec.template | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/build/00-prerequisites.ps1 b/build/00-prerequisites.ps1 index bd4bffef..dc24a59a 100644 --- a/build/00-prerequisites.ps1 +++ b/build/00-prerequisites.ps1 @@ -2,5 +2,5 @@ choco install ilmerge choco install GitVersion.Portable choco install wixtoolset choco install hub -choco install dotnet-7.0-sdk --pre - +choco install dotnet-7.0-sdk +choco install NuGet.CommandLine \ No newline at end of file diff --git a/build/Nuget/gsudo.nuspec.template b/build/Nuget/gsudo.nuspec.template index 55fe298c..22dced05 100644 --- a/build/Nuget/gsudo.nuspec.template +++ b/build/Nuget/gsudo.nuspec.template @@ -44,13 +44,13 @@ Examples http://github.com/gerardog/gsudo/releases/v#VERSION# - + - - - - + + + + From 3c9c563154fe8687c12a199e4b6231115619af59 Mon Sep 17 00:00:00 2001 From: Gerardo Grignoli Date: Fri, 17 Feb 2023 19:37:29 -0300 Subject: [PATCH 6/9] Replaced deprecated ilmerge with il-repack. --- .github/workflows/ci.yml | 2 +- build/00-prerequisites.ps1 | 2 +- build/01-build.ps1 | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fd708d87..9e940a5d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,7 +70,7 @@ jobs: with: fetch-depth: 0 - name: Install dependencies - run: choco install GitVersion.Portable ilmerge --confirm --no-progress + run: choco install GitVersion.Portable ilmerge il-repack --confirm --no-progress - name: Update project version run: gitversion /l console /output buildserver /updateAssemblyInfo /verbosity minimal - name: Get project version diff --git a/build/00-prerequisites.ps1 b/build/00-prerequisites.ps1 index dc24a59a..7b7a6477 100644 --- a/build/00-prerequisites.ps1 +++ b/build/00-prerequisites.ps1 @@ -1,4 +1,4 @@ -choco install ilmerge +choco install il-repack choco install GitVersion.Portable choco install wixtoolset choco install hub diff --git a/build/01-build.ps1 b/build/01-build.ps1 index 286036fc..1c5b60ba 100644 --- a/build/01-build.ps1 +++ b/build/01-build.ps1 @@ -9,6 +9,16 @@ dotnet publish .\src\gsudo\gsudo.csproj -c Release -o .\artifacts\x64 -f net7 dotnet publish .\src\gsudo\gsudo.csproj -c Release -o .\artifacts\x86 -f net7.0 -r win-x86 --sc -p:PublishReadyToRun=true -p:PublishSingleFile=true -v minimal -p:WarningLevel=0 || $(exit $LASTEXITCODE) "-- Building net4.6 AnyCpu" dotnet publish .\src\gsudo\gsudo.csproj -c Release -o .\artifacts\net46-AnyCpu\unmerged -f net46 -p:Platform=AnyCpu -v minimal -p:WarningLevel=0 || $(exit $LASTEXITCODE) + +"-- Repacking net4.6 AnyCpu into a single EXE" + +ilrepack .\artifacts\net46-AnyCpu\unmerged\gsudo.exe .\artifacts\net46-AnyCpu\unmerged\*.dll /out:.\artifacts\net46-AnyCpu\gsudo.exe /target:exe /targetplatform:v4 /ndebug /wildcards || $(exit $LASTEXITCODE) + +if ($?) { + rm artifacts\net46-AnyCpu\unmerged -Recurse + echo "artifacts\net46-AnyCpu\unmerged -> ilmerge -> artifacts\net46-AnyCpu\" +} + cp .\src\gsudo.Wrappers\* .\artifacts\x86 cp .\src\gsudo.Wrappers\* .\artifacts\x64 cp .\src\gsudo.Wrappers\* .\artifacts\arm64 From cdbd385fc604752359e15f70b1739c0652474d28 Mon Sep 17 00:00:00 2001 From: Gerardo Grignoli Date: Fri, 17 Feb 2023 20:07:28 -0300 Subject: [PATCH 7/9] Workaround for GitTools/GitVersion#3351 --- .github/workflows/ci.yml | 2 +- .github/workflows/release.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9e940a5d..950471f5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,7 +70,7 @@ jobs: with: fetch-depth: 0 - name: Install dependencies - run: choco install GitVersion.Portable ilmerge il-repack --confirm --no-progress + run: choco install GitVersion.Portable --version 5.6.11 --confirm --no-progress; choco install il-repack --confirm --no-progress - name: Update project version run: gitversion /l console /output buildserver /updateAssemblyInfo /verbosity minimal - name: Get project version diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 25a12b68..47eeaeb8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -30,7 +30,7 @@ jobs: contents: write steps: - name: Install dependencies - run: choco install NuGet.CommandLine GitVersion.Portable wixtoolset --confirm --no-progress + run: choco install GitVersion.Portable --version 5.6.11 --confirm --no-progress; choco install NuGet.CommandLine GitVersion.Portable wixtoolset --confirm --no-progress - uses: actions/checkout@v2 with: fetch-depth: 0 From 34fd69ec015fcb395b1aedbcb1f6fd2ca6469704 Mon Sep 17 00:00:00 2001 From: Gerardo Grignoli Date: Mon, 20 Feb 2023 08:34:33 -0300 Subject: [PATCH 8/9] Switched to nuget project as suggested by @awakecoding --- build/06-release-Nuget.ps1 | 8 +--- build/Nuget/gsudo.csproj | 36 ++++++++++++++++++ build/Nuget/gsudo.nuspec.template | 56 ---------------------------- build/Nuget/gsudo.targets | 33 ++++++++++++++++ src/gsudo.Wrappers/gsudoModule.psm1 | 58 +++++++++++++++++++++++++++++ 5 files changed, 129 insertions(+), 62 deletions(-) create mode 100644 build/Nuget/gsudo.csproj delete mode 100644 build/Nuget/gsudo.nuspec.template create mode 100644 build/Nuget/gsudo.targets diff --git a/build/06-release-Nuget.ps1 b/build/06-release-Nuget.ps1 index 87895be9..ccb822f1 100644 --- a/build/06-release-Nuget.ps1 +++ b/build/06-release-Nuget.ps1 @@ -16,15 +16,11 @@ if ($env:version) { "- Cleaning Nuget template folder" git clean .\Build\Nuget\gsudo -xf -"- Generate gsudo.nuspec" -(Get-Content Build\Nuget\gsudo.nuspec.template) -replace '#VERSION#', "$version" | Out-File -encoding UTF8 .\Build\Nuget\gsudo.nuspec - - "- Packing v$version to nuget" -mkdir Artifacts\Nuget -Force > $null -& nuget pack .\Build\Nuget\gsudo.nuspec -OutputDirectory "$((get-item Artifacts\Nuget).FullName)" || $(throw "Nuget pack failed.") +dotnet build .\Build\Nuget\gsudo.csproj /p:Version=$version -o artifacts\Nuget || $(throw "Nuget pack failed.") "`n- Uploading v$version to Nuget" +gi "artifacts\nuget\gsudo.$($version).nupkg" || $(throw "Nuget push failed.") nuget push artifacts\nuget\gsudo.$($version).nupkg -Source https://api.nuget.org/v3/index.json || $(throw "Nuget push failed.") diff --git a/build/Nuget/gsudo.csproj b/build/Nuget/gsudo.csproj new file mode 100644 index 00000000..13387ea0 --- /dev/null +++ b/build/Nuget/gsudo.csproj @@ -0,0 +1,36 @@ + + + + 1.0.0.0 + GerardoGrignoli + GerardoGrignoli + gsudo + gsudo + gsudo;sudo;runas + gsudo + netstandard2.0 + true + false + false + true + false + true + + + + + runtimes\win-anycpu\native\gsudo.exe + + + runtimes\win-x86\native\gsudo.exe + + + runtimes\win-x64\native\gsudo.exe + + + runtimes\win-arm64\native\gsudo.exe + + + + + diff --git a/build/Nuget/gsudo.nuspec.template b/build/Nuget/gsudo.nuspec.template deleted file mode 100644 index 22dced05..00000000 --- a/build/Nuget/gsudo.nuspec.template +++ /dev/null @@ -1,56 +0,0 @@ - - - - - - - - - gsudo - - - - #VERSION# - Gerardo Grignoli - - - - - gsudo - a sudo for windows - Gerardo Grignoli & GitHub contributors - - - 2023 Gerardo Grignoli - https://opensource.org/licenses/MIT - -`gsudo` allows to run commands with elevated permissions within the current console. -It is a `sudo` equivalent for Windows, with a similar user-experience as the original *nix sudo. - -Elevated commands are shown in the caller (non-elevated) console, no switching to another console required. - -http://github.com/gerardog/gsudo - -### Usage - -```gsudo [command] [arguments]``` -Executes the specified command, elevated, and returns. - -Examples - -```gsudo notepad c:\Windows\System32\drivers\etc\hosts``` -```gsudo cmd``` - - - http://github.com/gerardog/gsudo/releases/v#VERSION# - - - - - - - - - - - - diff --git a/build/Nuget/gsudo.targets b/build/Nuget/gsudo.targets new file mode 100644 index 00000000..e53270e4 --- /dev/null +++ b/build/Nuget/gsudo.targets @@ -0,0 +1,33 @@ + + + + + gsudo.exe + PreserveNewest + Included + false + false + + + runtimes\win-x86\native\gsudo.exe + PreserveNewest + Included + false + false + + + runtimes\win-x64\native\gsudo.exe + PreserveNewest + Included + false + false + + + runtimes\win-arm64\native\gsudo.exe + PreserveNewest + Included + false + false + + + \ No newline at end of file diff --git a/src/gsudo.Wrappers/gsudoModule.psm1 b/src/gsudo.Wrappers/gsudoModule.psm1 index d5dc4b1e..514c3a88 100644 --- a/src/gsudo.Wrappers/gsudoModule.psm1 +++ b/src/gsudo.Wrappers/gsudoModule.psm1 @@ -4,6 +4,64 @@ $c += "}" iex ($c -join "`n" | Out-String) function gsudo { +<# +.SYNOPSIS +Runs a command/scriptblock with elevated permissions. If no command is specified, it starts an elevated Powershell session. + +.DESCRIPTION +This function will attempt to retrieve a matching registry key for an +already installed application, usually to be used with a +chocolateyUninstall.ps1 automation script. + +The function also prevents `Get-ItemProperty` from failing when +handling wrongly encoded registry keys. + +.NOTES +Available in 0.9.10+. If you need to maintain compatibility with pre +0.9.10, please add the following to your nuspec (check for minimum +version): + +~~~xml + + + +~~~ + +.INPUTS +String + +.OUTPUTS +This function searches registry objects and returns an array +of PSCustomObject with the matched key's properties. + +Retrieve properties with dot notation, for example: +`$key.UninstallString` + +.EXAMPLE +> +# Version match: Software name is "Gpg4Win (2.3.0)" +[array]$key = Get-UninstallRegistryKey -SoftwareName "Gpg4win (*)" +$key.UninstallString + +.EXAMPLE +> +# Fuzzy match: Software name is "Launchy 2.5" +[array]$key = Get-UninstallRegistryKey -SoftwareName "Launchy*" +$key.UninstallString + +.EXAMPLE +> +# Exact match: Software name in Programs and Features is "VLC media player" +[array]$key = Get-UninstallRegistryKey -SoftwareName "VLC media player" +$key.UninstallString + +.EXAMPLE +> +# Elevate your current shell +gsudo + +#> + $invocationLine = $MyInvocation.Line -replace "^$($MyInvocation.InvocationName)\s+" # -replace '"','""' if ($invocationLine -match "(^| )!!( |$)") From 2b5aa58072b4e8c460d4fc23a12d805c9bff5a3f Mon Sep 17 00:00:00 2001 From: Gerardo Grignoli Date: Mon, 20 Feb 2023 08:39:36 -0300 Subject: [PATCH 9/9] Fix pkg description --- build/Nuget/gsudo.csproj | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/build/Nuget/gsudo.csproj b/build/Nuget/gsudo.csproj index 13387ea0..442ef354 100644 --- a/build/Nuget/gsudo.csproj +++ b/build/Nuget/gsudo.csproj @@ -2,12 +2,11 @@ 1.0.0.0 - GerardoGrignoli - GerardoGrignoli - gsudo + Gerardo Grignoli + Gerardo Grignoli gsudo gsudo;sudo;runas - gsudo + gsudo is a sudo for Windows, allows to run commands with elevated permissions in the current console. netstandard2.0 true false @@ -15,6 +14,11 @@ true false true + Gerardo Grignoli and GitHub Contributors + MIT + https://github.com/gerardog/gsudo + https://github.com/gerardog/gsudo + GIT