-
Notifications
You must be signed in to change notification settings - Fork 1
/
publish.ps1
68 lines (52 loc) · 2.27 KB
/
publish.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#### Configuration
$deleteExistingFiles = $false
$configuration = "Debug"
$publishsettings = ".\publishsettings.targets"
$envSpecificConfig = ".\zzz.Sitecore.Utilities.config"
####
function Resolve-MsBuild {
$msb2017 = Resolve-Path "${env:ProgramFiles(x86)}\Microsoft Visual Studio\*\*\MSBuild\*\bin\msbuild.exe" -ErrorAction SilentlyContinue
if($msb2017) {
Write-Host "Found MSBuild 2017 (or later)."
Write-Host $msb2017
return $msb2017 | Select-Object -First 1
}
$msBuild2015 = "${env:ProgramFiles(x86)}\MSBuild\14.0\bin\msbuild.exe"
if(-not (Test-Path $msBuild2015)) {
throw 'Could not find MSBuild 2015 or later.'
}
Write-Host "Found MSBuild 2015."
Write-Host $msBuild2015
return $msb2017 | Select-Object -First 1
}
function Test-ConfigExists($configName){
if(Test-Path $configName){
$true
}else{
Write-Warning "Could not find config: '$($configName)"
Write-Warning "Make a copy of '$($currentDirectory)\$($configName).example' file. "
Write-Warning "Then remove '.example' from the file name and fill its content with your settings."
$false
}
}
$MSBuildCall = Resolve-MsBuild
if(-not (Test-ConfigExists $envSpecificConfig) -or -not(Test-ConfigExists $publishsettings)){
exit
}
[xml]$targets = Get-Content -Path $publishsettings
$publishUrl = $targets.Project.PropertyGroup.publishUrl
$siteName = (Split-Path $publishUrl -NoQualifier).TrimStart("\").TrimStart("/")
$sxa_site = Get-Website | ? { $_.Name -eq $siteName }
$publishPath = $sxa_site.physicalPath
$currentDirectory = Get-Item .
clear
Write-Host "1. Restoring Nuget packages" -ForegroundColor "Green"
.\nuget\nuget.exe restore .\Sitecore.Utilities.sln
Write-Host "2. Building projects" -ForegroundColor "Green"
Get-ChildItem $currentDirectory.FullName -Recurse -Filter "*.csproj"| %{
$projectPath = $_.FullName.Replace($currentDirectory.FullName,".")
Write-Host "`tBuilding project $($_.Name)" -ForegroundColor "Cyan"
& $MSBuildCall $projectPath /p:Configuration=$configuration /p:Platform=AnyCPU /t:WebPublish /p:WebPublishMethod=FileSystem /p:DeleteExistingFiles=$deleteExistingFiles /p:publishUrl=$publishPath /v:q
}
Write-Host "3. Deploying '$envSpecificConfig'" -ForegroundColor "Green"
Copy-Item $envSpecificConfig "$($publishPath)\App_Config\Include"