forked from microsoft/CsWinRT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Microsoft.Windows.CsWinRT.IIDOptimizer.targets
88 lines (72 loc) · 4.71 KB
/
Microsoft.Windows.CsWinRT.IIDOptimizer.targets
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
<!--
***********************************************************************************************
Copyright (C) Microsoft Corporation. All rights reserved.
***********************************************************************************************
-->
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- For the IIDOptimizer to work, it needs to be given all the (reference) assemblies used during compilation
This target consolidates them based on an item group output by the CoreCompile target,
so they may be passed as an option to the IIDOptimizer in the target that invokes the tool -->
<Target Name="CsWinRTGenerateIIDOptimizerResponseFile"
AfterTargets="Compile"
BeforeTargets="CsWinRTInvokeGuidPatcher"
Condition="'$(DesignTimeBuild)' == ''">
<PropertyGroup>
<!-- CsWinRTIIDOptimizerPath: If building in the CsWinRT Repo, then this is set already via Directory.Build.props -->
<CsWinRTIIDOptimizerPath Condition="'$(CsWinRTIIDOptimizerPath)' == ''">$(CsWinRTPath)build\tools\IIDOptimizer\</CsWinRTIIDOptimizerPath>
<!-- CsWinRTIIDOptimizerTargetAssembly: First argument to the IIDOptimizer.
We are using the output's .dll from the *obj* folder.
After linking, the output's .dll gets copied to the bin folder. These targets run before linking. -->
<CsWinRTIIDOptimizerTargetAssembly>@(BuiltProjectOutputGroupKeyOutput->'%(Identity)')</CsWinRTIIDOptimizerTargetAssembly>
<!-- IIDOptimizerInterimDir: Second argument to the IIDOptimizer.
The folder used by the IIDOptimizer to save output files -->
<IIDOptimizerInterimDir>$([MSBuild]::NormalizeDirectory('$(MSBuildProjectDirectory)', '$(IntermediateOutputPath)', 'IIDOptimizer'))</IIDOptimizerInterimDir>
<!-- GuidPatchTargetAssemblyReferences: third argument to the IIDOptimizer.
We use ReferencePathWithRefAssemblies as this is passed to Csc (C# Compile Task) for the TargetAssembly's References -->
<GuidPatchTargetAssemblyReferences>@(ReferencePathWithRefAssemblies->'--refs 
 %(Identity)', '
')</GuidPatchTargetAssemblyReferences>
<!-- GuidPatchParams: Used to write the response file (.rsp) when executing IIDOptimizer.
include the current dll, the folder to winrt.runtime, and the reference assemblies -->
<GuidPatchParams>
--target
$(CsWinRTIIDOptimizerTargetAssembly)
--outdir
$(IIDOptimizerInterimDir)
$(GuidPatchTargetAssemblyReferences)
</GuidPatchParams>
</PropertyGroup>
<MakeDir Directories="$(IIDOptimizerInterimDir)"/>
<PropertyGroup>
<CsWinRTIIDOptimizerResponseFile>$(IIDOptimizerInterimDir)cswinrt_iidoptimizer.rsp</CsWinRTIIDOptimizerResponseFile>
<CsWinRTIIDOptimizerCommand>"$(CsWinRTIIDOptimizerPath)IIDOptimizer.exe" %40"$(CsWinRTIIDOptimizerResponseFile)"</CsWinRTIIDOptimizerCommand>
</PropertyGroup>
<WriteLinesToFile File="$(CsWinRTIIDOptimizerResponseFile)" Lines="$(GuidPatchParams)" Overwrite="true" WriteOnlyWhenDifferent="true" />
</Target>
<!-- Run the IIDOptimizer on the projection .dll -->
<Target Name="CsWinRTInvokeGuidPatcher"
Condition="'$(DesignTimeBuild)' == ''"
AfterTargets="Compile"
BeforeTargets="Link"
DependsOnTargets="CsWinRTGenerateIIDOptimizerResponseFile">
<Message Text="$(CsWinRTIIDOptimizerCommand)" Importance="$(CsWinRTMessageImportance)" />
<Exec Command="$(CsWinRTIIDOptimizerCommand)" ConsoleToMsBuild="true" IgnoreExitCode="true">
<Output TaskParameter="ConsoleOutput" PropertyName="CsWinRTGuidPatchOutput" />
<Output TaskParameter="ExitCode" PropertyName="CsWinRTGuidPatchExitCode"/>
</Exec>
</Target>
<!-- When the IIDOptimizer succeeds, replace the input .dll with the patched version -->
<Target Name="CsWinRTReplaceForPatchedRuntime"
Condition="$(CsWinRTGuidPatchExitCode) == 0"
AfterTargets="CsWinRTInvokeGuidPatcher"
BeforeTargets="Link"
DependsOnTargets="CsWinRTInvokeGuidPatcher">
<ItemGroup>
<CsWinRTGuidPatchedFiles Include="$(IIDOptimizerInterimDir)$(AssemblyName).dll;$(IIDOptimizerInterimDir)$(AssemblyName).pdb" />
</ItemGroup>
<PropertyGroup>
<!-- Use the above .dll to find the directory we should copy to when we finish (usually "obj")-->
<CsWinRTIIDOptimizerOutputDir>$([System.IO.Directory]::GetParent($(CsWinRTIIDOptimizerTargetAssembly))) </CsWinRTIIDOptimizerOutputDir>
</PropertyGroup>
<!-- Replace the .dll in the output folder with the optimized version we just made -->
<Copy SourceFiles="@(CsWinRTGuidPatchedFiles)" DestinationFolder="$(CsWinRTIIDOptimizerOutputDir)" />
</Target>
</Project>