Repository navigation
Expand file tree
/
Copy pathplugin.targets
More file actions
72 lines (67 loc) · 5.84 KB
/
Copy pathplugin.targets
File metadata and controls
72 lines (67 loc) · 5.84 KB
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
<?xml version="1.0" encoding="utf-8"?>
<!--
@nativescript/core: Windows plugin targets.
Copies the active-architecture NativeScript.Widgets C++/WinRT component (its
native .dll + .winmd metadata) to the package root ($(OutDir)). The runtime
resolves the winmd there via RoGetMetaDataFile and activates the in-proc server
(registered as windows.activatableClass.inProcessServer in the app's
Package.appxmanifest). An explicit Copy (rather than Content) is used so the
files survive EnableMsixTooling Content interception.
Native DLLs are per-architecture (no universal binary on Windows), so the
matching arch folder is chosen from $(Platform). The CLI stages this plugin's
platforms/windows/{x64,arm64}/ next to this file, so $(MSBuildThisFileDirectory)
resolves the arch subfolders.
-->
<Project>
<Target Name="CopyNativeScriptWidgets" AfterTargets="Build">
<PropertyGroup>
<_NSWidgetsArchDir Condition="'$(Platform)'=='ARM64' or '$(Platform)'=='arm64'">$(MSBuildThisFileDirectory)arm64\</_NSWidgetsArchDir>
<_NSWidgetsArchDir Condition="'$(Platform)'=='x64' or '$(Platform)'=='x86_64'">$(MSBuildThisFileDirectory)x64\</_NSWidgetsArchDir>
<!-- Fallback to x64 when $(Platform) is unset/AnyCPU during evaluation. -->
<_NSWidgetsArchDir Condition="'$(_NSWidgetsArchDir)'==''">$(MSBuildThisFileDirectory)x64\</_NSWidgetsArchDir>
</PropertyGroup>
<ItemGroup>
<_NSWidgetsFiles Include="$(_NSWidgetsArchDir)NativeScript.Widgets.dll" Condition="Exists('$(_NSWidgetsArchDir)NativeScript.Widgets.dll')" />
<_NSWidgetsFiles Include="$(_NSWidgetsArchDir)NativeScript.Widgets.winmd" Condition="Exists('$(_NSWidgetsArchDir)NativeScript.Widgets.winmd')" />
</ItemGroup>
<Message Text="[@nativescript/core] Copying NativeScript.Widgets ($(Platform)) to $(OutDir)" Importance="normal" Condition="'@(_NSWidgetsFiles)' != ''" />
<Copy SourceFiles="@(_NSWidgetsFiles)"
DestinationFolder="$(OutDir)"
SkipUnchangedFiles="true"
Condition="'@(_NSWidgetsFiles)' != ''" />
</Target>
<!--
Registers the NativeScript.Widgets C++/WinRT runtimeclasses as an in-proc activatable-class
server in the app's Package.appxmanifest, so the OS RoGetActivationFactory can create them.
Owned here in @nativescript/core (which ships the DLL) so apps NEVER hand-maintain the list in
their App_Resources manifest: adding a new C++ widget class only requires updating
NSWidgetsActivatableClass below. The injection is idempotent (skips classes already present),
so it is safe even if an app's manifest still lists some entries.
Runs after the app's manifest overrides/merge (ApplyManifestOverrides / MergeAppResourcesManifest
in the Windows project template's Directory.Build.targets), while the manifest is still being
assembled in the BeforeBuild phase, before the appx packaging consumes it.
-->
<ItemGroup>
<!-- Keep in sync with the runtimeclasses exported by NativeScript.Widgets.dll. -->
<NSWidgetsActivatableClass Include="NativeScript.Widgets.StackLayout" />
<NSWidgetsActivatableClass Include="NativeScript.Widgets.FlexboxLayout" />
<NSWidgetsActivatableClass Include="NativeScript.Widgets.ImageHelper" />
<NSWidgetsActivatableClass Include="NativeScript.Widgets.ShadowHelper" />
<NSWidgetsActivatableClass Include="NativeScript.Widgets.ClipHelper" />
<NSWidgetsActivatableClass Include="NativeScript.Widgets.PanelHelper" />
<NSWidgetsActivatableClass Include="NativeScript.Widgets.FontHelper" />
<NSWidgetsActivatableClass Include="NativeScript.Widgets.ScrollHelper" />
<NSWidgetsActivatableClass Include="NativeScript.Widgets.TileHelper" />
<NSWidgetsActivatableClass Include="NativeScript.Widgets.TextShadowHelper" />
</ItemGroup>
<!-- Idempotent XML injection via PowerShell (guaranteed present on Windows, full .NET XML, no
RoslynCodeTaskFactory assembly-reference issues). Adds only the ActivatableClass entries that
aren't already in the manifest, so it's safe regardless of what the app manifest already lists. -->
<Target Name="NSRegisterWidgetsActivatableClasses"
AfterTargets="ApplyManifestOverrides;MergeAppResourcesManifest"
BeforeTargets="Build"
Condition="Exists('$(MSBuildProjectDirectory)\Package.appxmanifest')">
<Message Text="[@nativescript/core] Registering NativeScript.Widgets activatable classes in Package.appxmanifest" Importance="normal" />
<Exec Command="powershell -NoProfile -ExecutionPolicy Bypass -Command "$ErrorActionPreference='Stop'; $p='$(MSBuildProjectDirectory)\Package.appxmanifest'; if(-not (Test-Path $p)){exit 0}; $dll='NativeScript.Widgets.dll'; $ids='@(NSWidgetsActivatableClass)'.Split(';'); [xml]$d=Get-Content -LiteralPath $p; $ns='http://schemas.microsoft.com/appx/manifest/foundation/windows10'; $m=New-Object System.Xml.XmlNamespaceManager($d.NameTable); $m.AddNamespace('a',$ns); $pkg=$d.DocumentElement; $ext=$pkg.SelectSingleNode('a:Extensions',$m); if(-not $ext){$ext=$d.CreateElement('Extensions',$ns);[void]$pkg.AppendChild($ext)}; $srv=$ext.SelectSingleNode('a:Extension[@Category=''windows.activatableClass.inProcessServer'']/a:InProcessServer[a:Path=''' + $dll + ''']',$m); if(-not $srv){$e=$d.CreateElement('Extension',$ns);$e.SetAttribute('Category','windows.activatableClass.inProcessServer');$srv=$d.CreateElement('InProcessServer',$ns);$pa=$d.CreateElement('Path',$ns);$pa.InnerText=$dll;[void]$srv.AppendChild($pa);[void]$e.AppendChild($srv);[void]$ext.AppendChild($e)}; $have=@($srv.SelectNodes('a:ActivatableClass',$m)|ForEach-Object{$_.GetAttribute('ActivatableClassId')}); $chg=$false; foreach($id in $ids){if($id -and ($have -notcontains $id)){$c=$d.CreateElement('ActivatableClass',$ns);$c.SetAttribute('ActivatableClassId',$id);$c.SetAttribute('ThreadingModel','both');[void]$srv.AppendChild($c);$chg=$true}}; if($chg){$d.Save($p)}"" />
</Target>
</Project>