-
Notifications
You must be signed in to change notification settings - Fork 151
Expand file tree
/
Copy pathHostsFileEditor.WinUI.csproj
More file actions
156 lines (153 loc) · 10.2 KB
/
Copy pathHostsFileEditor.WinUI.csproj
File metadata and controls
156 lines (153 loc) · 10.2 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
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
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
<UseWinUI>true</UseWinUI>
<AssemblyName>HostsFileEditor</AssemblyName>
<!-- Single version source for this app (the modern UI ships as its own version stream,
separate from classic). Drives AssemblyVersion/FileVersion/ProductVersion and, stamped
in Directory.Build.targets, the MSIX manifest Identity/@Version. -->
<Version>1.2.2.0</Version>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Platform Condition="'$(Platform)' == ''">x64</Platform>
<Platforms>x64;arm64</Platforms>
<EnablePreviewMsixTooling>true</EnablePreviewMsixTooling>
<UseWindowsForms>false</UseWindowsForms>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier Condition="'$(RuntimeIdentifier)' == ''">win-x64</RuntimeIdentifier>
<!-- Bundle the Windows App SDK runtime in the package (self-contained) so the app launches
on a clean machine without the Microsoft.WindowsAppRuntime.2 framework package installed.
Framework-dependent deployment crashed at launch in Store certification when that runtime
wasn't provisioned; the AppxManifest no longer declares it as a dependency. -->
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
<SelfContained>true</SelfContained>
<PublishSingleFile>false</PublishSingleFile>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<PublishTrimmed>true</PublishTrimmed>
<TrimmerSingleWarn>false</TrimmerSingleWarn>
<PublishAot>true</PublishAot>
<!-- CA5392: the Windows App SDK self-contained mode compiles in a Microsoft-generated
UndockedRegFreeWinRT-AutoInitializer.cs whose bootstrap P/Invoke lacks
DefaultDllImportSearchPaths. It's third-party generated code we can't edit; our own
P/Invokes (in Core) remain CA5392-compliant.
IL2081: System.ComponentModel.BindingList<T> (Core's HostsEntryList / HostsArchiveList
base) carries reflective PropertyDescriptor paths the trim analyzer flags. The former
blanket IL2026/IL3050 entries here were replaced by per-member
UnconditionalSuppressMessage attributes in Core (HostsEntryList / HostsFile), restoring
the trim/AOT analyzers' protection for all other code in this AOT-published app; keep this
list minimal. -->
<NoWarn>$(NoWarn);IDE0079;IDE0060;CA1822;IL2081;CA5392</NoWarn>
<ApplicationIcon>Assets\HostsFileEditor.ico</ApplicationIcon>
<!-- Provide our own Program.Main (Program.cs) so a headless command-line invocation (issue #2) can
run before the WinUI stack boots. Disables the auto-generated XAML entry point. -->
<DefineConstants>$(DefineConstants);DISABLE_XAML_GENERATED_MAIN</DefineConstants>
<PackagingFlavor>modern</PackagingFlavor>
<OutputPackagingDir>$(MSBuildProjectDirectory)\..\artifacts\modern\</OutputPackagingDir>
<CreatePublishZip>false</CreatePublishZip>
<!-- The WinUI build emits the package resource index; by default it names it
<AssemblyName>.pri with the resource-map root also = <AssemblyName> ("HostsFileEditor").
The app resolves its XAML from that fine, but the SHELL only resolves tile/taskbar logos
from a package-root resources.pri whose resource-map root matches the package Identity
Name — so with the default naming the taskbar fell back to the flat logo on the accent
plate. Emit the index as resources.pri with the identity as the map root so the shell
resolves the qualified logo assets (incl. altform-unplated) added to Assets\ and renders
the taskbar icon unplated. Keep this in sync with Identity/@Name in AppxManifest.xml.
Do NOT also set GenerateResourcesPri here: a second, logo-only resources.pri would shadow
this complete index and crash WinUI on launch (Microsoft.UI.Xaml.dll, 0xc000027b). -->
<ProjectPriFileName>resources.pri</ProjectPriFileName>
<ProjectPriIndexName>11033ScottLerch.HostsFileEditormodern</ProjectPriIndexName>
<GenerateResourcesPri>false</GenerateResourcesPri>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.9" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="2.2.0" />
<PackageReference Include="H.NotifyIcon.WinUI" Version="2.4.1" />
<PackageReference Include="System.Resources.Extensions" Version="10.0.9" />
<!-- Taskbar Jump List (issue #10) uses the WinRT Windows.UI.StartScreen.JumpList API — packaged-
native and AOT-compatible via CsWinRT — not WindowsAPICodePack (that library is pure COM
interop and fails Native AOT: `IL3052 COM interop is not supported`). Classic, which does not
AOT, still uses WindowsAPICodePack. -->
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\HostsFileEditor.Core\HostsFileEditor.Core.csproj" />
</ItemGroup>
<!-- Build the elevation helper and copy its output next to the app exe so the app can
launch it on demand (see PrivilegedFileOperations.UseElevationHelper). -->
<Target Name="CopyElevateHelper" AfterTargets="Build">
<MSBuild Projects="$(MSBuildThisFileDirectory)..\HostsFileEditor.Elevate\HostsFileEditor.Elevate.csproj"
Targets="Build"
Properties="Configuration=$(Configuration);Platform=AnyCPU"
RemoveProperties="RuntimeIdentifier">
<Output TaskParameter="TargetOutputs" ItemName="_ElevateHelperPrimaryOutput" />
</MSBuild>
<PropertyGroup>
<_ElevateHelperDir>%(_ElevateHelperPrimaryOutput.RootDir)%(_ElevateHelperPrimaryOutput.Directory)</_ElevateHelperDir>
</PropertyGroup>
<ItemGroup>
<_ElevateHelperFiles Include="$(_ElevateHelperDir)*.*" />
</ItemGroup>
<Copy SourceFiles="@(_ElevateHelperFiles)" DestinationFolder="$(OutDir)Elevate" SkipUnchangedFiles="true" />
<Message Importance="high" Text="Copied elevation helper to $(OutDir)Elevate" />
</Target>
<!-- Publish the elevation helper (AOT, self-contained native exe) for this app's RID and
bundle it under Elevate\ in the publish output so the MSIX package includes it. -->
<Target Name="PublishElevateHelper" AfterTargets="Publish" BeforeTargets="SignAndPackage">
<PropertyGroup>
<_ElevateRid Condition="'$(_ElevateRid)' == ''">$(RuntimeIdentifier)</_ElevateRid>
<_ElevateRid Condition="'$(_ElevateRid)' == ''">win-x64</_ElevateRid>
<_ElevateStaging>$(MSBuildProjectDirectory)\obj\elevate\$(Configuration)\$(_ElevateRid)\</_ElevateStaging>
</PropertyGroup>
<MSBuild Projects="$(MSBuildThisFileDirectory)..\HostsFileEditor.Elevate\HostsFileEditor.Elevate.csproj"
Targets="Publish"
Properties="Configuration=$(Configuration);RuntimeIdentifier=$(_ElevateRid);PublishDir=$(_ElevateStaging)" />
<Copy SourceFiles="$(_ElevateStaging)HostsFileEditor.Elevate.exe" DestinationFolder="$(PublishDir)Elevate" SkipUnchangedFiles="true" />
<Message Importance="high" Text="Bundled elevation helper into $(PublishDir)Elevate" />
</Target>
<ItemGroup>
<None Include="app.manifest" />
<Content Include="AppxManifest.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Assets\*.*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="HostsFileEditor.ico" />
</ItemGroup>
<!-- Publish the console launcher (AOT, self-contained single native exe) for this app's RID and drop
hfe.exe into the publish root so the MSIX package ships it (and the appExecutionAlias resolves). -->
<Target Name="PublishCliLauncher" AfterTargets="Publish" BeforeTargets="SignAndPackage">
<PropertyGroup>
<_CliRid Condition="'$(_CliRid)' == ''">$(RuntimeIdentifier)</_CliRid>
<_CliRid Condition="'$(_CliRid)' == ''">win-x64</_CliRid>
<_CliStaging>$(MSBuildProjectDirectory)\obj\cli\$(Configuration)\$(_CliRid)\</_CliStaging>
</PropertyGroup>
<MSBuild Projects="$(MSBuildThisFileDirectory)..\HostsFileEditor.Cli\HostsFileEditor.Cli.csproj"
Targets="Publish"
Properties="Configuration=$(Configuration);RuntimeIdentifier=$(_CliRid);PublishDir=$(_CliStaging)" />
<Copy SourceFiles="$(_CliStaging)hfe.exe" DestinationFolder="$(PublishDir)" SkipUnchangedFiles="true" />
<Message Importance="high" Text="Bundled hfe.exe launcher into $(PublishDir)" />
</Target>
<!-- Strip ~43 MB of Windows App SDK components this app never uses. The self-contained WinUI
runtime bundles the Windows ML / Copilot stack (onnxruntime + DirectML) and the Widgets
APIs; a hosts-file editor references none of it. There is no supported property to exclude
them (WindowsAppSDK issue #5969), so delete them from the publish output after Publish and
before the package is built. These are lazy-loaded only when the corresponding AI/Widgets
APIs are called, which never happens here — verified the app still launches without them.
WinUIEdit.dll is intentionally NOT removed: it backs text controls the app does use. -->
<Target Name="_StripUnusedWinAppSdkLibs" AfterTargets="Publish" BeforeTargets="SignAndPackage">
<ItemGroup>
<_UnusedWinAppSdkLib Include="$(PublishDir)onnxruntime.dll" />
<_UnusedWinAppSdkLib Include="$(PublishDir)DirectML.dll" />
<_UnusedWinAppSdkLib Include="$(PublishDir)PerceptiveStreaming.dll" />
<_UnusedWinAppSdkLib Include="$(PublishDir)Microsoft.Windows.Widgets.dll" />
<_UnusedWinAppSdkLib Include="$(PublishDir)Microsoft.Windows.Widgets.winmd" />
</ItemGroup>
<!-- Warn (don't fail) if an expected lib is missing: a future Windows App SDK bump that
renames/relocates one would otherwise silently stop stripping and the ~43 MB creeps back
with no signal. -->
<Warning Condition="!Exists('%(_UnusedWinAppSdkLib.Identity)')"
Text="Expected unused WinAppSDK lib not found (SDK layout may have changed): %(_UnusedWinAppSdkLib.Identity)" />
<Delete Files="@(_UnusedWinAppSdkLib)" />
<Message Importance="high" Text="Stripped unused Windows App SDK libraries (onnxruntime, DirectML, PerceptiveStreaming, Widgets) from publish output." />
</Target>
</Project>