forked from CommunityToolkit/Microsoft.Toolkit.Win32
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Microsoft.WinRT.Win32.targets
233 lines (212 loc) · 10.2 KB
/
Microsoft.WinRT.Win32.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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<DefaultTargetPlatformVersion Condition="'$(DefaultTargetPlatformVersion)'==''">18362</DefaultTargetPlatformVersion>
<AssetTargetFallback Condition="'$(AssetTargetFallback)'==''">uap10.0.$(DefaultTargetPlatformVersion)</AssetTargetFallback>
<!-- Up-to-date check fails for Xaml Islands projects: -->
<!-- https://github.com/dotnet/project-system/issues/5543 -->
<DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
<_PlatformShortName_>$(Platform)</_PlatformShortName_>
<_PlatformShortName_ Condition="'$(_PlatformShortName_)'=='Win32'">x86</_PlatformShortName_>
<_NetCoreUWP_NuGetPackageId>runtime.win10-$(_PlatformShortName_).Microsoft.NETCore.UniversalWindowsPlatform</_NetCoreUWP_NuGetPackageId>
<_NetCoreUWP_AOT_NuGetPackageId>runtime.win10-$(_PlatformShortName_)-aot.Microsoft.NETCore.UniversalWindowsPlatform</_NetCoreUWP_AOT_NuGetPackageId>
</PropertyGroup>
<PropertyGroup Condition="'$(DesignTimeBuild)' == 'true'">
<_DisableAppxCopy>true</_DisableAppxCopy>
</PropertyGroup>
<PropertyGroup>
<_TargetPlatformVersion Condition="$(_TargetPlatformVersion)==''">10.0.18362.0</_TargetPlatformVersion>
<ManifestTool Condition="Exists('$(MSBuildThisFileDirectory)\..\tools\mt.exe')">$(MSBuildThisFileDirectory)\..\tools\mt.exe</ManifestTool>
<ManifestTool Condition="'$(ManifestTool)'==''">$(MSBuildProgramFiles32)\Windows Kits\10\bin\$(_TargetPlatformVersion)\x86\mt.exe</ManifestTool>
</PropertyGroup>
<PropertyGroup Condition="'$(IntDir)'==''">
<IntDir>$(BaseIntermediateOutputPath)\$(Platform)\$(Configuration)\$(TargetFramework)\</IntDir>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VCRTForwarders.140" Version="1.0.6" />
</ItemGroup>
<Target Name="_GetUWPAppPayload">
<CreateItem Include="@(ProjectReference)" Condition="Exists('%(RelativeDir)\Package.appxmanifest')">
<Output ItemName="_AppxProject" TaskParameter="Include"/>
</CreateItem>
<MSBuild Projects="@(_AppxProject)"
Properties="Configuration=$(Configuration);Platform=$(Platform)"
Targets="Build;GetPackagingOutputs">
<Output TaskParameter="TargetOutputs" ItemName="_AppxBuildOutputPaths" />
</MSBuild>
<CreateItem Include="%(_AppxBuildOutputPaths.Identity)"
Condition="'%(_AppxBuildOutputPaths.TargetPath)'!=''"
AdditionalMetadata="FinalTargetPath=$(OutDir)%(_AppxBuildOutputPaths.TargetPath);TargetPath=%(_AppxBuildOutputPaths.TargetPath)">
<Output ItemName="_AppxInputs" TaskParameter="Include"/>
</CreateItem>
<CreateItem Include="%(_AppxBuildOutputPaths.RelativeDir)AppxManifest.xml" Condition="Exists('%(_AppxBuildOutputPaths.RelativeDir)AppxManifest.xml')">
<Output ItemName="AppxManifest" TaskParameter="Include"/>
</CreateItem>
<CreateProperty Value="$(IntDir)Manifests\app.manifest">
<Output
TaskParameter="Value"
PropertyName="GeneratedApplicationManifest" />
</CreateProperty>
<CreateProperty Value="$(IntDir)Manifests\mergeapp.manifest">
<Output
TaskParameter="Value"
PropertyName="MergedApplicationManifest" />
</CreateProperty>
</Target>
<Target Name="CopyAllProjectReferencesOutputs"
DependsOnTargets="_GetUWPAppPayload;ResolveReferences"
Inputs="@(_AppxInputs)"
Outputs="@(_AppxInputs->'%(FinalTargetPath)')"
Condition="'$(_DisableAppxCopy)'==''">
<CreateItem Include="@(_AppxBuildOutputPaths)"
Condition="'%(_AppxBuildOutputPaths.TargetPath)'!='' and
'%(_AppxBuildOutputPaths.NuGetPackageId)'!='$(_NetCoreUWP_AOT_NuGetPackageId)' and
'%(_AppxBuildOutputPaths.NuGetPackageId)'!='$(_NetCoreUWP_NuGetPackageId)' "
AdditionalMetadata="Link=%(_AppxBuildOutputPaths.TargetPath)">
<Output ItemName="_AppxBuildOutputs" TaskParameter="Include"/>
</CreateItem>
<CreateItem Include="@(_AppxBuildOutputs)" >
<Output ItemName="_AppxAllItems" TaskParameter="Include"/>
</CreateItem>
<CreateItem Include="@(_AppxAllItems)" AdditionalMetadata="CopyToOutputDirectory=PreserveNewest">
<Output ItemName="Content" TaskParameter="Include"/>
</CreateItem>
<WriteLinesToFile
File="$(IntDir)\AppUWP.payload"
Lines="@(_AppxBuildOutputPaths)"
Overwrite="true"
Encoding="Unicode"/>
</Target>
<UsingTask TaskName="GenerateWinRTManifestFromAppx" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<AppxManifest ParameterType="System.String" Required="false" />
<DestinationFolder ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
<Using Namespace="System.Collections.Generic" />
<Using Namespace="System.IO" />
<Using Namespace="System.Linq" />
<Using Namespace="System.Text" />
<Using Namespace="System.Xml" />
<Code Type="Fragment" Language="cs">
<![CDATA[
var headerF = @"<?xml version='1.0' encoding='utf-8' standalone='yes'?>
<assembly
manifestVersion='1.0'
xmlns:asmv3='urn:schemas-microsoft-com:asm.v3'
xmlns='urn:schemas-microsoft-com:asm.v1'>
<trustInfo xmlns='urn:schemas-microsoft-com:asm.v2'>
<security>
<requestedPrivileges xmlns='urn:schemas-microsoft-com:asm.v3'>
<requestedExecutionLevel level='asInvoker' uiAccess='false' />
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns='urn:schemas-microsoft-com:compatibility.v1'>
<application>
<maxversiontested Id='10.0.18362.0'/>
<supportedOS Id='{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}' />
</application>
</compatibility>
<application xmlns='urn:schemas-microsoft-com:asm.v3'>
<windowsSettings>
<dpiAware xmlns='http://schemas.microsoft.com/SMI/2005/WindowsSettings'>true/PM</dpiAware>
<dpiAwareness xmlns='http://schemas.microsoft.com/SMI/2016/WindowsSettings'>PerMonitorV2, PerMonitor</dpiAwareness>
</windowsSettings>
</application>";
var sb = new StringBuilder();
sb.Append(headerF);
bool foundXamlHost = false;
if (!string.IsNullOrEmpty(AppxManifest))
{
XmlDocument doc = new XmlDocument();
doc.Load(AppxManifest);
var nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("m", "http://schemas.microsoft.com/appx/manifest/foundation/windows10");
var xQuery = "./m:Package/m:Extensions/m:Extension/m:InProcessServer";
foreach (XmlNode winRTFactory in doc.SelectNodes(xQuery, nsmgr))
{
var dllPathNode = winRTFactory.SelectSingleNode("./m:Path", nsmgr);
var dllPath = dllPathNode.InnerText;
if (!foundXamlHost)
{
foundXamlHost = String.Compare(dllPath, "Microsoft.Toolkit.Win32.UI.XamlHost.dll", true) == 0;
}
var typesNames = winRTFactory.SelectNodes("./m:ActivatableClass", nsmgr).OfType<XmlNode>();
var xmlHeader = String.Format(@" <asmv3:file name='{0}'>", dllPath);
sb.Append(xmlHeader);
foreach (var typeNode in typesNames)
{
var attribs = typeNode.Attributes.OfType<XmlAttribute>().ToArray();
var typeName = attribs
.OfType<XmlAttribute>()
.SingleOrDefault(x => x.Name == "ActivatableClassId")
.InnerText;
var xmlEntry = String.Format(@"
<activatableClass
name='{0}'
threadingModel='both'
xmlns='urn:schemas-microsoft-com:winrt.v1'/>
", typeName);
sb.Append(xmlEntry);
}
var xmlFooter = @"
</asmv3:file>
";
sb.Append(xmlFooter);
}
}
if (!foundXamlHost)
{
sb.Append(@"
<asmv3:file name='Microsoft.Toolkit.Win32.UI.XamlHost.dll'>
<activatableClass
name='Microsoft.Toolkit.Win32.UI.XamlHost.XamlApplication'
threadingModel='both'
xmlns='urn:schemas-microsoft-com:winrt.v1'/>
</asmv3:file>");
}
var xmlFooterF = @"
</assembly>";
sb.Append(xmlFooterF);
var manifestContent = sb.ToString();
var outFileName = Path.Combine(DestinationFolder, "app.manifest");
File.WriteAllText(outFileName, manifestContent, Encoding.UTF8);
]]>
</Code>
</Task>
</UsingTask>
<Target Name="CreateWinRTRegistration"
AfterTargets="ResolveReferences"
DependsOnTargets="CopyAllProjectReferencesOutputs"
Inputs="@(AppxManifest);$(ApplicationManifest)"
Outputs="$(MergedApplicationManifest)"
Condition="'$(_DisableAppxCopy)'==''">
<MakeDir Directories="$(IntDir)\Manifests\" />
<GenerateWinRTManifestFromAppx AppxManifest="@(AppxManifest)" DestinationFolder="$(IntDir)\Manifests\" />
<CreateItem Include="$(IntDir)Manifests\*.manifest">
<Output
TaskParameter="Include"
ItemName="Manifest"/>
</CreateItem>
<Exec
Condition="Exists('$(ApplicationManifest)')"
Command=""$(ManifestTool)" -nologo -manifest "$(MSBuildProjectDirectory)\$(GeneratedApplicationManifest)" "$(MSBuildProjectDirectory)\$(ApplicationManifest)" -out:"$(MSBuildProjectDirectory)\$(MergedApplicationManifest)""
WorkingDirectory="$(MSBuildProjectDirectory)" >
</Exec>
<CreateProperty
Condition="!Exists('$(ApplicationManifest)')"
Value="$(GeneratedApplicationManifest)">
<Output
TaskParameter="Value"
PropertyName="MergedApplicationManifest" />
</CreateProperty>
<CreateProperty Value="$(MergedApplicationManifest)">
<Output
TaskParameter="Value"
PropertyName="ApplicationManifest" />
</CreateProperty>
</Target>
</Project>