Skip to content

Commit

Permalink
Switched to nuget project as suggested by @awakecoding
Browse files Browse the repository at this point in the history
  • Loading branch information
gerardog committed Feb 20, 2023
1 parent cdbd385 commit 34fd69e
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 62 deletions.
8 changes: 2 additions & 6 deletions build/06-release-Nuget.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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.")


Expand Down
36 changes: 36 additions & 0 deletions build/Nuget/gsudo.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk" DefaultTargets="Pack">

<PropertyGroup>
<Version>1.0.0.0</Version>
<Company>GerardoGrignoli</Company>
<Authors>GerardoGrignoli</Authors>
<Description>gsudo</Description>
<PackageId>gsudo</PackageId>
<PackageTags>gsudo;sudo;runas</PackageTags>
<Description>gsudo</Description>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<NoBuild>true</NoBuild>
<IncludeBuildOutput>false</IncludeBuildOutput>
<IncludeSymbols>false</IncludeSymbols>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackFrameworkReferences>false</PackFrameworkReferences>
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
</PropertyGroup>

<ItemGroup>
<Content Include="$(MSBuildThisFileDirectory)\..\..\artifacts\net46-AnyCpu\gsudo.exe" Pack="true">
<PackagePath>runtimes\win-anycpu\native\gsudo.exe</PackagePath>
</Content>
<Content Include="$(MSBuildThisFileDirectory)\..\..\artifacts\x86\gsudo.exe" Pack="true">
<PackagePath>runtimes\win-x86\native\gsudo.exe</PackagePath>
</Content>
<Content Include="$(MSBuildThisFileDirectory)\..\..\artifacts\x64\gsudo.exe" Pack="true">
<PackagePath>runtimes\win-x64\native\gsudo.exe</PackagePath>
</Content>
<Content Include="$(MSBuildThisFileDirectory)\..\..\artifacts\arm64\gsudo.exe" Pack="true">
<PackagePath>runtimes\win-arm64\native\gsudo.exe</PackagePath>
</Content>
<Content Include="gsudo.targets" PackagePath="build/gsudo.targets" Pack="true" />
</ItemGroup>

</Project>
56 changes: 0 additions & 56 deletions build/Nuget/gsudo.nuspec.template

This file was deleted.

33 changes: 33 additions & 0 deletions build/Nuget/gsudo.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Content Include="$(MSBuildThisFileDirectory)\..\runtimes\win-anycpu\native\gsudo.exe">
<Link>gsudo.exe</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
<Pack>false</Pack>
</Content>
<Content Include="$(MSBuildThisFileDirectory)\..\runtimes\win-x86\native\gsudo.exe">
<Link>runtimes\win-x86\native\gsudo.exe</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
<Pack>false</Pack>
</Content>
<Content Include="$(MSBuildThisFileDirectory)\..\runtimes\win-x64\native\gsudo.exe">
<Link>runtimes\win-x64\native\gsudo.exe</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
<Pack>false</Pack>
</Content>
<Content Include="$(MSBuildThisFileDirectory)\..\runtimes\win-arm64\native\gsudo.exe">
<Link>runtimes\win-arm64\native\gsudo.exe</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
<Pack>false</Pack>
</Content>
</ItemGroup>
</Project>
58 changes: 58 additions & 0 deletions src/gsudo.Wrappers/gsudoModule.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
<dependencies>
<dependency id="chocolatey-core.extension" version="1.1.0" />
</dependencies>
~~~
.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 "(^| )!!( |$)")
Expand Down

0 comments on commit 34fd69e

Please sign in to comment.