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 "(^| )!!( |$)")