<!--
***********************************************************************************************
Microsoft.Windows.UI.Xaml.Common.targets

WARNING:  DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
          created a backup copy.  Incorrect changes to this file will make it
          impossible to load or build your projects from the command-line or the IDE.

Copyright (C) Microsoft Corporation. All rights reserved.
***********************************************************************************************
-->

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <Import Project="ImportBefore\*"/>

  <!-- Need the path to vcmeta.dll -->
  <PropertyGroup>
    <XamlProjectName Condition=" '$(XamlProjectName)' == '' ">$(MSBuildProjectName)</XamlProjectName>
    <WindowsSdkPath Condition="'$(WindowsSdkPath)'==''">$([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\$(SDKIdentifier)\v$(SDKVersion)', 'InstallationFolder', null, RegistryView.Registry32, RegistryView.Default))</WindowsSdkPath>

    <XAMLFingerprint Condition="'$(XAMLFingerprint)' == ''">true</XAMLFingerprint>
    <DisableXbfGeneration Condition="'$(DisableXbfGeneration)' == '' AND '$(TargetPlatformVersion)' == '8.0'">true</DisableXbfGeneration>
    <DisableXbfGeneration Condition="'$(DisableXbfGeneration)' == ''">false</DisableXbfGeneration>

    <XamlSavedStateFileName Condition="'$(XamlSavedStateFileName)' == ''">XamlSaveStateFile.xml</XamlSavedStateFileName>
    <XamlSavedStateFilePath>$(IntermediateOutputPath)\$(XamlSavedStateFileName)</XamlSavedStateFilePath>

    <XAMLFingerprintIgnorePaths Condition="'$(XAMLFingerprintIgnorePaths)'==''">
      @(ReferenceAssemblyPaths);
      $(WindowsSdkPath)
    </XAMLFingerprintIgnorePaths>

    <PlatformXmlDir Condition="'$(PlatformXmlDir)' == ''">$(WindowsSdkPath)\Platforms\UAP\$(TargetPlatformVersion)\</PlatformXmlDir>

    <TPVFacadeWinmdPath>$(WindowsSdkPath)UnionMetadata\$(TargetPlatformVersion)\Facade\Windows.winmd</TPVFacadeWinmdPath>
    <!-- Favor a per-SDK Facade winmd. -->
    <FacadeWinmdPath Condition="'$(FacadeWinmdPath)' == '' AND Exists('$(TPVFacadeWinmdPath)')">$(TPVFacadeWinmdPath)</FacadeWinmdPath>
    <!-- If we can't find a per-SDK Facade winmd, use the one we used before. -->
    <FacadeWinmdPath Condition="'$(FacadeWinmdPath)' == ''">$(WindowsSdkPath)UnionMetadata\facade\Windows.winmd</FacadeWinmdPath>

    <XamlLanguage Condition="'$(XamlLanguage)' == ''">$(Language)</XamlLanguage>

    <!-- If building a C++\WinRT project, we need the cppwinrt.exe compiler to generate an IDL for our metadata provider -->
    <CppWinRTAddXamlMetaDataProviderIdl Condition="$(CppWinRTAddXamlMetaDataProviderIdl) != 'false'">true</CppWinRTAddXamlMetaDataProviderIdl>

    <!-- Turning CppWinRTHeapEnforcement back on by default for Xaml Projects.
         It had been previously turned off because of a bug in compiler code-gen. -->
    <CppWinRTHeapEnforcement Condition="'$(CppWinRTHeapEnforcement)' == ''">true</CppWinRTHeapEnforcement>
    
    <!-- Assume we're managed by default -->
    <IsNativeLanguage Condition="'$(IsNativeLanguage)' == ''">false</IsNativeLanguage>
    <IsNativeLanguage Condition="'$(IsNativeLanguage)' == 'false' AND '$(Language)' == 'C++'">true</IsNativeLanguage>

    <!-- If DisableGenXbfLineInfo is explicitly set, we should respect that value -->
    <!-- Otherwise, only enable XBF line info for debug builds -->
    <DisableXbfLineInfo Condition="'$(DisableXbfLineInfo)' == '' AND '$(Configuration)' != 'Debug'">true</DisableXbfLineInfo>
    <DisableXbfLineInfo Condition="'$(DisableXbfLineInfo)' == ''">false</DisableXbfLineInfo>
    <!-- Type info reflection for CppWinRT isn't supported yet, always disable it.  Additionally, disable it for CX until the implementation stabilizes -->
    <!-- This leaves type info reflection enabled for C# and VB -->
    <EnableTypeInfoReflection Condition="'$(XamlLanguage)' == 'CppWinRT' OR '$(XamlLanguage)' == 'C++'">false</EnableTypeInfoReflection>

    <!-- By default, we only enable type info reflection for debug CoreCLR builds.  We should respect if a project wants to enable/disable it in other cases -->
    <EnableTypeInfoReflection Condition="'$(EnableTypeInfoReflection)' == '' AND '$(Configuration)' == 'Debug' AND '$(UseDotNetNativeToolChain)' != 'true'">true</EnableTypeInfoReflection>
    <EnableTypeInfoReflection Condition="'$(EnableTypeInfoReflection)' == ''">false</EnableTypeInfoReflection>
    
    <!-- By default, XBindDiagnostics should not be generated on builds where E&C and Designer are likely not going to run -->
    <EnableXBindDiagnostics Condition="'$(EnableXBindDiagnostics)' == '' and '$(DisableXbfLineInfo)' == 'false'">true</EnableXBindDiagnostics>
    
    <!-- If EnableDefaultValidationContextGeneration is set, respect that value. Otherwise, we always generate it-->
    <EnableDefaultValidationContextGeneration Condition="'$(EnableDefaultValidationContextGeneration)' == ''">true</EnableDefaultValidationContextGeneration>
  </PropertyGroup>

  <!-- When using reflection for our metadata provider, we need to include the reflection helper DLL which is in the same folder as this targets file -->
  <Choose>
    <When Condition="'$(EnableTypeInfoReflection)' == 'true'">
      <ItemGroup>
        <Reference Include="Microsoft.UI.Xaml.Markup">
          <HintPath>$(MSBuildThisFileDirectory)Microsoft.UI.Xaml.Markup.winmd</HintPath>
        </Reference>
      </ItemGroup>
    </When>
  </Choose>

  <ItemGroup Condition="'$(BuildingInsideVisualStudio)'=='true'">
    <AvailableItemName Include="PRIResource" />
    <AvailableItemName Include="AppxManifest" />
    <AvailableItemName Include="ApplicationDefinition" />
    <AvailableItemName Include="Page" />
    <AvailableItemName Include="DesignData" />
    <AvailableItemName Include="DesignDataWithDesignTimeCreatableTypes" />
  </ItemGroup>

  <ItemGroup>
    <ProjectCapability Include="WindowsXaml"/>
    <ProjectCapability Include="WindowsXamlPage"/>
    <ProjectCapability Include="WindowsXamlCodeBehind"/>
    <ProjectCapability Include="WindowsXamlResourceDictionary"/>
    <ProjectCapability Include="WindowsXamlUserControl"/>
    <ProjectCapability Include="WindowsUniversalMultiViews"/>
  </ItemGroup>

  <!-- For Managed Assemblies Create a XAML Roots Log -->
  <PropertyGroup Condition="'$(ManagedAssembly)' != 'false'">
    <XamlRootsLog>$(AssemblyName).xr.xml</XamlRootsLog>
  </PropertyGroup>

  <!-- Setting PRI index name.  The XAML compiler use this in the LoadComponent() string.
         It must match the name of the directoy the AppX Packaging system uses -->
  <PropertyGroup>
    <!-- Exe's don't have an PriIndexName -->
    <PriIndexName Condition="'$(AppxPackage)' == 'true'"></PriIndexName>
    <!-- Managed Dll's use the "safe" name of the project as the App Package Name -->
    <PriIndexName Condition="'$(AppxPackage)' != 'true' and '$(ManagedAssembly)' != 'false' and '$(OutputType)' != 'winmdobj'">$(TargetName)</PriIndexName>
    <!-- Winmd library targets (managed or native) use the default root namespace of the project for the App package name -->
    <PriIndexName Condition="'$(AppxPackage)' != 'true' and '$(ManagedAssembly)' != 'false' and '$(OutputType)' == 'winmdobj'">$(RootNamespace)</PriIndexName>
    <PriIndexName Condition="'$(AppxPackage)' != 'true' and '$(ManagedAssembly)' == 'false' and '$(RootNamespace)' != ''">$(RootNamespace)</PriIndexName>
    <!-- If RootNamespace is empty fall back to TargetName -->
    <PriIndexName Condition="'$(AppxPackage)' != 'true' and $(PriIndexName) == ''">$(TargetName)</PriIndexName>
  </PropertyGroup>

  <PropertyGroup>
    <AvailablePlatforms>$(AvailablePlatforms),ARM</AvailablePlatforms>

    <!-- this Property is used only for the Managed build.
            See Microsoft.Windows.UI.Xaml.Cpp.Targets for Native build rules -->
    <PrepareResourcesDependsOn>
      ResolveKeySource;
      MarkupCompilePass1;
      XamlPreCompile;
      MarkupCompilePass2;
      $(PrepareResourcesDependsOn)
    </PrepareResourcesDependsOn>

    <Prefer32Bit Condition="'$(Prefer32Bit)' == '' and ('$(OutputType)' == 'exe' or '$(OutputType)' == 'winexe' or '$(OutputType)' == 'appcontainerexe')">true</Prefer32Bit>
    <HighEntropyVA Condition="'$(HighEntropyVA)' == ''">true</HighEntropyVA>
    <SubsystemVersion Condition="'$(SubsystemVersion)' == '' and ('$(PlatformTarget)' == 'ARM' or '$(OutputType)' == 'appcontainerexe' or '$(OutputType)' == 'winmdobj')">6.02</SubsystemVersion>
    <SubsystemVersion Condition="'$(SubsystemVersion)' == ''">6.00</SubsystemVersion>

    <OnXamlPreCompileErrorTarget Condition="'$(OnXamlPreCompileErrorTarget)' == ''">_OnXamlPreCompileError</OnXamlPreCompileErrorTarget>

    <!-- Use Intermediate dir if XamlGeneratedOutputPath is not defined -->
    <XamlGeneratedOutputPath Condition="'$(XamlGeneratedOutputPath)' == ''">$(IntermediateOutputPath)</XamlGeneratedOutputPath>
  </PropertyGroup>

  <PropertyGroup Condition="$(XamlCompilerTaskPath) == ''">
    <XamlCompilerTaskPath>$(MSBuildThisFileDirectory)Microsoft.Windows.UI.Xaml.Build.Tasks.dll</XamlCompilerTaskPath>
  </PropertyGroup>

  <UsingTask TaskName="Microsoft.Windows.UI.Xaml.Build.Tasks.CompileXaml"                  AssemblyFile="$(XamlCompilerTaskPath)" />
  <UsingTask TaskName="Microsoft.Windows.UI.Xaml.Build.Tasks.AddDefaultXamlLinkMetadata"   AssemblyFile="$(XamlCompilerTaskPath)" />
  <UsingTask TaskName="Microsoft.Windows.UI.Xaml.Build.Tasks.GetXamlCppIncludeDirectories" AssemblyFile="$(XamlCompilerTaskPath)" />

  <PropertyGroup>
    <!--If the path to the sign tool is not set, assume the SDK path -->
    <SignToolPath Condition="'$(SignToolPath)' == ''">$(FrameworkSDKRoot)bin</SignToolPath>

    <!--Integration with packaging for GeneratedXamlFilesOutputGroupOutput -->
    <IncludeCustomOutputGroupForPackaging>true</IncludeCustomOutputGroupForPackaging>
  </PropertyGroup>

  <ItemGroup>
    <XamlIntermediateAssembly Condition="'$(ManagedAssembly)'!='false'" Include="$(XamlGeneratedOutputPath)intermediatexaml\$(TargetName)$(TargetExt)"/>
    <XamlIntermediateAssembly Condition="'$(ManagedAssembly)'=='false'" Include="$(OutputPath)\$(TargetName).winmd"/>
  </ItemGroup>

  <!--
    ============================================================
    Adds all XAML Pages to the $(Resource) collection
    ============================================================
    -->
  <ItemGroup Condition=" '$(ManagedAssembly)'=='' ">
    <!-- Add XAML Page items to $(Resource) -->
    <Resource Include="@(Page)" />
    <Resource Include="@(ApplicationDefinition)" />
  </ItemGroup>

  <!-- Manifest metadata items.                       -->
  <!-- See Microsoft.AppxPackage.targets for details. -->
  <!-- Project binary needs to be updated after updating xaml page -->
  <ItemGroup>
    <CustomAdditionalCompileInputs Include="@(Page)" />
  </ItemGroup>

  <ItemGroup Label="AppxManifestMetadata">
    <AppxManifestMetadata Include="$(XamlCompilerTaskPath)" />
  </ItemGroup>

  <PropertyGroup>
    <MarkupCompilePass1DependsOn>
      GetXamlCppIncludeDirectories;
      $(GetXamlCppIncludeDirectories)
    </MarkupCompilePass1DependsOn>

    <MarkupCompilePass2DependsOn>
      GetXamlCppIncludeDirectories;
      $(GetXamlCppIncludeDirectories)
    </MarkupCompilePass2DependsOn>

    <Prep_ComputeProcessXamlFilesDependsOn>
      GetXamlCppIncludeDirectories;
      $(Prep_ComputeProcessXamlFilesDependsOn)
    </Prep_ComputeProcessXamlFilesDependsOn>
  </PropertyGroup>

  <!-- In order for the XAML compiler to generated the correct relative paths for #includes in
         the generated C++ code it needs to know the AdditionalIncludeDirectories of all the .cpp
         files are DependentUpon XAML files.-->
  <Target Name="GetXamlCppIncludeDirectories" Condition="'$(ManagedAssembly)'=='false' and '$(XamlCppIncludeDirectories)' == ''">
    <GetXamlCppIncludeDirectories ClCompile="@(ClCompile)">
      <Output PropertyName="XamlCppIncludeDirectories" TaskParameter="ComputedIncludeDirectories" />
    </GetXamlCppIncludeDirectories>
  </Target>

  <!-- 
    ================================================================
                        DesignTimeMarkupCompilation
                        
    Support for the Intellisense build
    ================================================================
     -->
  <PropertyGroup>
    <CoreCompileDependsOn Condition="'$(BuildingInsideVisualStudio)' == 'true' ">
      DesignTimeMarkupCompilation;
      $(CoreCompileDependsOn)
    </CoreCompileDependsOn>
  </PropertyGroup>

  <Target Name="DesignTimeMarkupCompilation">
    <!-- BuildingProject is used in Managed builds (always true in Native) -->
    <!-- DesignTimeBuild is used in Native builds (always false in Managed) -->
    <CallTarget Condition="'$(BuildingProject)' != 'true' Or $(DesignTimeBuild) == 'true'" Targets="DesignTimeMarkupCompilationCT" />
  </Target>

  <!-- A copy of the first pass, without the WarningLevel manipulation -->
  <Target Name="DesignTimeMarkupCompilationCT"
        DependsOnTargets="$(MarkupCompilePass1DependsOn)"
        Condition="'@(Page)' != '' Or '@(ApplicationDefinition)' != '' " >

    <MakeDir Condition="'$(ManagedAssembly)'!='false'" Directories="$(XamlGeneratedOutputPath)intermediatexaml\" />
    <ItemGroup>
      <ReferencePath Condition="'$(IsNativeLanguage)'=='true' and Exists($(FacadeWinmdPath))" Include="$(FacadeWinmdPath)" />
    </ItemGroup>
    <CompileXaml
            LanguageSourceExtension="$(DefaultLanguageSourceExtension)"
            Language="$(XamlLanguage)"
            RootNamespace="$(RootNamespace)"
            XamlPages="@(Page)"
            XamlApplications="@(ApplicationDefinition)"
            PriIndexName="$(PriIndexName)"
            ProjectName="$(XamlProjectName)"
            IsPass1="True"
            CodeGenerationControlFlags="$(XamlCodeGenerationControlFlags)"
            CIncludeDirectories="$(XamlCppIncludeDirectories)"
            ProjectPath="$(MSBuildProjectFullPath)"
            OutputPath="$(XamlGeneratedOutputPath)"
            OutputType="$(OutputType)"
            ReferenceAssemblyPaths="@(ReferenceAssemblyPaths)"
            ReferenceAssemblies="@(ReferencePath)"
            ForceSharedStateShutdown="False"
            ContinueOnError="True"
            CompileMode="DesignTimeBuild"
            XAMLFingerprint="$(XAMLFingerprint)"
            FingerprintIgnorePaths="$(XAMLFingerprintIgnorePaths)"
            VCInstallDir="$(VCInstallDir)"
            SavedStateFile="$(XamlSavedStateFilePath)"
            SuppressWarnings="$(SuppressXamlWarnings)"
            TargetPlatformMinVersion="$(TargetPlatformMinVersion)"
            WindowsSdkPath="$(WindowsSdkPath)"
            XamlResourceMapName="$(XamlResourceMapName)"
            XamlComponentResourceLocation="$(XamlComponentResourceLocation)"
            EnableTypeInfoReflection="$(EnableTypeInfoReflection)"
            EnableXBindDiagnostics="$(EnableXBindDiagnostics)"
            EnableDefaultValidationContextGeneration="$(EnableDefaultValidationContextGeneration)"
            >
      <Output Condition=" '$(ManagedAssembly)'!='false' " ItemName="Compile"   TaskParameter="GeneratedCodeFiles" />

      <!--
      Add to the list of files written.
      It is used in Microsoft.Common.Targets for a next clean build 
      -->
      <Output ItemName="FileWrites" TaskParameter="GeneratedCodeFiles" />
      <Output ItemName="FileWrites" TaskParameter="GeneratedXamlFiles" />
      <Output ItemName="_GeneratedCodeFiles" TaskParameter="GeneratedCodeFiles" />
      <Output ItemName="_GeneratedXamlFiles" TaskParameter="GeneratedXamlFiles" />
    </CompileXaml>

    <ItemGroup>
      <FileWrites Include="$(XamlSavedStateFilePath)" />
    </ItemGroup>

    <Message Text="(Out) ISenseCodeFiles: '@(_GeneratedCodeFiles)'" />
    <Message Text="(Out) ISenseXamlFiles: '@(_GeneratedXamlFiles)'" />
    <Message Text="(Out) ClCompile: '@(ClCompile)'" Condition="'%(ClCompile.CompilerIteration)' != 'XamlGenerated'"/>
    <Message Text="(Out) Compile: '@(Compile)'" />
  </Target>

  <!--   
    ================================================================
                         MarkupCompilePass1
    ================================================================
    -->

  <Target Name="MarkupCompilePass1"
        DependsOnTargets="$(MarkupCompilePass1DependsOn)"
        Condition="'@(Page)' != '' Or '@(ApplicationDefinition)' != '' " >

    <MakeDir Condition="'$(ManagedAssembly)'!='false'" Directories="$(XamlGeneratedOutputPath)intermediatexaml\" />
    <ItemGroup>
      <ReferencePath Condition="'$(IsNativeLanguage)'=='true' and Exists($(FacadeWinmdPath))" Include="$(FacadeWinmdPath)" />
    </ItemGroup>
    <CompileXaml
            LanguageSourceExtension="$(DefaultLanguageSourceExtension)"
            Language="$(XamlLanguage)"
            RootNamespace="$(RootNamespace)"
            XamlPages="@(Page)"
            XamlApplications="@(ApplicationDefinition)"
            PriIndexName="$(PriIndexName)"
            ProjectName="$(XamlProjectName)"
            IsPass1="True"
            CodeGenerationControlFlags="$(XamlCodeGenerationControlFlags)"
            ProjectPath="$(MSBuildProjectFullPath)"
            CIncludeDirectories="$(XamlCppIncludeDirectories)"
            OutputPath="$(XamlGeneratedOutputPath)"
            OutputType="$(OutputType)"
            ReferenceAssemblyPaths="@(ReferenceAssemblyPaths)"
            ReferenceAssemblies="@(ReferencePath)"
            ForceSharedStateShutdown="False"
            CompileMode="RealBuildPass1"
            XAMLFingerprint="$(XAMLFingerprint)"
            FingerprintIgnorePaths="$(XAMLFingerprintIgnorePaths)"
            VCInstallDir="$(VCInstallDir)"
            SavedStateFile="$(XamlSavedStateFilePath)"
            SuppressWarnings="$(SuppressXamlWarnings)"
            TargetPlatformMinVersion="$(TargetPlatformMinVersion)"
            WindowsSdkPath="$(WindowsSdkPath)"
            XamlResourceMapName="$(XamlResourceMapName)"
            XamlComponentResourceLocation="$(XamlComponentResourceLocation)"
            EnableTypeInfoReflection="$(EnableTypeInfoReflection)"
            EnableXBindDiagnostics="$(EnableXBindDiagnostics)"
            EnableDefaultValidationContextGeneration="$(EnableDefaultValidationContextGeneration)"
            >

      <Output Condition=" '$(ManagedAssembly)'!='false' " ItemName="Compile"   TaskParameter="GeneratedCodeFiles" />

      <!--
      FileWrites is used in Microsoft.Common.Targets for "Clean" build 
      -->
      <Output ItemName="FileWrites" TaskParameter="GeneratedCodeFiles" />
      <Output ItemName="FileWrites" TaskParameter="GeneratedXamlFiles" />
      <Output ItemName="FileWrites" TaskParameter="GeneratedXbfFiles" />
      <Output ItemName="_GeneratedCodeFiles" TaskParameter="GeneratedCodeFiles" />
      <Output ItemName="_GeneratedXamlFiles" TaskParameter="GeneratedXamlFiles" />
      <Output ItemName="_GeneratedXbfFiles" TaskParameter="GeneratedXbfFiles" />
    </CompileXaml>

    <ItemGroup>
      <FileWrites Include="$(XamlSavedStateFilePath)" />
    </ItemGroup>

    <Message Text="(Out) GeneratedCodeFiles: '@(_GeneratedCodeFiles)'" />
    <Message Text="(Out) GeneratedXamlFiles: '@(_GeneratedXamlFiles)'" />
    <Message Text="(Out) GeneratedXbfFiles: '@(_GeneratedXbfFiles)'" />
    <Message Text="(Out) ClCompile: '@(ClCompile)'" Condition="'$(ManagedAssembly)'=='false' and '%(ClCompile.CompilerIteration)'!='XamlGenerated'"/>
    <Message Text="(Out) Compile: '@(Compile)'" Condition="'$(ManagedAssembly)'!='false'"/>

    <PropertyGroup>
      <PrevWarningLevel>$(WarningLevel)</PrevWarningLevel>
      <WarningLevel Condition="'$(SuppressWarningsInPass1)'=='true'">0</WarningLevel>
    </PropertyGroup>
  </Target>

  <!--   
    ================================================================
                         MarkupCompilePass2
    ================================================================
    -->

  <Target Name="MarkupCompilePass2"
          DependsOnTargets="$(MarkupCompilePass2DependsOn)"
          Condition="'@(Page)' != '' Or '@(ApplicationDefinition)' != '' " >

    <PropertyGroup>
      <WarningLevel>$(PrevWarningLevel)</WarningLevel>
      <WarningLevel Condition="'$(WarningLevel)' == '' and '$(ExplicitResetWarningSuppression)' == 'true'">1</WarningLevel>
    </PropertyGroup>

    <!-- The Name of the Local Assembly in Managed and Native -->
    <PropertyGroup>
      <LocalAssembly Condition="'$(LocalAssembly)' == '' and Exists(@(XamlIntermediateAssembly))">
        @(XamlIntermediateAssembly->'%(Identity)')
      </LocalAssembly>
      <XamlLocalAssembly Condition="'$(XamlLocalAssembly)' == ''">$(LocalAssembly)</XamlLocalAssembly>
    </PropertyGroup>

    <CallTarget Targets="SDKRedistOutputGroup" Condition="'$(IncludeSDKRedistOutputGroup)' == 'true'">
      <Output TaskParameter="TargetOutputs" ItemName="_SDKRedistOutputGroupOutput_xaml"/>
    </CallTarget>
    <ItemGroup>
      <SdkXamlItems Include="@(_SDKRedistOutputGroupOutput_xaml)" Condition="'%(Extension)'=='.xaml'" />
    </ItemGroup>

    <ItemGroup>
      <!-- C++ provides a filtered Item that eliminates any Managed Assemblies on the ReferencePath (from SDKs for example) -->
      <XamlReferencesToCompile Condition="'$(IsNativeLanguage)'=='true'" Include="@(WinMDReferenceToCompile)" />
      <XamlReferencesToCompile Condition="'$(IsNativeLanguage)'=='true' and Exists($(FacadeWinmdPath))" Include="$(FacadeWinmdPath)" />
      <XamlReferencesToCompile Condition="'$(IsNativeLanguage)'!='true'" Include="@(ReferencePath)" />
    </ItemGroup>

    <CompileXaml
            LanguageSourceExtension="$(DefaultLanguageSourceExtension)"
            Language="$(XamlLanguage)"
            RootNamespace="$(RootNamespace)"
            XamlPages="@(Page)"
            XamlApplications="@(ApplicationDefinition)"
            SdkXamlPages="@(SdkXamlItems)"
            PriIndexName="$(PriIndexName)"
            ProjectName="$(XamlProjectName)"
            IsPass1="False"
            DisableXbfGeneration="$(DisableXbfGeneration)"
            DisableXbfLineInfo="$(DisableXbfLineInfo)"
            CodeGenerationControlFlags="$(XamlCodeGenerationControlFlags)"
            ClIncludeFiles="@(ClInclude)"
            CIncludeDirectories="$(XamlCppIncludeDirectories)"
            LocalAssembly="$(XamlLocalAssembly)"
            ProjectPath="$(MSBuildProjectFullPath)"
            OutputPath="$(XamlGeneratedOutputPath)"
            OutputType="$(OutputType)"
            ReferenceAssemblyPaths="@(ReferenceAssemblyPaths)"
            ReferenceAssemblies="@(XamlReferencesToCompile)"
            ForceSharedStateShutdown="False"
            CompileMode="RealBuildPass2"
            XAMLFingerprint="$(XAMLFingerprint)"
            FingerprintIgnorePaths="$(XAMLFingerprintIgnorePaths)"
            VCInstallDir="$(VCInstallDir)"
            WindowsSdkPath="$(WindowsSdkPath)"
            SavedStateFile="$(XamlSavedStateFilePath)"
            RootsLog="$(XamlRootsLog)"
            SuppressWarnings="$(SuppressXamlWarnings)"
            TargetPlatformMinVersion="$(TargetPlatformMinVersion)"
            XamlResourceMapName="$(XamlResourceMapName)"
            XamlComponentResourceLocation="$(XamlComponentResourceLocation)"
            PlatformXmlDir="$(PlatformXmlDir)"
            EnableTypeInfoReflection="$(EnableTypeInfoReflection)"
            EnableXBindDiagnostics="$(EnableXBindDiagnostics)"
            EnableDefaultValidationContextGeneration="$(EnableDefaultValidationContextGeneration)"
            >
      <Output Condition=" '$(ManagedAssembly)'!='false' " ItemName="Compile"   TaskParameter="GeneratedCodeFiles" />
      <Output Condition=" '$(ManagedAssembly)'=='false' " ItemName="XamlGFiles" TaskParameter="GeneratedCodeFiles" />

      <!--
      FileWrites is used in Microsoft.Common.Targets for "Clean" build 
      -->
      <Output ItemName="FileWrites" TaskParameter="GeneratedCodeFiles" />
      <Output ItemName="FileWrites" TaskParameter="GeneratedXamlFiles" />
      <Output ItemName="FileWrites" TaskParameter="GeneratedXbfFiles" />
      <Output ItemName="FileWrites" TaskParameter="GeneratedXamlPagesFiles" />
      <Output ItemName="_GeneratedCodeFiles" TaskParameter="GeneratedCodeFiles" />
      <Output ItemName="_GeneratedXamlFiles" TaskParameter="GeneratedXamlFiles" />
      <Output ItemName="_GeneratedXbfFiles" TaskParameter="GeneratedXbfFiles" />
      <Output ItemName="GeneratedXamlPagesFiles" TaskParameter="GeneratedXamlPagesFiles" />
    </CompileXaml>

    <ItemGroup>
      <FileWrites Include="$(XamlSavedStateFilePath)" />
      <FileWrites Condition="'$(XamlRootsLog)' != ''" Include="$(XamlRootsLog)" />
    </ItemGroup>

    <Message Text="(Out) GeneratedCodeFiles: '@(_GeneratedCodeFiles)'" />
    <Message Text="(Out) GeneratedXamlFiles: '@(_GeneratedXamlFiles)'" />
    <Message Text="(Out) GeneratedXbfFiles: '@(_GeneratedXbfFiles)'" />
    <Message Text="(Out) GeneratedXamlPagesFiles: '@(GeneratedXamlPagesFiles)'" />
    <Message Text="(Out) ClCompile: '@(ClCompile)'" Condition="'$(ManagedAssembly)'=='false'"/>
    <Message Text="(Out) Compile: '@(Compile)'" Condition="'$(ManagedAssembly)'!='false'"/>

    <ItemGroup>
      <ClCompile Include="@(GeneratedXamlPagesFiles)" >
        <CompilerIteration>XamlGenerated</CompilerIteration>
      </ClCompile>
    </ItemGroup>
  </Target>

  <Target Name="_OnXamlPreCompileError"
          DependsOnTargets="$(_OnXamlPrecompileErrorDependsOn)" >

    <CompileXaml
            ProjectPath="$(MSBuildProjectFullPath)"
            Language="$(XamlLanguage)"
            LanguageSourceExtension="$(DefaultLanguageSourceExtension)"
            OutputPath="$(XamlGeneratedOutputPath)"
            ReferenceAssemblies="@(ReferencePath)"
            ReferenceAssemblyPaths="@(ReferenceAssemblyPaths)"
            XamlPages="@(Page)"
            XamlApplications="@(ApplicationDefinition)"
            ForceSharedStateShutdown="True"
            CompileMode="OnErrorShutdown"
            SavedStateFile="$(XamlSavedStateFilePath)"
            TargetPlatformMinVersion="$(TargetPlatformMinVersion)"
            XamlResourceMapName="$(XamlResourceMapName)"
            XamlComponentResourceLocation="$(XamlComponentResourceLocation)"
            >
    </CompileXaml>
  </Target>

  <Target Name="Prep_ComputeProcessXamlFiles"
          Condition="'@(ApplicationDefinition)'!='' or '@(Page)'!=''"
          DependsOnTargets="$(Prep_ComputeProcessXamlFilesDependsOn)" >

    <!-- collect all the XAML pages from the Project file into one Item -->
    <ItemGroup>
      <AllProjectXamlPages Condition="'%(ApplicationDefinition.ExcludedFromBuild)'!='true'" Include="@(ApplicationDefinition)" />
      <AllProjectXamlPages Condition="'%(Page.ExcludedFromBuild)'!='true'" Include="@(Page)" />
    </ItemGroup>

    <!-- For items are outside the project core Link metadata tells us what the apparent project path should be.
         C++ doesn't use Link data, so for C++ add implied DefaultXamlLink metadata based on the Include Path -->
    <AddDefaultXamlLinkMetadata Condition="'$(ManagedAssembly)'=='false'"
                                ProjectPath="$(ProjectPath)"
                                XamlPages="@(AllProjectXamlPages)"
                                CIncludeDirectories ="$(XamlCppIncludeDirectories)">
      <Output TaskParameter="OutputItems" ItemName="_Temp" />
    </AddDefaultXamlLinkMetadata>

    <!-- Remove the Items named in _Temp, then add the actual items from _Temp, then clear _Temp  -->
    <ItemGroup>
      <AllProjectXamlPages Remove="@(_Temp)" />
      <AllProjectXamlPages Include="@(_Temp)" />
      <_Temp Remove="@(_Temp)" />
    </ItemGroup>

    <!-- transfer the DefaultXamlLink data to the Link attribute -->
    <ItemGroup>
      <AllProjectXamlPages Condition="'%(AllProjectXamlPages.DefaultXamlLink)'!=''">
        <Link>%(AllProjectXamlPages.DefaultXamlLink)</Link>
      </AllProjectXamlPages>
    </ItemGroup>

    <!-- Compute the Generated XAML source path and the bin dir Destination path -->
    <!-- If there is a Link use that, otherwise use the Given path from the Project file Item -->
    <ItemGroup>
      <GeneratedXamlSrc0 Condition="'%(AllProjectXamlPages.Link)'!=''" Include="@(AllProjectXamlPages->'$(XamlGeneratedOutputPath)%(Link)')" />
      <GeneratedXamlSrc0 Condition="'%(AllProjectXamlPages.Link)'==''" Include="@(AllProjectXamlPages->'$(XamlGeneratedOutputPath)%(Identity)')" />

      <GeneratedXamlDest0 Condition="'%(AllProjectXamlPages.Link)'!=''" Include="@(AllProjectXamlPages->'$(OutputPath)\%(Link)')" />
      <GeneratedXamlDest0 Condition="'%(AllProjectXamlPages.Link)'==''" Include="@(AllProjectXamlPages->'$(OutputPath)\%(Identity)')" />
    </ItemGroup>

    <!-- Swap in the XBF suffix if appropriate. -->
    <ItemGroup Condition="'$(DisableXbfGeneration)' == 'true'">
      <GeneratedXamlSrc Include="@(GeneratedXamlSrc0)" />
      <GeneratedXamlDest Include="@(GeneratedXamlDest0)" />
    </ItemGroup>
    <ItemGroup Condition="'$(DisableXbfGeneration)' != 'true'">
      <GeneratedXamlSrc Include="%(GeneratedXamlSrc0.RelativeDir)%(GeneratedXamlSrc0.Filename).xbf" />
      <GeneratedXamlDest Include="%(GeneratedXamlDest0.RelativeDir)%(GeneratedXamlDest0.Filename).xbf" />
    </ItemGroup>

    <!-- if we converted SDK XAML into XBF, add the XBF to the list, and remove the XAML from the list -->
    <ItemGroup Condition="'$(DisableXbfGeneration)' != 'true' and '@(SdkXamlItems)' != ''">
      <GeneratedSdkXamlSrc0 Include="@(SdkXamlItems->'$(XamlGeneratedOutputPath)%(TargetPath)')" />
      <GeneratedSdkXamlDest0 Include="@(SdkXamlItems->'$(OutputPath)\%(TargetPath)')" />

      <GeneratedXamlSrc Include="%(GeneratedSdkXamlSrc0.RelativeDir)%(GeneratedSdkXamlSrc0.Filename).xbf" >
        <ReferenceSourceTarget>ExpandSDKReference</ReferenceSourceTarget>
      </GeneratedXamlSrc>
      <GeneratedXamlDest Include="%(GeneratedSdkXamlDest0.RelativeDir)%(GeneratedSdkXamlDest0.Filename).xbf" >
        <ReferenceSourceTarget>ExpandSDKReference</ReferenceSourceTarget>
      </GeneratedXamlDest>
      <RemoveSdkFilesFromAppxPackage Include="@(SdkXamlItems)" />
    </ItemGroup>

    <ItemGroup Condition="'$(XamlRootsLog)' != ''">
      <GeneratedXamlSrc Include="$(XamlGeneratedOutputPath)\$(XamlRootsLog)" />
      <GeneratedXamlDest Include="$(OutputPath)\$(XamlRootsLog)" />
    </ItemGroup>

    <Message Importance="low" Text="(Out) Prep_GeneratedXamlSrc == @(GeneratedXamlSrc)" />
    <Message Importance="low" Text="(Out) Prep_GeneratedXamlDest == @(GeneratedXamlDest)" />
  </Target>

  <!-- if $GenerateLibraryLayout is True this is skipped and see the PrepareLibraryLayout target -->
  <Target Name="CopyGeneratedXaml" BeforeTargets="CopyFilesToOutputDirectory" DependsOnTargets="Prep_ComputeProcessXamlFiles"
            Condition="'$(GenerateLibraryLayout)' != 'true'">
    <Copy
        SourceFiles="@(GeneratedXamlSrc)"
        DestinationFiles="@(GeneratedXamlDest)"
        SkipUnchangedFiles="$(SkipCopyUnchangedFiles)"
        OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
        Retries="$(CopyRetryCount)"
        RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)"
        UseHardlinksIfPossible="$(CreateHardLinksForCopyFilesToOutputDirectoryIfPossible)"
        />
    <ItemGroup>
      <FileWrites Include="@(GeneratedXamlDest)" />
    </ItemGroup>
  </Target>

  <Target Name="ComputeProcessXamlFiles" Returns="@(ProcessedXamlFiles)" DependsOnTargets="Prep_ComputeProcessXamlFiles">
    <ItemGroup >
      <!-- In the normal (non-SDK) build, AppX Packaging picks up the files from the bin aka OutputPath folder -->
      <ProcessedXamlFiles Condition="'$(GenerateLibraryLayout)' != 'true'" Include="@(GeneratedXamlDest)" />

      <!-- In the SDK build, AppX Packaging picks up the files from the XamlGeneratedOutput folder -->
      <!-- For SDK builds include both the XAML and XBF -->
      <ProcessedXamlFiles Condition="'$(GenerateLibraryLayout)' == 'true'" Include="@(GeneratedXamlSrc)" />
      <ProcessedXamlFiles Condition="'$(GenerateLibraryLayout)' == 'true' and '$(DisableXbfGeneration)' != 'true'"
                          Include="@(GeneratedXamlSrc0)" />
    </ItemGroup>
    <Message Importance="Low" Text="(Out) GeneratedXamlDest == @(GeneratedXamlDest)" />
    <Message Importance="Low" Text="(Out) GeneratedXamlSrc == @(GeneratedXamlSrc)" />
    <Message Text="(Out) ProcessedXamlFiles == @(ProcessedXamlFiles)" />
  </Target>

  <Target Name="CustomOutputGroupForPackaging"
          DependsOnTargets="ComputeProcessXamlFiles"
          Returns="@(CustomOutputGroupForPackagingOutput)"
            >
    <ItemGroup>
      <ProcessedXamlFilesFullPath Include="@(ProcessedXamlFiles->'%(FullPath)')" />
    </ItemGroup>

    <PropertyGroup>
      <XamlPackagingRootFolder Condition="'$(GenerateLibraryLayout)' == 'true'">$(XamlGeneratedOutputPath)</XamlPackagingRootFolder>
      <XamlPackagingRootFolder Condition="'$(GenerateLibraryLayout)' != 'true'">$(OutputPath)\</XamlPackagingRootFolder>
    </PropertyGroup>

    <AssignTargetPath Files="@(ProcessedXamlFilesFullPath)" RootFolder="$(XamlPackagingRootFolder)">
      <Output TaskParameter="AssignedFiles" ItemName="CustomOutputGroupForPackagingOutput" />
    </AssignTargetPath>

    <Message Text="(Out) Project='$(MsBuildProjectName)' ProcessedXamlFiles == @(ProcessedXamlFiles)" />
    <Message Text="(Out) XamlPackagingRootFolder == $(XamlPackagingRootFolder)" />
    <Message Text="(Out) ProcessedXamlFilesFullPath == @(ProcessedXamlFilesFullPath)" />
    <Message Text="(Out) Project='$(MsBuildProjectName)' CustomOutputGroupForPackagingOutput == @(CustomOutputGroupForPackagingOutput)" />

  </Target>

  <PropertyGroup>
    <PrepareLibraryLayoutDependsOn>
      GetPackagingOutputs;
      $(PrepareLibraryLayoutDependsOn)
    </PrepareLibraryLayoutDependsOn>
  </PropertyGroup>

  <!-- This builds the Bin Folder for DLL's that wish to have the SDK type layout -->
  <Target Name="PrepareLibraryLayout"
          Condition="'$(GenerateLibraryLayout)' == 'true'"
          DependsOnTargets="$(PrepareLibraryLayoutDependsOn)"
          BeforeTargets="CopyFilesToOutputDirectory"
            >

    <ItemGroup>
      <_LayoutFile Include="@(PackagingOutputs)" Condition="'%(OutputGroup)' == 'ContentFilesProjectOutputGroup'" />
      <_LayoutFile Include="@(PackagingOutputs)" Condition="'%(OutputGroup)' == 'CustomOutputGroupForPackaging'" />
    </ItemGroup>

    <Copy SourceFiles="@(_LayoutFile)"
          DestinationFiles="@(_LayoutFile->'$(OutputPath)\%(TargetPath)')"
          SkipUnchangedFiles="$(SkipCopyUnchangedFiles)"
          OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
          Retries="$(CopyRetryCount)"
          RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)"
          UseHardlinksIfPossible="$(CreateHardLinksForCopyFilesToOutputDirectoryIfPossible)"
              />
  </Target>

  <!--
    ============================================================
    Properties and Targets Common to Managed .NETCore projects
    ============================================================
    -->

  <!--
      The ImplicitlyExpandTargetFramework target will expand all 
      of the dll reference assemblies in the TargetFrameworkDirectory 
      for the project and place the items into the ReferencePath itemgroup 
      which contains resolved items.
    -->
  <PropertyGroup>
    <ResolveReferencesDependsOn>
      $(ResolveReferencesDependsOn);
      ImplicitlyExpandTargetFramework;
      ImplicitlyExpandTargetPlatform
    </ResolveReferencesDependsOn>

    <ImplicitlyExpandTargetFrameworkDependsOn>
      $(ImplicitlyExpandTargetFrameworkDependsOn);
      GetReferenceAssemblyPaths
    </ImplicitlyExpandTargetFrameworkDependsOn>
  </PropertyGroup>

  <Target Name="ImplicitlyExpandTargetFramework"
      Condition="'$(ImplicitlyExpandTargetFramework)' == 'true'"
      DependsOnTargets="$(ImplicitlyExpandTargetFrameworkDependsOn)"
    >
    <ItemGroup>
      <ReferenceAssemblyPaths Include="$(_TargetFrameworkDirectories)"/>
      <ReferencePath Include="%(ReferenceAssemblyPaths.Identity)*.dll">
        <WinMDFile>false</WinMDFile>
        <CopyLocal>false</CopyLocal>
        <ReferenceGroupingDisplayName>.NET for Windows Store apps</ReferenceGroupingDisplayName>
        <ReferenceGrouping>$(TargetFrameworkMoniker)</ReferenceGrouping>
        <ResolvedFrom>ImplicitlyExpandTargetFramework</ResolvedFrom>
        <IsSystemReference>True</IsSystemReference>
      </ReferencePath>
    </ItemGroup>

    <Message Importance="Low" Text="TargetMonikerDisplayName: $(TargetFrameworkMonikerDisplayName) ReferenceAssemblyPaths: @(ReferenceAssemblyPaths)"/>

    <Message Importance="Low" Text="Including @(ReferencePath)"
      Condition="'%(ReferencePath.ResolvedFrom)' == 'ImplicitlyExpandTargetFramework'"/>

    <ItemGroup>
      <_ResolveAssemblyReferenceResolvedFiles Include="@(ReferencePath)"
        Condition="'%(ReferencePath.ResolvedFrom)' == 'ImplicitlyExpandTargetFramework'"/>
    </ItemGroup>
  </Target>

  <!--
      The ImplicitlyExpandTargetPlatform target will find the 
      appropriate platform in the requested SDK, gather the 
      list of references for that platform, and add them to the
      ReferencePath item which is the ItemGroup which contains
      resolved paths to pass to e.g. the compiler. 
    -->
  <Target Name="ImplicitlyExpandTargetPlatform"
     Condition="'$(ImplicitlyExpandTargetPlatform)' == 'true'"
    >

    <ItemGroup>
      <_TargetPlatformWinMDs Condition="'$(TargetPlatformWinMDLocation)' != ''" Include="$(TargetPlatformWinMDLocation)\**\*.winmd">
        <WinMDFile>true</WinMDFile>
        <CopyLocal>false</CopyLocal>
        <ReferenceGrouping>$(TargetPlatformMoniker)</ReferenceGrouping>
        <ReferenceGroupingDisplayName>$(TargetPlatformDisplayName)</ReferenceGroupingDisplayName>
        <ResolvedFrom>ImplicitlyExpandTargetPlatform</ResolvedFrom>
        <IsSystemReference>True</IsSystemReference>
      </_TargetPlatformWinMDs>
      <_TargetPlatformWinMDs Condition="'$(TargetPlatformSdkRootOverride)' != '' AND '$(TargetPlatformWinMDLocation)' == ''" Include="$(TargetPlatformSdkRootOverride)\References\$(XeWin10TargetVersion)\**\*.winmd">
        <WinMDFile>true</WinMDFile>
        <CopyLocal>false</CopyLocal>
        <ReferenceGrouping>$(TargetPlatformMoniker)</ReferenceGrouping>
        <ReferenceGroupingDisplayName>$(TargetPlatformDisplayName)</ReferenceGroupingDisplayName>
        <ResolvedFrom>ImplicitlyExpandTargetPlatform</ResolvedFrom>
        <IsSystemReference>True</IsSystemReference>
      </_TargetPlatformWinMDs>
      <_TargetPlatformWinMDs Condition="'$(TargetPlatformSdkRootOverride)' == '' AND '$(TargetPlatformWinMDLocation)' == ''" Include="$([Microsoft.Build.Utilities.ToolLocationHelper]::GetTargetPlatformReferences($(SDKIdentifier), $(SDKVersion), $(TargetPlatformIdentifier), $(TargetPlatformMinVersion), $(TargetPlatformVersion)))">
        <WinMDFile>true</WinMDFile>
        <CopyLocal>false</CopyLocal>
        <ReferenceGrouping>$(TargetPlatformMoniker)</ReferenceGrouping>
        <ReferenceGroupingDisplayName>$(TargetPlatformDisplayName)</ReferenceGroupingDisplayName>
        <ResolvedFrom>ImplicitlyExpandTargetPlatform</ResolvedFrom>
        <IsSystemReference>True</IsSystemReference>
      </_TargetPlatformWinMDs>
    </ItemGroup>

    <Warning Condition="'@(_TargetPlatformWinMDs)' == ''"
      Text="Could not find target platform winmds for the SDK specified by [$(SDKIdentifier), $(SDKVersion), $(TargetPlatformIdentifier), $(TargetPlatformMinVersion), $(TargetPlatformVersion)]"/>

    <Message Importance="Low" Text="Including @(_TargetPlatformWinMDs)" />

    <ItemGroup>
      <ReferencePath Include="@(_TargetPlatformWinMDs)" />
      <ReferencePath Include="$(FacadeWinmdPath)" Condition="Exists($(FacadeWinmdPath))"/>
      <_ResolveAssemblyReferenceResolvedFiles Include="@(_TargetPlatformWinMDs)" />

      <!-- Clear out 'temporary' variable -->
      <_TargetPlatformWinMDs Remove="@(_TargetPlatformWinMDs)" />
    </ItemGroup>
  </Target>

  <!-- 
      Enable warning when referenced projects have higher version than the current project
      for Windows Store projects 
    -->
  <PropertyGroup>
    <FindInvalidProjectReferences Condition="'$(TargetPlatformIdentifier)' == 'Windows' and 
                                              '$(TargetPlatformVersion)' &gt;= '8.0'">true</FindInvalidProjectReferences>
  </PropertyGroup>

  <!-- 
      Enable warning when referenced ESDKs do not have MaxPlatformVersion 
      specified for Windows Store projects 
    -->
  <PropertyGroup>
    <SDKReferenceWarnOnMissingMaxPlatformVersion Condition="'$(SDKReferenceWarnOnMissingMaxPlatformVersion)' == '' and 
                                                             '$(TargetPlatformIdentifier)' == 'Windows' and 
                                                             '$(TargetPlatformVersion)' &gt;= '8.0'">true</SDKReferenceWarnOnMissingMaxPlatformVersion>
  </PropertyGroup>


  <Import Project="ImportAfter\*"/>

</Project>
