1<?xml version="1.0" encoding="utf-8"?>
2<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
4    <Target Name="ProcessInstallFiles" AfterTargets="PrepareForBuild" Condition="@(InstallFiles) != ''">
5        <PropertyGroup>
6            <_FileListTarget>$(IntermediateOutputPath)$(MSBuildProjectName).g.csv</_FileListTarget>
7            <_InstallFilesTarget>$(IntermediateOutputPath)$(MSBuildProjectName).g.wxs</_InstallFilesTarget>
8        </PropertyGroup>
9
10        <ItemGroup>
11            <InstallFiles>
12                <_Source>%(Source)$([msbuild]::MakeRelative(%(SourceBase), %(FullPath)))</_Source>
13                <_Target>%(Target_)$([msbuild]::MakeRelative(%(TargetBase), %(FullPath)))</_Target>
14            </InstallFiles>
15
16            <_CatalogFiles Include="@(InstallFiles)" Condition="%(InstallFiles.IncludeInCat) and ''!=$([System.IO.File]::ReadAllText(%(InstallFiles.FullPath)))" />
17        </ItemGroup>
18
19        <WriteLinesToFile File="$(_FileListTarget)" Lines="@(InstallFiles->'&quot;%(_Source)&quot;,&quot;%(_Target)&quot;,&quot;%(Group)&quot;,&quot;%(DiskId)&quot;,&quot;%(Condition)&quot;')" Overwrite="true" />
20        <Exec Command='"$(PythonExe)" csv_to_wxs.py "$(_FileListTarget)" "$(_InstallFilesTarget)"'
21              WorkingDirectory="$(MSBuildThisFileDirectory)" />
22
23        <ItemGroup>
24            <FileWrites Include="$(_FileListTarget);$(_InstallFilesTarget)" />
25            <Compile Include="$(_InstallFilesTarget)" />
26        </ItemGroup>
27    </Target>
28
29    <Target Name="GenerateCatalog" AfterTargets="ProcessInstallFiles" Condition="'@(_CatalogFiles)' != ''">
30        <PropertyGroup>
31            <_CatFileSourceTarget>$(IntermediateOutputPath)$(MSBuildProjectName).cdf</_CatFileSourceTarget>
32            <_CatFileTarget>$(IntermediateOutputPath)python_$(MSBuildProjectName).cat</_CatFileTarget>
33            <_CatFile>[CatalogHeader]
34Name=$([System.IO.Path]::GetFileName($(_CatFileTarget)))
35ResultDir=$([System.IO.Path]::GetDirectoryName($(_CatFileTarget)))
36PublicVersion=1
37CatalogVersion=2
38HashAlgorithms=SHA256
39PageHashes=false
40EncodingType=
41
42[CatalogFiles]
43@(_CatalogFiles->'&lt;HASH&gt;%(Filename)%(Extension)=%(FullPath)','
44')
45</_CatFile>
46        </PropertyGroup>
47
48        <WriteLinesToFile File="$(_CatFileSourceTarget)" Lines="$(_CatFile)" Overwrite="true" />
49        <Exec Command='$(_MakeCatCommand) "$(_CatFileSourceTarget)"' WorkingDirectory="$(MSBuildThisFileDirectory)" />
50        <Exec Command='$(_SignCommand) "$(_CatFileTarget)"' WorkingDirectory="$(MSBuildThisFileDirectory)"
51              Condition="Exists($(_CatFileTarget)) and '$(_SignCommand)' != ''" />
52
53        <ItemGroup>
54            <FileWrites Include="$(_CatFileSourceTarget);$(_CatFileTarget)" />
55        </ItemGroup>
56    </Target>
57
58    <Target Name="_TransformWxlTemplates" AfterTargets="PrepareForBuild" Inputs="@(WxlTemplate);$(PySourcePath)include\patchlevel.h" Outputs="$(IntermediateOutputPath)%(Filename).wxl">
59        <PropertyGroup Condition="'@(WxlTemplate)' != ''">
60            <_Content>$([System.IO.File]::ReadAllText(%(WxlTemplate.FullPath)).Replace(`{{ShortVersion}}`, `$(MajorVersionNumber).$(MinorVersionNumber)$(PyTestExt)`).Replace(`{{LongVersion}}`, `$(PythonVersion)$(PyTestExt)`).Replace(`{{Bitness}}`, `$(Bitness)`))</_Content>
61            <_ExistingContent Condition="Exists('$(IntermediateOutputPath)%(WxlTemplate.Filename).wxl')">$([System.IO.File]::ReadAllText($(IntermediateOutputPath)%(WxlTemplate.Filename).wxl))</_ExistingContent>
62        </PropertyGroup>
63
64        <WriteLinesToFile File="$(IntermediateOutputPath)%(WxlTemplate.Filename).wxl"
65                          Lines="$(_Content)"
66                          Overwrite="true"
67                          Condition="$(_Content) != $(_ExistingContent)" />
68
69        <ItemGroup Condition="'@(WxlTemplate)' != ''">
70            <EmbeddedResource Include="$(IntermediateOutputPath)%(WxlTemplate.Filename).wxl" />
71            <FileWrites Include="$(IntermediateOutputPath)%(WxlTemplate.Filename).wxl" />
72        </ItemGroup>
73    </Target>
74
75    <Import Project="$(WixTargetsPath)" />
76
77    <Target Name="SignCabs">
78        <Error Text="Unable to locate signtool.exe. Set /p:SignToolPath and rebuild" Condition="'$(_SignCommand)' == ''" />
79        <Exec Command="$(_SignCommand) @(SignCabs->'&quot;%(FullPath)&quot;',' ')" ContinueOnError="false" />
80    </Target>
81    <Target Name="SignMsi">
82        <Error Text="Unable to locate signtool.exe. Set /p:SignToolPath and rebuild" Condition="'$(_SignCommand)' == ''" />
83        <Exec Command="$(_SignCommand) @(SignMsi->'&quot;%(FullPath)&quot;',' ')" ContinueOnError="false" />
84    </Target>
85    <Target Name="SignBundleEngine">
86        <Error Text="Unable to locate signtool.exe. Set /p:SignToolPath and rebuild" Condition="'$(_SignCommand)' == ''" />
87        <Exec Command="$(_SignCommand) @(SignBundleEngine->'&quot;%(FullPath)&quot;',' ')" ContinueOnError="false" />
88    </Target>
89    <Target Name="SignBundle">
90        <Error Text="Unable to locate signtool.exe. Set /p:SignToolPath and rebuild" Condition="'$(_SignCommand)' == ''" />
91        <Exec Command="$(_SignCommand) @(SignBundle->'&quot;%(FullPath)&quot;',' ')" ContinueOnError="false" />
92    </Target>
93</Project>