aboutsummaryrefslogtreecommitdiff
path: root/src/dtf/WixToolset.Dtf.CustomAction/WixToolset.Dtf.CustomAction.targets
blob: e83272a2ade11060d4e935e7fffa7ee80d92983f (plain)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. -->

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

  <Import Project="$(CustomBeforeWixCATargets)" Condition=" '$(CustomBeforeWixCATargets)' != '' and Exists('$(CustomBeforeWixCATargets)')" />

  <PropertyGroup>
    <WixCATargetsImported>true</WixCATargetsImported>

    <TargetCAFileName Condition=" '$(TargetCAFileName)' == '' ">$(TargetName).CA$(TargetExt)</TargetCAFileName>

    <MakeSfxCAPath Condition=" '$(MakeSfxCAPath)' == '' ">$(MSBuildThisFileDirectory)..\tools\</MakeSfxCAPath>

    <MakeSfxCA Condition=" '$(MakeSfxCA)' == '' ">$(MakeSfxCAPath)WixToolset.Dtf.MakeSfxCA.exe</MakeSfxCA>
    <SfxCADll Condition=" '$(SfxCADll)' == '' and '$(Platform)' == 'ARM64' ">$(MakeSfxCAPath)arm64\SfxCA.dll</SfxCADll>
    <SfxCADll Condition=" '$(SfxCADll)' == '' and '$(Platform)' == 'x64' ">$(MakeSfxCAPath)x64\SfxCA.dll</SfxCADll>
    <SfxCADll Condition=" '$(SfxCADll)' == '' ">$(MakeSfxCAPath)x86\SfxCA.dll</SfxCADll>
  </PropertyGroup>

  <!--
  ==================================================================================================
  PackCustomAction

    Creates an MSI managed custom action package that includes the custom action assembly,
    local assembly dependencies, and project content files. This target is skipped until the
    custom action assembly has been built. This prevents the target from running (and failing)
    during project restore and other scenarios where the project is executed but the assembly
    build is skipped.

    [IN]
    @(IntermediateAssembly) - Managed custom action assembly.
    @(Content) - Project items of type Content will be included in the package.
    $(CustomActionContents) - Optional space-delimited list of additional files to include.

    [OUT]
    $(IntermediateOutputPath)$(TargetCAFileName) - Managed custom action package with unmanaged stub.
  ==================================================================================================
  -->
  <Target Name="PackCustomAction"
          Inputs="@(IntermediateAssembly);@(Content);$(CustomActionContents)"
          Outputs="$(IntermediateOutputPath)$(TargetCAFileName)"
          Condition=" Exists('@(IntermediateAssembly)') ">

    <!-- Find all referenced items marked CopyLocal, but exclude non-binary files. -->
    <ItemGroup>
      <CustomActionReferenceContents Include="@(ReferenceCopyLocalPaths)"
                                     Condition=" '%(Extension)' == '.dll' or '%(Extension)' == '.exe' " />
      <CustomActionReferenceContents Include="@(ReferenceComWrappersToCopyLocal)"
                                     Condition=" '%(Extension)' == '.dll' or '%(Extension)' == '.exe' " />

      <!-- include PDBs for Debug only -->
      <CustomActionReferenceContents Include="@(IntermediateAssembly->'%(RootDir)%(Directory)%(Filename).pdb')"
                                     Condition=" Exists('%(RootDir)%(Directory)%(Filename).pdb') and '$(Configuration)' == 'Debug' " />
      <CustomActionReferenceContents Include="@(ReferenceCopyLocalPaths)"
                                     Condition=" '%(Extension)' == '.pdb' and '$(Configuration)' == 'Debug' " />
      <CustomActionReferenceContents Include="@(ReferenceComWrappersToCopyLocal)"
                                     Condition=" '%(Extension)' == '.pdb' and '$(Configuration)' == 'Debug' " />
    </ItemGroup>

    <!--
      Items to include in the CA package:
         - Reference assemblies marked CopyLocal
         - Project items of type Content
         - Additional items in the CustomActionContents property
    -->
    <ItemGroup>
      <CustomActionContents Include="@(CustomActionReferenceContents);@(Content->'%(FullPath)');$(CustomActionContents)" />

      <IntermediateCAResponseFile TaskParameter="Value" PropertyName="IntermediateCAResponseFile" />
      <IntermediateCAAssembly Include="@(IntermediateAssembly->'%(FullPath)')" />
      <IntermediateCAPackage Include="@(IntermediateAssembly->'%(RootDir)%(Directory)$(TargetCAFileName)')" />
    </ItemGroup>

    <!-- Use a response file to pass the potentially very long contents to MakeSfxCA.exe -->
    <PropertyGroup>
      <IntermediateCAResponseFile>@(IntermediateCAPackage->'%(RootDir)%(Directory)%(Filename).rsp')</IntermediateCAResponseFile>
    </PropertyGroup>

    <WriteLinesToFile File="$(IntermediateCAResponseFile)" Lines="@(CustomActionContents->'&quot;%(Identity)&quot;')" Overwrite="true" />

    <ItemGroup>
      <FileWrites Include="$(IntermediateCAResponseFile)" />
    </ItemGroup>

    <!-- Run the MakeSfxCA.exe CA packaging tool. -->
    <Exec Command='"$(MakeSfxCA)" "@(IntermediateCAPackage)" "$(SfxCADll)" "@(IntermediateCAAssembly)" "@$(IntermediateCAResponseFile)"'
          WorkingDirectory="$(ProjectDir)" />

    <!-- Add modules to be copied to output dir. -->
    <ItemGroup>
      <AddModules Include="@(IntermediateCAPackage)" />
    </ItemGroup>
  </Target>

  <!--
  ==================================================================================================
  CleanCustomAction

    Cleans the .CA.dll binary created by the PackCustomAction target.

  ==================================================================================================
  -->
  <Target Name="CleanCustomAction">
    <Delete Files="$(IntermediateOutputPath)$(TargetCAFileName)"
            TreatErrorsAsWarnings="true" />
  </Target>

  <!--
  ==================================================================================================
  AfterCompile (redefinition)

    Calls the PackCustomAction target after compiling.
    Overrides the empty AfterCompile target from Microsoft.Common.targets.

  ==================================================================================================
  -->
  <Target Name="AfterCompile"
          DependsOnTargets="PackCustomAction" />

  <!--
  ==================================================================================================
  BeforeClean (redefinition)

    Calls the CleanCustomAction target before cleaning.
    Overrides the empty AfterCompile target from Microsoft.Common.targets.

  ==================================================================================================
  -->
  <Target Name="BeforeClean"
          DependsOnTargets="CleanCustomAction" />

  <Import Project="$(CustomAfterWixCATargets)" Condition=" '$(CustomAfterWixCATargets)' != '' and Exists('$(CustomAfterWixCATargets)')" />

</Project>