Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use .NET 8.0 #367

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@ jobs:
permissions:
id-token: write
contents: read
checks: write
checks: write
steps:
- uses: actions/setup-dotnet@v2
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '7.0.x'
include-prerelease: true
dotnet-version: '8.0.x'
- uses: actions/checkout@v2
with:
fetch-depth: 0
with:
fetch-depth: 0
- name: Run Tests
id: tests
run: ./build/02-test.ps1
Expand All @@ -45,7 +44,7 @@ jobs:
if: success() || failure()
with:
name: TestsResults (dotnet)
path: "**/TestResults*.trx"
path: "**/TestResults*.trx"
reporter: dotnet-trx
fail-on-error: true
- name: Test Report PowerShell v5
Expand All @@ -68,15 +67,14 @@ jobs:
name: Build
runs-on: windows-latest
steps:
- uses: actions/setup-dotnet@v2
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- uses: actions/checkout@v2
with:
dotnet-version: '7.0.x'
include-prerelease: true
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install dependencies
run: choco install GitVersion.Portable --version 5.6.11 --confirm --no-progress; choco install il-repack --confirm --no-progress
run: choco install GitVersion.Portable --version 5.12.0 --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
Expand Down
50 changes: 25 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

**gsudo** is a `sudo` equivalent for Windows, with a similar user-experience as the original Unix/Linux sudo.
Allows you to run a command (or re-launch your current shell) with elevated permissions, in the current console window or a new one.

