diff --git a/build.psm1 b/build.psm1
index 1a0c359e6..d88717b6e 100644
--- a/build.psm1
+++ b/build.psm1
@@ -51,6 +51,9 @@ function Start-PSBuild {
[Parameter(ParameterSetName='FullCLR')]
[switch]$FullCLR,
+ [Parameter(ParameterSetName='FullCLR')]
+ [switch]$ResolveXaml,
+
[Parameter(ParameterSetName='FullCLR')]
[string]$cmakeGenerator = "Visual Studio 14 2015 Win64",
@@ -152,6 +155,13 @@ function Start-PSBuild {
Start-ResGen
}
+ # handle xaml files
+ # Heuristic to resolve xaml on the fresh machine
+ if ($FullCLR -and ($ResolveXaml -or -not (Test-Path "$PSScriptRoot/src/Microsoft.PowerShell.Activities/gen/*.g.resources")))
+ {
+ Resolve-Xaml -MSBuildConfiguration $msbuildConfiguration
+ }
+
# Build native components
if ($IsLinux -or $IsOSX) {
$Ext = if ($IsLinux) {
@@ -980,6 +990,115 @@ function Find-Dotnet() {
}
}
+function Resolve-Xaml
+{
+ [CmdletBinding()]
+ param(
+ [Parameter()]
+ [ValidateSet("Debug", "Release")]
+ [string]
+ $MSBuildConfiguration = "Release"
+ )
+
+ $MSBuildExe = Join-Path -Path ${env:SystemRoot}\Microsoft.Net\Framework\v4.0.30319 -ChildPath MSBuild.exe
+ if (-not (Test-Path -Path $MSBuildExe -PathType Leaf))
+ {
+ Write-Warning -Message 'msbuild not found. Install Visual Studio 2015.'
+ return
+ }
+
+ Get-ChildItem -Path "$PSScriptRoot/src" -Directory | % {
+
+ $XamlDir = Join-Path -Path $_.FullName -ChildPath Xamls
+ if ((Test-Path -Path $XamlDir -PathType Container) -and
+ (@(Get-ChildItem -Path "$XamlDir\*.xaml").Count -gt 0))
+ {
+ $OutputDir = Join-Path -Path $env:TEMP -ChildPath "_Resolve_Xaml_"
+ Remove-Item -Path $OutputDir -Recurse -Force -ErrorAction SilentlyContinue
+ mkdir -Path $OutputDir -Force > $null
+
+ $SourceDir = ConvertFrom-Xaml -Configuration $MSBuildConfiguration -OutputDir $OutputDir -XamlDir $XamlDir -MSBuildExe $MSBuildExe
+ $DestinationDir = Join-Path -Path $_.FullName -ChildPath gen
+
+ if (-not (Test-Path $DestinationDir -PathType Container))
+ {
+ mkdir -Path $DestinationDir -Force > $null
+ }
+ Copy-Item -Path $SourceDir\*.cs, $SourceDir\*.g.resources -Destination $DestinationDir -Force
+ }
+ }
+}
+
+$Script:XamlProj = @"
+
+
+ C#
+ Microsoft.PowerShell.Activities
+ library
+ {0}
+ Any CPU
+ {1}
+ true
+
+
+
+
+
+
+{2}
+
+ False
+
+
+ False
+
+
+ False
+
+
+
+"@
+
+$Script:XamlProjPage = @'
+
+
+'@
+
+function script:ConvertFrom-Xaml {
+ [CmdletBinding()]
+ param(
+ [Parameter(Mandatory=$true)]
+ [string] $Configuration,
+
+ [Parameter(Mandatory=$true)]
+ [string] $OutputDir,
+
+ [Parameter(Mandatory=$true)]
+ [string] $XamlDir,
+
+ [Parameter(Mandatory=$true)]
+ [string] $MSBuildExe
+ )
+
+ $Pages = ""
+ Get-ChildItem -Path "$XamlDir\*.xaml" | % {
+ $Page = $Script:XamlProjPage -f $_.FullName
+ $Pages += $Page
+ }
+
+ $XamlProjContent = $Script:XamlProj -f $Configuration, $OutputDir, $Pages
+ $XamlProjPath = Join-Path -Path $OutputDir -ChildPath xaml.proj
+ Set-Content -Path $XamlProjPath -Value $XamlProjContent -Encoding Ascii -NoNewline -Force
+
+ & $MSBuildExe $XamlProjPath > $null
+
+ if ($LASTEXITCODE -ne 0)
+ {
+ throw "'& $MSBuildExe $XamlProjPath > `$null' failed with exit code $LASTEXITCODE"
+ }
+
+ return (Join-Path -Path $OutputDir -ChildPath "obj\Any CPU\$Configuration")
+}
function script:log([string]$message) {
Write-Host -Foreground Green $message