| 1 | <?xml version="1.0" encoding="utf-8" ?> |
| 2 | <!-- 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. --> |
| 3 | |
| 4 | <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
| 5 | |
| 6 | <Import Project="$(CustomBeforeWixCATargets)" Condition=" '$(CustomBeforeWixCATargets)' != '' and Exists('$(CustomBeforeWixCATargets)')" /> |
| 7 | |
| 8 | <PropertyGroup> |
| 9 | <WixCATargetsImported>true</WixCATargetsImported> |
| 10 | |
| 11 | <TargetCAFileName Condition=" '$(TargetCAFileName)' == '' ">$(TargetName).CA$(TargetExt)</TargetCAFileName> |
| 12 | |
| 13 | <MakeSfxCAPath Condition=" '$(MakeSfxCAPath)' == '' ">$(MSBuildThisFileDirectory)..\tools\</MakeSfxCAPath> |
| 14 | |
| 15 | <MakeSfxCA Condition=" '$(MakeSfxCA)' == '' ">$(MakeSfxCAPath)WixToolset.Dtf.MakeSfxCA.exe</MakeSfxCA> |
| 16 | <SfxCADll Condition=" '$(SfxCADll)' == '' and '$(Platform)' == 'ARM64' ">$(MakeSfxCAPath)arm64\SfxCA.dll</SfxCADll> |
| 17 | <SfxCADll Condition=" '$(SfxCADll)' == '' and '$(Platform)' == 'x64' ">$(MakeSfxCAPath)x64\SfxCA.dll</SfxCADll> |
| 18 | <SfxCADll Condition=" '$(SfxCADll)' == '' ">$(MakeSfxCAPath)x86\SfxCA.dll</SfxCADll> |
| 19 | </PropertyGroup> |
| 20 | |
| 21 | <!-- |
| 22 | ================================================================================================== |
| 23 | PackCustomAction |
| 24 | |
| 25 | Creates an MSI managed custom action package that includes the custom action assembly, |
| 26 | local assembly dependencies, and project content files. This target is skipped until the |
| 27 | custom action assembly has been built. This prevents the target from running (and failing) |
| 28 | during project restore and other scenarios where the project is executed but the assembly |
| 29 | build is skipped. |
| 30 | |
| 31 | [IN] |
| 32 | @(IntermediateAssembly) - Managed custom action assembly. |
| 33 | @(Content) - Project items of type Content will be included in the package. |
| 34 | $(CustomActionContents) - Optional space-delimited list of additional files to include. |
| 35 | |
| 36 | [OUT] |
| 37 | $(IntermediateOutputPath)$(TargetCAFileName) - Managed custom action package with unmanaged stub. |
| 38 | ================================================================================================== |
| 39 | --> |
| 40 | <Target Name="PackCustomAction" |
| 41 | Inputs="@(IntermediateAssembly);@(Content);$(CustomActionContents)" |
| 42 | Outputs="$(IntermediateOutputPath)$(TargetCAFileName)" |
| 43 | Condition=" Exists('@(IntermediateAssembly)') "> |
| 44 | |
| 45 | <!-- Find all referenced items marked CopyLocal, but exclude non-binary files. --> |
| 46 | <ItemGroup> |
| 47 | <CustomActionReferenceContents Include="@(ReferenceCopyLocalPaths)" |
| 48 | Condition=" '%(Extension)' == '.dll' or '%(Extension)' == '.exe' " /> |
| 49 | <CustomActionReferenceContents Include="@(ReferenceComWrappersToCopyLocal)" |
| 50 | Condition=" '%(Extension)' == '.dll' or '%(Extension)' == '.exe' " /> |
| 51 | |
| 52 | <!-- include PDBs for Debug only --> |
| 53 | <CustomActionReferenceContents Include="@(IntermediateAssembly->'%(RootDir)%(Directory)%(Filename).pdb')" |
| 54 | Condition=" Exists('%(RootDir)%(Directory)%(Filename).pdb') and '$(Configuration)' == 'Debug' " /> |
| 55 | <CustomActionReferenceContents Include="@(ReferenceCopyLocalPaths)" |
| 56 | Condition=" '%(Extension)' == '.pdb' and '$(Configuration)' == 'Debug' " /> |
| 57 | <CustomActionReferenceContents Include="@(ReferenceComWrappersToCopyLocal)" |
| 58 | Condition=" '%(Extension)' == '.pdb' and '$(Configuration)' == 'Debug' " /> |
| 59 | </ItemGroup> |
| 60 | |
| 61 | <!-- |
| 62 | Items to include in the CA package: |
| 63 | - Reference assemblies marked CopyLocal |
| 64 | - Project items of type Content |
| 65 | - Additional items in the CustomActionContents property |
| 66 | --> |
| 67 | <ItemGroup> |
| 68 | <CustomActionContents Include="@(CustomActionReferenceContents);@(Content->'%(FullPath)');$(CustomActionContents)" /> |
| 69 | |
| 70 | <IntermediateCAResponseFile TaskParameter="Value" PropertyName="IntermediateCAResponseFile" /> |
| 71 | <IntermediateCAAssembly Include="@(IntermediateAssembly->'%(FullPath)')" /> |
| 72 | <IntermediateCAPackage Include="@(IntermediateAssembly->'%(RootDir)%(Directory)$(TargetCAFileName)')" /> |
| 73 | </ItemGroup> |
| 74 | |
| 75 | <!-- Use a response file to pass the potentially very long contents to MakeSfxCA.exe --> |
| 76 | <PropertyGroup> |
| 77 | <IntermediateCAResponseFile>@(IntermediateCAPackage->'%(RootDir)%(Directory)%(Filename).rsp')</IntermediateCAResponseFile> |
| 78 | </PropertyGroup> |
| 79 | |
| 80 | <WriteLinesToFile File="$(IntermediateCAResponseFile)" Lines="@(CustomActionContents->'"%(Identity)"')" Overwrite="true" /> |
| 81 | |
| 82 | <ItemGroup> |
| 83 | <FileWrites Include="$(IntermediateCAResponseFile)" /> |
| 84 | </ItemGroup> |
| 85 | |
| 86 | <!-- Run the MakeSfxCA.exe CA packaging tool. --> |
| 87 | <Exec Command='"$(MakeSfxCA)" "@(IntermediateCAPackage)" "$(SfxCADll)" "@(IntermediateCAAssembly)" "@$(IntermediateCAResponseFile)"' |
| 88 | WorkingDirectory="$(ProjectDir)" /> |
| 89 | |
| 90 | <!-- Add modules to be copied to output dir. --> |
| 91 | <ItemGroup> |
| 92 | <AddModules Include="@(IntermediateCAPackage)" /> |
| 93 | </ItemGroup> |
| 94 | </Target> |
| 95 | |
| 96 | <!-- |
| 97 | ================================================================================================== |
| 98 | CleanCustomAction |
| 99 | |
| 100 | Cleans the .CA.dll binary created by the PackCustomAction target. |
| 101 | |
| 102 | ================================================================================================== |
| 103 | --> |
| 104 | <Target Name="CleanCustomAction"> |
| 105 | <Delete Files="$(IntermediateOutputPath)$(TargetCAFileName)" |
| 106 | TreatErrorsAsWarnings="true" /> |
| 107 | </Target> |
| 108 | |
| 109 | <!-- |
| 110 | ================================================================================================== |
| 111 | AfterCompile (redefinition) |
| 112 | |
| 113 | Calls the PackCustomAction target after compiling. |
| 114 | Overrides the empty AfterCompile target from Microsoft.Common.targets. |
| 115 | |
| 116 | ================================================================================================== |
| 117 | --> |
| 118 | <Target Name="AfterCompile" |
| 119 | DependsOnTargets="PackCustomAction" /> |
| 120 | |
| 121 | <!-- |
| 122 | ================================================================================================== |
| 123 | BeforeClean (redefinition) |
| 124 | |
| 125 | Calls the CleanCustomAction target before cleaning. |
| 126 | Overrides the empty AfterCompile target from Microsoft.Common.targets. |
| 127 | |
| 128 | ================================================================================================== |
| 129 | --> |
| 130 | <Target Name="BeforeClean" |
| 131 | DependsOnTargets="CleanCustomAction" /> |
| 132 | |
| 133 | <Import Project="$(CustomAfterWixCATargets)" Condition=" '$(CustomAfterWixCATargets)' != '' and Exists('$(CustomAfterWixCATargets)')" /> |
| 134 | |
| 135 | </Project> |