From 5af2281c473d32ede44e5842141362fa859a4d41 Mon Sep 17 00:00:00 2001 From: "ray.hayes" Date: Sat, 8 Feb 2020 12:14:59 -0400 Subject: [PATCH] Updated installer script for new release --- Make-Installer.ps1 | 120 -------------------------- New-Installer.ps1 | 195 ++++++++++++++++++++++++++++++++++++++++++ SharedAssemblyInfo.cs | 8 +- 3 files changed, 199 insertions(+), 124 deletions(-) delete mode 100644 Make-Installer.ps1 create mode 100644 New-Installer.ps1 diff --git a/Make-Installer.ps1 b/Make-Installer.ps1 deleted file mode 100644 index 0810d6e9..00000000 --- a/Make-Installer.ps1 +++ /dev/null @@ -1,120 +0,0 @@ -function Get-MsBuildCommand() { - - $findCommand = Get-Command msbuild -ErrorAction SilentlyContinue - if ( $findCommand -ne $null ) { - return "msbuild" - } - - # Since VS2017, there is a bundled command called vswhere - # - vswhere is included with the installer as of Visual Studio 2017 version 15.2 and later, - # and can be found at the following location: - # %ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe - $vsWhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" - - if ( (Get-Command $vsWhere -ErrorAction SilentlyContinue) -eq $null) { - Write-Error "Unable to find 'vswhere'" - } - else { - $vspath = & $vsWhere -latest -products * -requires Microsoft.Component.MSBuild -property installationPath - if ($vspath) { - $msbuild = join-path $vspath 'MSBuild\15.0\Bin\MSBuild.exe' - - if ( Test-Path $msbuild ) { - return $msbuild - } else { - Write-Error "Should be located at $msbuild but Test-Path failed" - } - } - } - - return $null; -} - -function Get-NugetCommand() { - $findCommand = Get-Command nuget -ErrorAction SilentlyContinue - if ( $findCommand -ne $null ) { - return "nuget" - } - - # $installedNuget = ".\packages\NuGet.CommandLine.4.6.2\tools\NuGet.exe" - $installedNuget = (Get-ChildItem -Path .\packages\ -Recurse -Include NuGet.exe | Select-Object -First 1) - if ( Test-Path $installedNuget ) { - return $installedNuget - } else { - return $null; - } -} - -function Get-SquirrelCommand() { - $findCommand = Get-Command squirrel.exe -ErrorAction SilentlyContinue - if ( $findCommand -ne $null ) { - return "squirrel.exe" - } - - $squirrel = (Get-ChildItem -Path .\packages\ -Recurse -Include squirrel.exe | Select-Object -First 1) - if ( Test-Path $squirrel ) { - return $squirrel - } else { - return $null; - } -} - -$msbuild = Get-MsBuildCommand -if ( $msbuild -eq $null ) { - Write-Error "Unable to locate MSBuild" - Exit -} - -$nuget = Get-NugetCommand -if ( $nuget -eq $null ) { - Write-Error "Unable to locate Nuget" - Exit -} - -$squirrel = Get-SquirrelCommand -if ( $squirrel -eq $null ) { - Write-Error "Unable to locate Squirrel" - Exit -} - -Write-Output "MSBuild = $msbuild" -Write-Output "Nuget = $nuget" -Write-Output "Squirrel = $squirrel" - -$solutionFile = "Sentinel.sln" -$nuspecFile = "Sentinel.nuspec" - -$buildConfiguration = "Release" - -& $msbuild /t:Clean /p:Configuration=$buildConfiguration $solutionFile -& $msbuild /t:Build /p:Configuration=$buildConfiguration $solutionFile - -if ($LASTEXITCODE -eq 0) { - $basePath = "Sentinel\Bin\$buildConfiguration" - $application = "$basePath\Sentinel.exe" - $version = (get-item $application).VersionInfo.ProductVersion - Write-Output "Packaging up $application [$version]" - - & $nuget pack $nuspecFile -Version $version -BasePath $basePath - - $package = "Sentinel.$version.nupkg" - if ( Test-Path $package ) { - Write-Output "Packed into $package" - $releasesLocation = "Releases" - - # Squirrel doesn't wait, so cheat by pipelining it with | Write-Output - # See https://github.com/Squirrel/Squirrel.Windows/issues/489 - & $squirrel --releasify $package --no-msi --releaseDir=$releasesLocation | Write-Output - - if ( $LASTEXITCODE -eq 0) { - # Give the installer a sensible name - Move-Item (Join-Path $releasesLocation "setup.exe") ` - (Join-Path $releasesLocation "Sentinel-Setup-$version.exe") ` - -Force - } - } else { - Write-Error "Problem creating package" - } -} else { - Write-Error "Failed to build!" -} \ No newline at end of file diff --git a/New-Installer.ps1 b/New-Installer.ps1 new file mode 100644 index 00000000..8ae3a2ce --- /dev/null +++ b/New-Installer.ps1 @@ -0,0 +1,195 @@ +<# +.SYNOPSIS + New Installer generator +.DESCRIPTION + Makes a new installer for the current code +.EXAMPLE + New-Installer +.EXAMPLE + New-Installer --NoCompile --NoVersionUpdate +.INPUTS + None +.OUTPUTS + Installers should be generated in the Releases folder +.NOTES + +.COMPONENT + NCCIS Checker +.ROLE + Installer generator +.FUNCTIONALITY + Installer generator +#> +[CmdletBinding()] +param ( + [Alias("b")] + [Switch] + $NoBuild = $false, + + [Alias("v")] + [Switch] + $NoVersionUpdate = $false +) + +function Get-MsBuildCommand() { + + Write-Verbose "Get-MsBuildCommand()" + + $findCommand = Get-Command msbuild -ErrorAction SilentlyContinue + if ( $null -eq $findCommand ) { + Write-Verbose "Get-MsBuildCommand() - returning 'msbuild' due to Get-Command finding something" + return "msbuild" + } + + # Since VS2017, there is a bundled command called vswhere + # - vswhere is included with the installer as of Visual Studio 2017 version 15.2 and later, + # and can be found at the following location: + # %ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe + + Write-Verbose "Get-MsBuildCommand() - using vswhere to find" + $vsWhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" + Write-Verbose "Get-MsBuildCommand() - looking for vswhere at $vsWhere" + + if ( $null -eq (Get-Command $vsWhere -ErrorAction SilentlyContinue) ) { + Write-Error "Unable to find 'vswhere'" + } + else { + $msbuild = & $vswhere -latest -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe | select-object -first 1 + + if ( Test-Path $msbuild ) { + Write-Verbose "Get-MsBuildCommand() - found at $msbuild" + return $msbuild + } + else { + Write-Error "Should be located at $msbuild but Test-Path failed" + } + } + + Write-Verbose "Get-MsBuildCommand() - giving up and returning $null" + return $null; +} + +function Get-NugetCommand() { + $findCommand = Get-Command nuget -ErrorAction SilentlyContinue + if ( $null -ne $findCommand ) { + return "nuget" + } + + # $installedNuget = ".\packages\NuGet.CommandLine.4.6.2\tools\NuGet.exe" + $installedNuget = (Get-ChildItem -Path .\packages\ -Recurse -Include NuGet.exe | Select-Object -First 1) + if ( Test-Path $installedNuget ) { + return $installedNuget + } + else { + return $null; + } +} + +function Get-SquirrelCommand() { + $findCommand = Get-Command squirrel.exe -ErrorAction SilentlyContinue + if ( $null -ne $findCommand ) { + return "squirrel.exe" + } + + $squirrel = (Get-ChildItem -Path .\packages\ -Recurse -Include squirrel.exe | Select-Object -First 1) + if ( Test-Path $squirrel ) { + return $squirrel + } + else { + return $null; + } +} + +$msbuild = Get-MsBuildCommand +if ( $null -eq $msbuild ) { + Write-Error "Unable to locate MSBuild" + Exit +} + +$nuget = Get-NugetCommand +if ( $null -eq $nuget ) { + Write-Error "Unable to locate Nuget" + Exit +} + +Write-Output "MSBuild = $msbuild" +Write-Output "Nuget = $nuget" + +# Restore any packages +& $nuget restore + +# Look for locations of things that may have required nuget restore to download +$squirrel = Get-SquirrelCommand +if ( $null -eq $squirrel ) { + Write-Error "Unable to locate Squirrel" + Exit +} + +Write-Output "Squirrel = $squirrel" + +# =========================================================================== +$productName = "Sentinel" +$applicationName = "Sentinel" +$solutionFile = "Sentinel.sln" +$nuspecFile = "Sentinel.nuspec" + +$buildConfiguration = "Release" + +if ( -not $NoBuild ) { + # Build the code in release mode + & $msbuild /t:Clean /p:Configuration=$buildConfiguration $solutionFile + & $msbuild /t:Build /p:Configuration=$buildConfiguration $solutionFile + + if ($LASTEXITCODE -ne 0) { + Write-Error "Failed to build!" + Exit + } +} + +$basePath = "$applicationName\Bin\$buildConfiguration" +Write-Host "Base Path = $basePath" + +$application = "$basePath\$applicationName.exe" +Write-Host "Application = $application" + +$version = (get-item $application).VersionInfo.FileVersion +Write-Debug (get-item $application).VersionInfo + +# See whether there is a symver truncation of version +Write-Verbose "Determining version" +$symver = $version -replace '(\d+)\.(\d+)\.(\d+)\.(\d+)', '$1.$2.$3' +if ( $symver -ne $version ) { + Write-Information "SymVer version being used: $($version) -> $($symver)" + $version = $symver +} + +Write-Verbose "Creating Nuget package to contain installation content" +Write-Output "Packaging up $application [$version]" +& $nuget pack -NoPackageAnalysis $nuspecFile -Version $version -BasePath $basePath +$package = "$productName.$version.nupkg" + +if ( Test-Path $package ) { + Write-Verbose "Processing nuget package: $package" + Write-Output "Packed into $package" + $releasesLocation = "Releases" + + # Squirrel doesn't wait, so cheat by pipelining it with | Write-Output + # See https://github.com/Squirrel/Squirrel.Windows/issues/489 + Write-Verbose "Involking Squirrel" + & $squirrel --releasify $package --no-msi --releaseDir=$releasesLocation | Write-Output + + if ( $LASTEXITCODE -eq 0) { + $srcFile = Join-Path $releasesLocation "setup.exe" + $destFile = Join-Path $releasesLocation "$($productName)-Setup-$version.exe" + Write-Verbose "Renaming output file: src: $srcFile dest: $destFile" + + # Give the installer a sensible name + Move-Item $srcFile $destFile -Force + } else { + Write-Error "Failed to write package" + } +} +else { + Write-Output "File $($package) not found" + Write-Error "Problem creating package" +} diff --git a/SharedAssemblyInfo.cs b/SharedAssemblyInfo.cs index dcfaa307..1b1b87db 100644 --- a/SharedAssemblyInfo.cs +++ b/SharedAssemblyInfo.cs @@ -2,13 +2,13 @@ using System.Reflection; using System.Resources; -[assembly: AssemblyVersion("0.13.4")] -[assembly: AssemblyFileVersion("0.13.4")] +[assembly: AssemblyVersion("0.13.5")] +[assembly: AssemblyFileVersion("0.13.5")] // Ensure all assemblies have a neutral language defined. [assembly: NeutralResourcesLanguage("en")] -// Addres CA1014 issues +// Address CA1014 issues [assembly: CLSCompliant(true)] -[assembly: AssemblyCopyright("Copyright � Ray Hayes 2009-2018")] +[assembly: AssemblyCopyright("Copyright � Ray Hayes 2009-2020")]