Just [prepend `gsudo`](#usage) (or the `sudo` alias) to your command and it will run elevated. For PowerShell use this [syntax](#usage-from-powershell--powershell-core): `gsudo { ScriptBlock }`

One UAC popup will appear each time. You can see less popups if you enable [gsudo cache](#credentials-cache).

It detects your current shell and elevates your command as native shell commands. (Supports `Cmd`, `PowerShell`, `WSL`, `git-bash`, `MinGW`, `Cygwin`, `Yori`, `Take Command`, `BusyBox` & `NuShell`.)
It detects your current shell and elevates your command as native shell commands. (Supports `Cmd`, `PowerShell`, `WSL`, `git-bash`, `MinGW`, `Cygwin`, `Yori`, `Take Command`, `BusyBox` & `NuShell`.)

## Table of contents

Expand Down Expand Up @@ -52,7 +52,7 @@ It detects your current shell and elevates your command as native shell commands
- Supports being used on scripts:
- Outputs StdOut/StdErr can be piped or captured (e.g. `gsudo dir | findstr /c:"bytes free" > FreeSpace.txt`) and exit codes too (`%errorlevel%`). If `gsudo` fails to elevate, the exit code will be 999.
- If `gsudo` is invoked from an already elevated console, it will just run the command (it won't fail). So, you don't have to worry if you run `gsudo` or a script that uses `gsudo` from an already elevated console. (The UAC popup will not appear, as no elevation is required)

- `gsudo !!` elevates the last executed command. Works on CMD, Git-Bash, MinGW, Cygwin (and PowerShell with [gsudo module](#gsudomodule) only)

## Installation
Expand All @@ -64,11 +64,11 @@ It detects your current shell and elevates your command as native shell commands
``` PowerShell
PowerShell -Command "Set-ExecutionPolicy RemoteSigned -scope Process; [Net.ServicePointManager]::SecurityProtocol = 'Tls12'; iwr -useb https://raw.githubusercontent.com/gerardog/gsudo/master/installgsudo.ps1 | iex"
```
- Portable:
- Portable:
1. Download `gsudo.portable.zip` from the [latest release](https://github.com/gerardog/gsudo/releases/latest)
2. Extract the folder corresponding to your processor architecture (x64, x86, or arm64) from the zip file to a suitable directory on your computer.
3. Optionally, add that directory to your system's PATH environment variable if it's not already accessible.

**Please restart all your console windows** after installing to ensure that the `PATH` environment variable is refreshed.

Note: `gsudo.exe` is portable. No windows service is required or system change is done, except adding it to the Path.
Expand Down Expand Up @@ -149,10 +149,10 @@ To elevate a commands or script block: **Wrap it in {curly braces}**.

# Pass arguments with -args
$MyString = "Hello World"
gsudo { Write-Output $args[0] } -args $MyString
gsudo { Write-Output $args[0] } -args $MyString

# Output is serialized as PSObjects with properties.
$services = gsudo { Get-Service 'WSearch', 'Winmgmt'}
$services = gsudo { Get-Service 'WSearch', 'Winmgmt'}
Write-Output $services.DisplayName

# Inputs too: Example elevated iteration of a list.
Expand All @@ -167,18 +167,18 @@ Alternative syntaxes:
# Pass values (not variables by reference) by prefixing `$using:`. I.E.

$MyString = "Hello World"
Invoke-Gsudo { Write-Output $using:MyString }
Invoke-Gsudo { Write-Output $using:MyString }

# Syntax:
Invoke-Gsudo [-ScriptBlock] <ScriptBlock>
[[-ArgumentList] <Object[]>]
[-InputObject <PSObject>]
[-LoadProfile | -NoProfile]
Invoke-Gsudo [-ScriptBlock] <ScriptBlock>
[[-ArgumentList] <Object[]>]
[-InputObject <PSObject>]
[-LoadProfile | -NoProfile]
[-Credential <PSCredential>]
```

- PowerShell function.
- Performs auto serialization of inputs & outputs.
- Performs auto serialization of inputs & outputs.
- You can prefix variables with the `$using:` scope modifier (like `$using:variableName`) and their serialized value is applied.
- Use `-LoadProfile` or `-NoProfile` to override profile loading or not.
- Use `-Credential` option for Run As User (same as `-u` but for `Get-Credentials`).
Expand All @@ -187,16 +187,16 @@ Alternative syntaxes:

<details>
<summary>3. Manual string interpolation. (not recommended) </summary>
I don't recommend this approach as it is really hard to do proper escape all special characters.
I don't recommend this approach as it is really hard to do proper escape all special characters.

``` PowerShell
Usage: gsudo 'string literal'

# Variable substitutions example:
$file='C:\My Secret.txt';
$file='C:\My Secret.txt';
$algorithm='md5';
$hash = gsudo "(Get-FileHash '$file' -Algorithm $algorithm).Hash"
# or
# or
$hash = gsudo "(Get-FileHash ""$file"" -Algorithm $algorithm).Hash"
```

Expand All @@ -209,13 +209,13 @@ Alternative syntaxes:
- <a name="gsudomodule"></a> Optional: Import module `gsudoModule.psd1` into your PowerShell Profile:
- Adds syntax auto-complete to gsudo in PowerShell. Plus, it suggests the 3 previous commands, making your workflow smoother than ever!
- Enables `gsudo !!` on Powershell, to elevate the last executed command.
- Adds Functions:
- Adds Functions:
- `Test-IsGsudoCacheAvailable` Returns true if a gsudo cache is active (meaning elevation with no UAC is possible).
- `Test-IsProcessElevated`: Returns true if the current process is elevated.
- `Test-IsAdminMember`: Returns true if the current user is member of the `Local Administrators` groups, which means it can elevate with.

``` Powershell
# Add the following line to your $PROFILE
# Add the following line to your $PROFILE
Import-Module "gsudoModule"

# Or run:
Expand All @@ -224,12 +224,12 @@ Alternative syntaxes:

- If you haven't already customized your PowerShell prompt (for example by installing Oh-My-Posh), you can easily add a red `#` indicating that the current process is elevated:
![gsudo prompt](docs/static/img/gsudo-powershell-prompt.gif)

To do so add this line to your profile (after importing `gsudoModule`):

``` powershell
Set-Alias Prompt gsudoPrompt
```
```
---

### Usage from WSL (Windows Subsystem for Linux)
Expand All @@ -240,7 +240,7 @@ On WSL bash, prepend `gsudo` to elevate **WSL commands** or `gsudo -d` for **CMD

``` bash
# elevate default shell
PC:~$ gsudo
PC:~$ gsudo

# run elevated WSL command
PC:~$ gsudo mkdir /mnt/c/Windows/MyFolder
Expand Down Expand Up @@ -304,9 +304,9 @@ In any case, you can stop all cache sessions with `gsudo -k`.

When I created `gsudo`, there were other `sudo` packages on most Windows popular package managers such as `Chocolatey` and `Scoop`, so I had no other choice to pick another name. `gsudo` installers create an alias for `sudo`, so feel free to use `sudo` on your command line to invoke `gsudo`.

- Why did you migrated from `.Net Framework 4.6` to `.Net Core 7.0`?
- Why did you migrated from `.Net Framework 4.6` to `.Net 8.0`?

Starting from v1.4.0, it is built using `.Net 7.0` NativeAOT. It loads faster and uses less memory, and runs on machines without any .Net runtime installed. Prior versions `<v1.3.0` used .Net 4.6, because it was included in every Windows 10/11 installation.
Starting from v1.4.0, it is built using `.Net 8.0` NativeAOT. It loads faster and uses less memory, and runs on machines without any .Net runtime installed. Prior versions `<v1.3.0` used .Net 4.6, because it was included in every Windows 10/11 installation.

- Is `gsudo` a port of `*nix sudo`?

Expand Down
4 changes: 2 additions & 2 deletions build/00-prerequisites.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
choco install il-repack
choco install il-repack
choco install GitVersion.Portable
choco install wixtoolset
choco install hub
choco install dotnet-7.0-sdk
choco install dotnet-8.0-sdk
choco install NuGet.CommandLine
26 changes: 13 additions & 13 deletions build/01-build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ if ($env:version) {
"- Using version number v$version / v$version_MajorMinorPatch"

"-- Cleaning bin & obj folders"
Get-Item ".\src\gsudo\bin\", ".\src\gsudo\obj\" -ErrorAction Ignore | Remove-Item -Recurse -Force
"-- Building net7.0 win-arm64"
dotnet publish .\src\gsudo\gsudo.csproj -c Release -o .\artifacts\arm64 -f net7.0 -r win-arm64 --sc -p:PublishAot=true -p:IlcOptimizationPreference=Size -v minimal -p:WarningLevel=0 || $(exit $LASTEXITCODE)
"-- Building net7.0 win-x64"
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)
Get-Item ".\src\gsudo\bin\", ".\src\gsudo\obj\" -ErrorAction Ignore | Remove-Item -Recurse -Force
"-- Building net8.0 win-arm64"
dotnet publish .\src\gsudo\gsudo.csproj -c Release -o .\artifacts\arm64 -f net8.0 -r win-arm64 --sc -p:PublishAot=true -p:IlcOptimizationPreference=Size -v minimal -p:WarningLevel=0 || $(exit $LASTEXITCODE)
"-- Building net8.0 win-x64"
dotnet publish .\src\gsudo\gsudo.csproj -c Release -o .\artifacts\x64 -f net8.0 -r win-x64 --sc -p:PublishAot=true -p:IlcOptimizationPreference=Size -v minimal -p:WarningLevel=0 || $(exit $LASTEXITCODE)
"-- Building net8.0 win-x86"
dotnet publish .\src\gsudo\gsudo.csproj -c Release -o .\artifacts\x86 -f net8.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\"
}
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
Expand Down
14 changes: 7 additions & 7 deletions build/02-test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dotnet build .\src\gsudo.sln || $(exit $LASTEXITCODE)

$originalPath = $env:path

$env:path=(Get-Item .\src\gsudo.Tests\bin\Debug\net7.0\).FullName+";" + [String]::Join(";", (($ENV:Path).Split(";") -notlike "*gsudo*" | % {$_ -replace "\\$" }))
$env:path=(Get-Item .\src\gsudo.Tests\bin\Debug\net8.0\).FullName+";" + [String]::Join(";", (($ENV:Path).Split(";") -notlike "*gsudo*" | % {$_ -replace "\\$" }))

gsudo -k
gsudo --debug cache on -p 0 -d 1
Expand All @@ -25,19 +25,19 @@ if (! $?) { $failure = $true }
if ($failure) { exit 1 } # fail fast

$script = {
$ProgressPreference = "SilentlyContinue";
$ProgressPreference = "SilentlyContinue";
if ((Get-InstalledModule Pester -ErrorAction SilentlyContinue).Version -lt "5.0.0") { Install-Module Pester -Force -SkipPublisherCheck }
Import-Module Pester
Import-Module Pester

$configuration = New-PesterConfiguration;
$configuration.Run.Path = "src"
$configuration.TestResult.Enabled = $true
$configuration.TestResult.OutputPath = "TestResults_PS$($PSVersionTable.PSVersion.Major).xml"
$configuration.TestResult.OutputFormat = "JUnitXml"
# $configuration.Should.ErrorAction = 'Continue'
# $configuration.CodeCoverage.Enabled = $true
Invoke-Pester -Configuration $configuration
# $configuration.CodeCoverage.Enabled = $true

Invoke-Pester -Configuration $configuration
}

gsudo --debug cache on -p 0 -d 1
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "7.0.0",
"version": "8.0.0",
"rollForward": "latestFeature"
}
}
4 changes: 2 additions & 2 deletions src/gsudo.Tests/gsudo.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<Configurations>Debug;Release</Configurations>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\gsudo\gsudo.csproj" AdditionalProperties="TargetFramework=net7.0" />
<ProjectReference Include="..\gsudo\gsudo.csproj" AdditionalProperties="TargetFramework=net8.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.*" />
Expand Down
18 changes: 9 additions & 9 deletions src/gsudo/gsudo.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net7.0;net46</TargetFrameworks>
<TargetFrameworks>net8.0;net46</TargetFrameworks>
<SignAssembly>false</SignAssembly>
<AssemblyOriginatorKeyFile>StrongName.snk</AssemblyOriginatorKeyFile>
<Authors>Gerardo Grignoli</Authors>
Expand All @@ -25,27 +25,27 @@
<FileVersion>1.0.0.0</FileVersion>
<NoWarn>1701;1702;CA1303;CA1707;CA1028;CA1001;CA1031;CA1416</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)'=='net7.0'">
<PropertyGroup Condition="'$(TargetFramework)'=='net8.0'">
<AutoGenerateBindingRedirects>False</AutoGenerateBindingRedirects>
<PublishTrimmed>true</PublishTrimmed>
<InvariantGlobalization>true</InvariantGlobalization>
<InvariantGlobalization>true</InvariantGlobalization>
<IlcOptimizationPreference>Size</IlcOptimizationPreference>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>DEBUG</DefineConstants>
<DebugType>pdbonly</DebugType>
<DebugSymbols>true</DebugSymbols>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<Compile Remove="bin\**" />
<EmbeddedResource Remove="bin\**" />
<None Remove="bin\**" />
</ItemGroup>
<ItemGroup>
<Compile Remove="Tokens\PrivilegeManager.cs" />
<ItemGroup>
<Compile Remove="Tokens\PrivilegeManager.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Tokens\PrivilegeManager.cs" />
<ItemGroup>
<None Include="Tokens\PrivilegeManager.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="GitVersion.MsBuild" Version="5.6.11">
Expand All @@ -57,7 +57,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='net7.0'">
<ItemGroup Condition="'$(TargetFramework)'=='net8.0'">
<PackageReference Include="System.Security.Principal.Windows" Version="5.0.0" />
<PackageReference Include="System.Threading.AccessControl" Version="6.0.0" />
</ItemGroup>
Expand Down
Loading