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

Fixed self-building process #5111

Merged
merged 2 commits into from
Feb 23, 2019
Merged
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
45 changes: 23 additions & 22 deletions bin/build-project.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ param (
[string]$ProjectPath = (Resolve-Path -Path (Join-Path -Path $PSModuleRoot -ChildPath 'bin\projects\dbatools\dbatools.sln')),
[ValidateSet('ps3', 'ps4', 'Release', 'Debug')]
[string]$MsbuildConfiguration = "Release",
[string]$MsbuildOptions = "",
[Parameter(HelpMessage = 'Target to run instead of build')]
[string]$MsbuildTarget = 'Build'
[string]$MsbuildTarget = 'Build',
[string]$DllRoot = $script:DllRoot,
[string]$LibraryBase = (Join-Path $PSModuleRoot "bin")
)

if (-not $PSBoundParameters.ContainsKey('MsbuildConfiguration')) {
Expand All @@ -24,53 +25,53 @@ if (-not $PSBoundParameters.ContainsKey('MsbuildConfiguration')) {
$_MsbuildConfiguration = $MsbuildConfiguration
}

function Get-MsBuildPath {
function Get-DotNetPath {
[CmdletBinding()]
[OutputType([string])]
param ()
process {
$rawPath = "$(Split-Path ([string].Assembly.Location))\msbuild.exe"
(Resolve-Path $rawPath).Path
if (Get-Command dotnet.exe -CommandType Application -ErrorAction SilentlyContinue) { return (Get-Command dotnet.exe -CommandType Application).Source }
"$($env:ProgramFiles)\dotnet\dotnet.exe"
}
}

$start = Get-Date
$msbuild = Get-MsBuildPath
$dotnet = Get-DotNetPath

if (-not (Test-Path $msbuild)) {
throw "msbuild not found, cannot compile library! Check your .NET installation health, then try again. Path checked: $msbuild"
if (-not (Test-Path $dotnet)) {
throw "dotnet application not found, cannot compile library! Download and install the dotnet SDK from https://dotnet.microsoft.com/download"
}

if ($env:APPVEYOR -eq 'True') {
$MsbuildOptions = $MsbuildOptions + '/logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" '
$_MsbuildConfiguration = 'Debug'

if (-not (Test-Path "C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll")) {
throw "msbuild logger not found, cannot compile library! Check your .NET installation health, then try again. Path checked: $msbuild"
}
}

#$MsbuildOptions = $MsbuildOptions + '/logger:BinaryLogger,"{0}";"{1}" ' -f (Join-Path $PSScriptRoot 'StructuredLogger.dll'), (Resolve-Path '..\msbuild.bin.log').Path

if (-not (Test-Path $ProjectPath)) {
throw new-object 'System.IO.FileNotFoundException' 'Could not file project or solution', $ProjectPath
}

Write-Verbose -Message "Building the library with command $msbuild $ProjectPath /p:Configuration=$_MsbuildConfiguration $MsbuildOptions /t:$MsBuildTarget"
& $msbuild $ProjectPath "/p:Configuration=$_MsbuildConfiguration" $MsbuildOptions "/t:$MsBuildTarget"
Write-Verbose -Message "Building the library with command $dotnet build $ProjectPath -c $_MsbuildConfiguration"
& $dotnet build $ProjectPath -c $_MsbuildConfiguration

if ($MsbuildTarget -eq 'Build') {
if ($MsbuildTarget -eq 'Build')
{
if ($PSVersionTable.PSVersion.Major -ge 6) {
$dll = (Resolve-Path -Path "$libraryBase\netcoreapp2.1\dbatools.dll" -ErrorAction Ignore)
}
else {
$dll = (Resolve-Path -Path "$libraryBase\net452\dbatools.dll" -ErrorAction Ignore)
}
try {
Write-Verbose -Message "Found library, trying to copy & import"
if ($script:alwaysBuildLibrary) {
Move-Item -Path (Resolve-Path -Path "$PSModuleRoot\bin\dbatools.dll") -Destination $script:DllRoot -Force -ErrorAction Stop
Move-Item -Path $dll -Destination $DllRoot -Force -ErrorAction Stop
} else {
Copy-Item -Path (Resolve-Path -Path "$PSModuleRoot\bin\dbatools.dll") -Destination $script:DllRoot -Force -ErrorAction Stop
Copy-Item -Path $dll -Destination $DllRoot -Force -ErrorAction Stop
}
Add-Type -Path (Resolve-Path -Path "$PSModuleRoot\dbatools.dll") -ErrorAction Stop
Add-Type -Path (Resolve-Path -Path "$DllRoot\dbatools.dll") -ErrorAction Stop
} catch {
Write-Verbose -Message "Failed to copy & import, attempting to import straight from the module directory"
Add-Type -Path (Resolve-Path -Path "$PSModuleRoot\bin\dbatools.dll") -ErrorAction Stop
Add-Type -Path $dll -ErrorAction Stop
}
Write-Verbose -Message "Total duration: $((Get-Date) - $start)"
}
5 changes: 1 addition & 4 deletions bin/library.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,10 @@ if ($ImportLibrary) {
$hasCompiledDll = Test-Path -Path $dll -ErrorAction Stop
}

$reslibdll = Resolve-Path -Path "$libraryBase\dbatools.dll"

if ((-not $script:alwaysBuildLibrary) -and $hasCompiledDll -and ([System.Diagnostics.FileVersionInfo]::GetVersionInfo($reslibdll).FileVersion -eq $currentLibraryVersion)) {
if ((-not $script:alwaysBuildLibrary) -and $hasCompiledDll -and ([System.Diagnostics.FileVersionInfo]::GetVersionInfo($dll).FileVersion -eq $currentLibraryVersion)) {
$start = Get-Date

try {
$libraryBase = Resolve-Path -Path "$libraryBase\"
$script:DllRoot = Resolve-Path -Path $script:DllRoot
Write-Verbose -Message "Found library, trying to copy & import"
# this looks excessive but for some reason the explicit string to string is required
Expand Down