<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <!-- Import default properties if not done yet. This does not overwrite any previously defined properties. -->
  <Import Condition="'$(VcpkgPropsImported)' != 'true'" Project="vcpkg.props" />

  <!-- VS2015's version of "vcpkg integrate install" imports both the props and targets together in the "props" area,
  meaning we have no opportunity to respond to user customizations in their project files. It also means that this
  .targets must defend against normal properties being unset. (For example, VcpkgPlatformTarget below.)

  Also, we copy all initial values to internal values to avoid properties being inconsistently evaluated in targets
  and dependent properties.
  -->

  <PropertyGroup>
    <_ZVcpkgRoot>$(VcpkgRoot)</_ZVcpkgRoot>
    <_ZVcpkgManifestRoot>$(VcpkgManifestRoot)</_ZVcpkgManifestRoot>
    <_ZVcpkgInstalledDir>$(VcpkgInstalledDir)</_ZVcpkgInstalledDir>
    <_ZVcpkgManifestInstalledBaseDir>$(VcpkgManifestInstalledBaseDir)</_ZVcpkgManifestInstalledBaseDir>
  </PropertyGroup>

  <!-- Add trailing slashes to inputs that must have them to conform with msbuild conventions. -->
  <PropertyGroup>
    <_ZVcpkgRoot Condition="!$(_ZVcpkgRoot.EndsWith('\'))">$(_ZVcpkgRoot)\</_ZVcpkgRoot>
    <_ZVcpkgManifestRoot Condition="'$(_ZVcpkgManifestRoot)' != '' and !$(_ZVcpkgManifestRoot.EndsWith('\'))">$(_ZVcpkgManifestRoot)\</_ZVcpkgManifestRoot>
    <_ZVcpkgInstalledDir Condition="'$(_ZVcpkgInstalledDir)' != '' and !$(_ZVcpkgInstalledDir.EndsWith('\'))">$(_ZVcpkgInstalledDir)\</_ZVcpkgInstalledDir>
    <_ZVcpkgManifestInstalledBaseDir Condition="'$(_ZVcpkgManifestInstalledBaseDir)' != '' and !$(_ZVcpkgManifestInstalledBaseDir.EndsWith('\'))">$(_ZVcpkgManifestInstalledBaseDir)\</_ZVcpkgManifestInstalledBaseDir>
  </PropertyGroup>

  <PropertyGroup>
    <_ZVcpkgClassicOrManifest Condition="'$(VcpkgEnabled)' == 'true' And ('$(VcpkgEnableClassic)' == 'true' Or '$(VcpkgEnableManifest)' == 'true')">true</_ZVcpkgClassicOrManifest>
    <_ZVcpkgClassicOrManifest Condition="'$(_ZVcpkgClassicOrManifest)' == ''">false</_ZVcpkgClassicOrManifest>
  </PropertyGroup>

  <!-- Special-case custom MSBuild platforms defined in the Microsoft GDK. See https://aka.ms/gdk and https://aka.ms/gdkx -->
  <PropertyGroup Condition="'$(VcpkgOSTarget)' == '' AND '$(VcpkgPlatformTarget)' == '' AND '$(Platform)'=='Gaming.Desktop.x64'">
    <VcpkgOSTarget>windows</VcpkgOSTarget>
    <VcpkgPlatformTarget>x64</VcpkgPlatformTarget>
    <VcpkgUseMD>true</VcpkgUseMD>
  </PropertyGroup>
  <PropertyGroup Condition="'$(VcpkgOSTarget)' == '' AND '$(VcpkgPlatformTarget)' == '' AND '$(Platform)'=='Gaming.Xbox.Scarlett.x64'">
    <VcpkgOSTarget>xbox-scarlett</VcpkgOSTarget>
    <VcpkgPlatformTarget>x64</VcpkgPlatformTarget>
    <VcpkgUseMD>false</VcpkgUseMD>
  </PropertyGroup>
  <PropertyGroup Condition="'$(VcpkgOSTarget)' == '' AND '$(VcpkgPlatformTarget)' == '' AND '$(Platform)'=='Gaming.Xbox.XboxOne.x64'">
    <VcpkgOSTarget>xbox-xboxone</VcpkgOSTarget>
    <VcpkgPlatformTarget>x64</VcpkgPlatformTarget>
    <VcpkgUseMD>false</VcpkgUseMD>
  </PropertyGroup>

  <!-- Determine the triplet to use. Note that $(PlatformTarget) is not available at the top of the .vcxproj file. -->
  <PropertyGroup Condition="'$(VcpkgOSTarget)' == ''">
    <VcpkgOSTarget>windows</VcpkgOSTarget>
    <VcpkgOSTarget Condition="'$(AppContainerApplication)' == 'true'">uwp</VcpkgOSTarget>
  </PropertyGroup>

  <PropertyGroup Condition="'$(VcpkgPlatformTarget)' == ''">
    <VcpkgPlatformTarget>$(Platform.ToLower())</VcpkgPlatformTarget>
    <VcpkgPlatformTarget Condition="'$(VcpkgPlatformTarget)' == 'win32'">x86</VcpkgPlatformTarget>
  </PropertyGroup>

  <PropertyGroup>
    <_ZVcpkgLinkage />
    <_ZVcpkgLinkage Condition="'$(VcpkgUseStatic)' == 'true'">-static</_ZVcpkgLinkage>
    <_ZVcpkgLinkageMD />
    <_ZVcpkgLinkageMD Condition="'$(VcpkgUseStatic)' == 'true' and '$(VcpkgUseMD)' == 'true'">-md</_ZVcpkgLinkageMD>
    <VcpkgTriplet Condition="'$(VcpkgTriplet)' == ''">$(VcpkgPlatformTarget)-$(VcpkgOSTarget)$(_ZVcpkgLinkage)$(_ZVcpkgLinkageMD)</VcpkgTriplet>
    <VcpkgTriplet Condition="!$(VcpkgTriplet.EndsWith($(_ZVcpkgLinkage)$(_ZVcpkgLinkageMD)))">$(VcpkgTriplet)$(_ZVcpkgLinkage)$(_ZVcpkgLinkageMD)</VcpkgTriplet>
  </PropertyGroup>

  <!-- Include the triplet in ProjectStateLine to force VS2017 and later to fully rebuild if the user changes it.  -->
  <PropertyGroup>
    <ProjectStateLine>VcpkgTriplet=$(VcpkgTriplet):$(ProjectStateLine)</ProjectStateLine>
  </PropertyGroup>

  <!-- Determine the locations trees we want to consume. _ZVcpkgManifestInstalledBaseDir and _ZVcpkgInstalledDir are
  special in that it doesn't have a default value in the .props because we normally derive it, but users may override
  the value. -->
  <Choose>
    <When Condition="'$(VcpkgEnableManifest)' == 'true'">
      <PropertyGroup>
        <_ZVcpkgManifestInstalledBaseDir Condition="'$(_ZVcpkgManifestInstalledBaseDir)' == ''">$(_ZVcpkgManifestRoot)vcpkg_installed\</_ZVcpkgManifestInstalledBaseDir>
        <_ZVcpkgInstalledDir Condition="'$(_ZVcpkgInstalledDir)' == ''">$(_ZVcpkgManifestInstalledBaseDir)$(VcpkgTriplet)\</_ZVcpkgInstalledDir>
      </PropertyGroup>
    </When>
    <Otherwise>
      <PropertyGroup>
        <_ZVcpkgInstalledDir Condition="'$(_ZVcpkgInstalledDir)' == ''">$(_ZVcpkgRoot)installed\</_ZVcpkgInstalledDir>
      </PropertyGroup>
    </Otherwise>
  </Choose>

  <PropertyGroup>
    <_ZVcpkgCurrentInstalledDir>$(_ZVcpkgInstalledDir)$(VcpkgTriplet)\</_ZVcpkgCurrentInstalledDir>
    <_ZVcpkgNormalizedConfiguration Condition="$(VcpkgConfiguration.StartsWith('Debug'))">Debug</_ZVcpkgNormalizedConfiguration>
    <_ZVcpkgNormalizedConfiguration Condition="$(VcpkgConfiguration.StartsWith('Release')) or '$(VcpkgConfiguration)' == 'RelWithDebInfo' or '$(VcpkgConfiguration)' == 'MinSizeRel'">Release</_ZVcpkgNormalizedConfiguration>

    <_ZVcpkgConfigSubdir Condition="'$(_ZVcpkgNormalizedConfiguration)' == 'Debug'">debug\</_ZVcpkgConfigSubdir>
    <_ZVcpkgExecutable>$(_ZVcpkgRoot)vcpkg.exe</_ZVcpkgExecutable>
    <ExternalIncludePath Condition="'$(_ZVcpkgClassicOrManifest)' == 'true'">$(ExternalIncludePath);$(_ZVcpkgCurrentInstalledDir)include</ExternalIncludePath>
  </PropertyGroup>

  <PropertyGroup>
    <!-- Note: Overwrite VcpkgPageSchema with a non-existing path to disable the VcPkg property sheet in your projects -->
    <VcpkgPageSchema Condition="'$(VcpkgPageSchema)' == ''">$(_ZVcpkgRoot)scripts\buildsystems\msbuild\vcpkg-general.xml</VcpkgPageSchema>
  </PropertyGroup>

  <ItemGroup Condition="'$(VcpkgPageSchema)' != '' and exists('$(VcpkgPageSchema)') and '$(MSBuildToolsVersion)' != '14.0'">
    <PropertyPageSchema Include="$(VcpkgPageSchema)">
      <Context>Project</Context>
    </PropertyPageSchema>
  </ItemGroup>

  <!-- Install settings to get headers and import libs for the currently selected _ZVcpkgCurrentInstalledDir -->
  <ItemDefinitionGroup Condition="'$(_ZVcpkgClassicOrManifest)' == 'true'">
    <Lib>
      <AdditionalLibraryDirectories>%(AdditionalLibraryDirectories);$(_ZVcpkgCurrentInstalledDir)$(_ZVcpkgConfigSubdir)lib;$(_ZVcpkgCurrentInstalledDir)$(_ZVcpkgConfigSubdir)lib\manual-link</AdditionalLibraryDirectories>
    </Lib>
    <Link>
      <AdditionalDependencies Condition="'$(VcpkgAutoLink)' != 'false'">%(AdditionalDependencies);$(_ZVcpkgCurrentInstalledDir)$(_ZVcpkgConfigSubdir)lib\*.lib</AdditionalDependencies>
      <AdditionalLibraryDirectories>%(AdditionalLibraryDirectories);$(_ZVcpkgCurrentInstalledDir)$(_ZVcpkgConfigSubdir)lib;$(_ZVcpkgCurrentInstalledDir)$(_ZVcpkgConfigSubdir)lib\manual-link</AdditionalLibraryDirectories>
    </Link>
    <ClCompile>
      <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(_ZVcpkgCurrentInstalledDir)include</AdditionalIncludeDirectories>
    </ClCompile>
    <ResourceCompile>
      <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(_ZVcpkgCurrentInstalledDir)include</AdditionalIncludeDirectories>
    </ResourceCompile>
  </ItemDefinitionGroup>

  <Target Name="VcpkgCheckManifestRoot" BeforeTargets="VcpkgInstallManifestDependencies" Condition="'$(VcpkgEnabled)' == 'true'">
    <Error Text="The vcpkg manifest was enabled, but we couldn't find a manifest file (vcpkg.json) in any directories above $(MSBuildProjectDirectory). Please add a manifest, disable manifests in your properties page, or pass /p:VcpkgEnableManifest=false."
           Condition="'$(VcpkgEnableManifest)' == 'true' and '$(_ZVcpkgManifestRoot)' == ''" />
    <Message Text="The vcpkg manifest was disabled, but we found a manifest file in $(_ZVcpkgManifestRoot). You may want to enable vcpkg manifests in your properties page or pass /p:VcpkgEnableManifest=true to the msbuild invocation."
             Importance="High" Condition="'$(VcpkgEnableManifest)' != 'true' and '$(_ZVcpkgManifestRoot)' != ''" />
  </Target>

  <Target Name="VcpkgTripletSelection" BeforeTargets="ClCompile" Condition="'$(_ZVcpkgClassicOrManifest)' == 'true'">
    <Message Text="Using triplet &quot;$(VcpkgTriplet)&quot; from &quot;$(_ZVcpkgCurrentInstalledDir)&quot;"
             Importance="Normal" Condition="'$(VcpkgEnabled)' == 'true'"/>
    <Message Text="Using normalized configuration &quot;$(_ZVcpkgNormalizedConfiguration)&quot;"
             Importance="Normal" Condition="'$(VcpkgEnabled)' == 'true'"/>
    <Message Text="Not using Vcpkg because VcpkgEnabled is &quot;$(VcpkgEnabled)&quot;"
             Importance="Normal" Condition="'$(VcpkgEnabled)' != 'true'"/>
    <Message Text="Vcpkg is unable to link because we cannot decide between Release and Debug libraries. Please define the property VcpkgConfiguration to be 'Release' or 'Debug' (currently '$(VcpkgConfiguration)')."
             Importance="High" Condition="'$(VcpkgEnabled)' == 'true' and '$(_ZVcpkgNormalizedConfiguration)' == ''"/>
  </Target>

  <Choose>
    <When Condition="'$(VcpkgHostTriplet)' != ''">
      <PropertyGroup>
        <_ZVcpkgHostTripletParameter>"--host-triplet=$(VcpkgHostTriplet)"</_ZVcpkgHostTripletParameter>
        <_ZVcpkgHostTripletSuffix>$(VcpkgHostTriplet).</_ZVcpkgHostTripletSuffix>
      </PropertyGroup>
    </When>
    <Otherwise>
      <PropertyGroup>
        <_ZVcpkgHostTripletParameter />
        <_ZVcpkgHostTripletSuffix />
      </PropertyGroup>
    </Otherwise>
  </Choose>

  <PropertyGroup>
    <_ZVcpkgManifestFileLocation>$(_ZVcpkgManifestRoot)vcpkg.json</_ZVcpkgManifestFileLocation>
    <_ZVcpkgConfigurationFileLocation>$(_ZVcpkgManifestRoot)vcpkg-configuration.json</_ZVcpkgConfigurationFileLocation>
    <_ZVcpkgMSBuildStampFile>$(_ZVcpkgInstalledDir).msbuildstamp-$(VcpkgTriplet).$(_ZVcpkgHostTripletSuffix)stamp</_ZVcpkgMSBuildStampFile>
  </PropertyGroup>

  <ItemGroup Condition="'$(VcpkgEnabled)' == 'true' and '$(VcpkgEnableManifest)' == 'true' and '$(VcpkgManifestInstall)' == 'true'">
    <_ZVcpkgInstallManifestDependenciesInputs Include="$(_ZVcpkgManifestFileLocation)"/>
    <_ZVcpkgInstallManifestDependenciesInputs Include="$(_ZVcpkgConfigurationFileLocation)" Condition="Exists('$(_ZVcpkgConfigurationFileLocation)')"/>
  </ItemGroup>

  <!-- Import 'support\Bootstrap.targets' to bootstrap Vcpkg if we can. Only import if:
    1. If VcpkgEnableManifest is true - Vcpkg needs to be bootstrapped only in manifest mode.
    2. If VcpkgAutoBootstrap is true - VcpkgAutoBootstrap allows consumers to opt-out.
    3. The OS is Windows.
    4. The 'bootstrap'-script is present in the Vcpkg root directory - When 'vcpkg' is redistributed through mechanisms that don't need bootstrapping, the script isn't present so we shouldn't attempt to run it.
  -->
  <Import Condition="'$(VcpkgEnableManifest)' == 'true' and '$(VcpkgAutoBootstrap)' == 'true' and $([MSBuild]::IsOSPlatform('Windows')) and Exists('$(_ZVcpkgRoot)bootstrap-vcpkg.bat')"
          Project="$(MSBuildThisFileDirectory)\support\Bootstrap.targets" />
  <Import Project="$(MSBuildThisFileDirectory)support\GetVcpkgEnvVars.task" 
          Condition="'$(VcpkgEnabled)' == 'true' and '$(VcpkgEnableManifest)' == 'true' and '$(VcpkgManifestInstall)' == 'true'"
  />
  <Import Project="$(MSBuildThisFileDirectory)support\GetGlobalProperties.task"
          Condition="'$(VcpkgEnabled)' == 'true' and '$(VcpkgEnableManifest)' == 'true' and '$(VcpkgManifestInstall)' == 'true' and '$(_ZVcpkgGetGlobalPropertiesImported)' != 'true'"
  />

  <Target Name="VcpkgInstallManifestDependencies" BeforeTargets="ClCompile"
          Condition="'$(VcpkgEnabled)' == 'true' and '$(VcpkgEnableManifest)' == 'true' and '$(VcpkgManifestInstall)' == 'true'"
          Inputs="@(_ZVcpkgInstallManifestDependenciesInputs)"
          Outputs="$(_ZVcpkgMSBuildStampFile)">
    <GetGlobalProperties>
      <Output TaskParameter="GlobalPropertyNames" PropertyName="_ZVcpkgGlobalPropertyNames" />
    </GetGlobalProperties>
    <GetVcpkgEnvVars>
      <Output TaskParameter="VcpkgEnvVars" PropertyName="_ZVcpkgEnvVars" />
    </GetVcpkgEnvVars>

    <!-- This is set inside the target because $(TLogLocation) may not be set yet when parsing the .targets on VS2015 -->
    <PropertyGroup>
      <_ZVcpkgTLogFileLocation>$(TLogLocation)VcpkgInstallManifest$(VcpkgTriplet).$(_ZVcpkgHostTripletSuffix)read.1u.tlog</_ZVcpkgTLogFileLocation>
    </PropertyGroup>
    <MSBuild BuildInParallel="true"
             Projects="$(MSBuildThisFileDirectory)\support\InstallImplementation.targets"
             Targets="VcpkgInstallImplementation"
             RemoveProperties="$(_ZVcpkgGlobalPropertyNames)"
             Properties="_ZVcpkgMSBuildStampFile=$(_ZVcpkgMSBuildStampFile);_ZVcpkgRoot=$(_ZVcpkgRoot);_ZVcpkgHostTripletSuffix=$(_ZVcpkgHostTripletSuffix);_ZVcpkgInstalledDir=$(_ZVcpkgInstalledDir);_ZVcpkgExecutable=$(_ZVcpkgExecutable);_ZVcpkgHostTripletParameter=$(_ZVcpkgHostTripletParameter);VcpkgTriplet=$(VcpkgTriplet);_ZVcpkgManifestRoot=$(_ZVcpkgManifestRoot);VcpkgAdditionalInstallOptions=$([MSBuild]::Escape($(VcpkgAdditionalInstallOptions)));_ZVcpkgEnvVars=$(_ZVcpkgEnvVars)"
    />
    <WriteLinesToFile File="$(_ZVcpkgTLogFileLocation)"
                      Lines="@(_ZVcpkgInstallManifestDependenciesInputs -> '^%(Identity)')"
                      Encoding="Unicode"
                      Overwrite="true"/>

    <CreateProperty Value="false">
      <Output TaskParameter="ValueSetByTask" PropertyName="Link_MinimalRebuildFromTracking" />
    </CreateProperty>
  </Target>

  <Target Name="AppLocalFromInstalled" AfterTargets="CopyFilesToOutputDirectory" BeforeTargets="CopyLocalFilesOutputGroup;RegisterOutput"
          Condition="'$(_ZVcpkgClassicOrManifest)' == 'true' and '$(VcpkgApplocalDeps)' == 'true' and '$(LinkSkippedExecution)' != 'true' and '@(Link)' != ''">
    <Message Text="[vcpkg] Starting VcpkgApplocalDeps" Importance="low" />
    <PropertyGroup>
      <_ZVcpkgApplocalInstalledBinDir>$(_ZVcpkgCurrentInstalledDir)$(_ZVcpkgConfigSubdir)bin</_ZVcpkgApplocalInstalledBinDir>
      <_ZVcpkgApplocalTLogPath>$(TLogLocation)$(ProjectName).write.1u.tlog</_ZVcpkgApplocalTLogPath>
      <_ZVcpkgApplocalCopiedFilesLogPath>$(IntDir)vcpkg.applocal.log</_ZVcpkgApplocalCopiedFilesLogPath>
      <_ZVcpkgApplocalBuiltinArguments>--target-binary="$(TargetPath)" --installed-bin-dir="$(_ZVcpkgApplocalInstalledBinDir)" --tlog-file="$(_ZVcpkgApplocalTLogPath)" --copied-files-log="$(_ZVcpkgApplocalCopiedFilesLogPath)"</_ZVcpkgApplocalBuiltinArguments>
      <_ZVcpkgAppLocalPowerShellCommonArguments>-ExecutionPolicy Bypass -noprofile -File "$(MSBuildThisFileDirectory)applocal.ps1" "$(TargetPath)" "$(_ZVcpkgApplocalInstalledBinDir)" "$(_ZVcpkgApplocalTLogPath)" "$(_ZVcpkgApplocalCopiedFilesLogPath)"</_ZVcpkgAppLocalPowerShellCommonArguments>
    </PropertyGroup>
    <Exec
      Condition="'$(VcpkgXUseBuiltInApplocalDeps)' == 'true'"
      Command="%22$(_ZVcpkgExecutable)%22 z-applocal $(_ZVcpkgApplocalBuiltinArguments)"
      UseUtf8Encoding="Always"
      StdOutEncoding="utf-8"
      StdErrEncoding="utf-8"
      UseCommandProcessor="false"
      IgnoreExitCode="true">
      <Output TaskParameter="ExitCode"
              PropertyName="_ZVcpkgAppLocalExitCode" />
    </Exec>
    <Warning Text="[vcpkg] Failed to gather app local DLL dependencies, program may not run. Set VcpkgApplocalDeps to false in your project file to suppress this warning. Builtin arguments: $(_ZVcpkgApplocalBuiltinArguments)"
      Condition="$(_ZVcpkgAppLocalExitCode) != 0 and '$(VcpkgXUseBuiltInApplocalDeps)' == 'true'"/>

    <!-- Search %PATH% for pwsh.exe if it is available. -->
    <Exec
      Condition="'$(VcpkgXUseBuiltInApplocalDeps)' != 'true'"
      Command="pwsh.exe $(_ZVcpkgAppLocalPowerShellCommonArguments)"
      IgnoreExitCode="true"
      UseCommandProcessor="false">
      <Output TaskParameter="ExitCode"
              PropertyName="_ZVcpkgAppLocalExitCode" />
    </Exec>
    <!-- Fall back to well known system PowerShell location otherwise. -->
    <Message Text="[vcpkg] Failed to run applocal.ps1 using pwsh, falling back to system PowerShell." Importance="low"
             Condition="$(_ZVcpkgAppLocalExitCode) == 9009" />
    <Exec
      Command="%22$(SystemRoot)\System32\WindowsPowerShell\v1.0\powershell.exe%22 $(_ZVcpkgAppLocalPowerShellCommonArguments)"
      IgnoreExitCode="true"
      UseCommandProcessor="false"
      Condition="$(_ZVcpkgAppLocalExitCode) == 9009 and '$(VcpkgXUseBuiltInApplocalDeps)' != 'true'">
      <Output TaskParameter="ExitCode"
              PropertyName="_ZVcpkgAppLocalExitCode" />
    </Exec>
    <!-- We're ignoring the above exit codes, so translate into a warning if both failed. -->
    <Warning Text="[vcpkg] Failed to gather app local DLL dependencies, program may not run. Set VcpkgApplocalDeps to false in your project file to suppress this warning. PowerShell arguments: $(_ZVcpkgAppLocalPowerShellCommonArguments)"
      Condition="$(_ZVcpkgAppLocalExitCode) != 0 and '$(VcpkgXUseBuiltInApplocalDeps)' != 'true'"/>

    <ReadLinesFromFile File="$(IntDir)vcpkg.applocal.log"
      Condition="$(_ZVcpkgAppLocalExitCode) == 0">
      <Output TaskParameter="Lines" ItemName="VcpkgAppLocalDLLs" />
    </ReadLinesFromFile>
    <Message Text="@(VcpkgAppLocalDLLs,'%0A')" Importance="Normal" Condition="$(_ZVcpkgAppLocalExitCode) == 0" />
    <ItemGroup Condition="$(_ZVcpkgAppLocalExitCode) == 0">
      <ReferenceCopyLocalPaths Include="@(VcpkgAppLocalDLLs)" />
      <!-- Register the deployed DLLs as file writes so MSBuild's IncrementalClean
           doesn't treat them as orphan outputs and delete them. Without this, any
           clean-file entries recorded by AppLocalFromInstalledPreserve on a previous
           link-skipped build cause IncrementalClean to delete the DLLs on the next
           build where the link runs, immediately after they were deployed. The paths
           are re-based to $(OutDir) because z-applocal logs source paths while
           applocal.ps1 logs destination paths. -->
      <FileWrites Include="@(VcpkgAppLocalDLLs -> '$(OutDir)%(Filename)%(Extension)')" />
    </ItemGroup>
  </Target>

  <!--
    When the link step is skipped (incremental build, exe up-to-date),
    AppLocalFromInstalled doesn't run, so DLLs it previously copied aren't
    registered in FileWrites. MSBuild's IncrementalClean then treats them as
    orphan outputs and deletes them. This target re-registers those DLLs so
    IncrementalClean leaves them alone.
  -->
  <Target Name="AppLocalFromInstalledPreserve"
          AfterTargets="CopyFilesToOutputDirectory"
          BeforeTargets="_CleanGetCurrentAndPriorFileWrites"
          Condition="'$(_ZVcpkgClassicOrManifest)' == 'true'
                     and '$(VcpkgApplocalDeps)' == 'true'
                     and '$(LinkSkippedExecution)' == 'true'
                     and '@(Link)' != ''">
    <ReadLinesFromFile File="$(IntDir)vcpkg.applocal.log"
                       Condition="Exists('$(IntDir)vcpkg.applocal.log')">
      <Output TaskParameter="Lines" ItemName="_ZVcpkgPreservedAppLocalDLLs" />
    </ReadLinesFromFile>
    <ItemGroup>
      <FileWrites Include="@(_ZVcpkgPreservedAppLocalDLLs -> '$(OutDir)%(Filename)%(Extension)')" />
    </ItemGroup>
  </Target>
</Project>
