Skip to content

Commit 62518f2

Browse files
authored
Feature: Added an out-of-proc WinRT server for long-running background tasks (#14335)
1 parent ea43865 commit 62518f2

File tree

36 files changed

+571
-1114
lines changed

36 files changed

+571
-1114
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ jobs:
9797
- name: Setup NuGet
9898
uses: NuGet/[email protected]
9999

100-
- name: Setup .NET 7
100+
- name: Setup .NET 8
101101
uses: actions/setup-dotnet@v3
102102
with:
103-
dotnet-version: '7.0.x'
103+
dotnet-version: '8.0.x'
104104

105105
- name: Restore NuGet
106106
shell: pwsh

.github/workflows/deploy-preview.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ jobs:
3434
- name: Setup NuGet
3535
uses: NuGet/[email protected]
3636

37-
- name: Setup .NET 7
37+
- name: Setup .NET 8
3838
uses: actions/setup-dotnet@v3
3939
with:
40-
dotnet-version: '7.0.x'
40+
dotnet-version: '8.0.x'
4141

4242
# TODO: Move the command to PowerShell script instead
4343
- name: Update Package.appxmanifest

Files.sln

Lines changed: 60 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,16 @@ EndProject
2727
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Files.App.Launcher", "src\Files.App.Launcher\Files.App.Launcher.vcxproj", "{25FD5045-6D4C-4DD0-B3AC-613AB59CBB07}"
2828
EndProject
2929
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Files.App", "src\Files.App\Files.App.csproj", "{6F431D82-A5FF-4833-B5E4-702E1E523126}"
30+
ProjectSection(ProjectDependencies) = postProject
31+
{1EE996D6-885E-4403-A461-26C7A4E14D26} = {1EE996D6-885E-4403-A461-26C7A4E14D26}
32+
EndProjectSection
3033
EndProject
3134
Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "Files.Package", "src\Files.App (Package)\Files.Package.wapproj", "{8F60FD8E-1921-47D6-97B0-D26D7B3A4999}"
3235
EndProject
3336
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Files.Core.SourceGenerator", "src\Files.Core.SourceGenerator\Files.Core.SourceGenerator.csproj", "{6FA07816-DE0A-4D49-84E8-38E953A33C87}"
3437
EndProject
38+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Files.App.Server", "src\Files.App.Server\Files.App.Server.csproj", "{1EE996D6-885E-4403-A461-26C7A4E14D26}"
39+
EndProject
3540
Global
3641
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3742
Debug|arm64 = Debug|arm64
@@ -378,30 +383,66 @@ Global
378383
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Debug|x64.Build.0 = Debug|Any CPU
379384
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Debug|x86.ActiveCfg = Debug|Any CPU
380385
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Debug|x86.Build.0 = Debug|Any CPU
381-
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Preview|arm64.ActiveCfg = Debug|Any CPU
382-
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Preview|arm64.Build.0 = Debug|Any CPU
383-
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Preview|x64.ActiveCfg = Debug|Any CPU
384-
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Preview|x64.Build.0 = Debug|Any CPU
385-
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Preview|x86.ActiveCfg = Debug|Any CPU
386-
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Preview|x86.Build.0 = Debug|Any CPU
386+
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Preview|arm64.ActiveCfg = Release|Any CPU
387+
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Preview|arm64.Build.0 = Release|Any CPU
388+
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Preview|x64.ActiveCfg = Release|Any CPU
389+
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Preview|x64.Build.0 = Release|Any CPU
390+
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Preview|x86.ActiveCfg = Release|Any CPU
391+
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Preview|x86.Build.0 = Release|Any CPU
387392
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Release|arm64.ActiveCfg = Release|Any CPU
388393
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Release|arm64.Build.0 = Release|Any CPU
389394
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Release|x64.ActiveCfg = Release|Any CPU
390395
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Release|x64.Build.0 = Release|Any CPU
391396
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Release|x86.ActiveCfg = Release|Any CPU
392397
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Release|x86.Build.0 = Release|Any CPU
393-
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Stable|arm64.ActiveCfg = Debug|Any CPU
394-
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Stable|arm64.Build.0 = Debug|Any CPU
395-
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Stable|x64.ActiveCfg = Debug|Any CPU
396-
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Stable|x64.Build.0 = Debug|Any CPU
397-
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Stable|x86.ActiveCfg = Debug|Any CPU
398-
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Stable|x86.Build.0 = Debug|Any CPU
399-
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Store|arm64.ActiveCfg = Debug|Any CPU
400-
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Store|arm64.Build.0 = Debug|Any CPU
401-
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Store|x64.ActiveCfg = Debug|Any CPU
402-
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Store|x64.Build.0 = Debug|Any CPU
403-
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Store|x86.ActiveCfg = Debug|Any CPU
404-
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Store|x86.Build.0 = Debug|Any CPU
398+
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Stable|arm64.ActiveCfg = Release|Any CPU
399+
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Stable|arm64.Build.0 = Release|Any CPU
400+
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Stable|x64.ActiveCfg = Release|Any CPU
401+
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Stable|x64.Build.0 = Release|Any CPU
402+
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Stable|x86.ActiveCfg = Release|Any CPU
403+
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Stable|x86.Build.0 = Release|Any CPU
404+
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Store|arm64.ActiveCfg = Release|Any CPU
405+
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Store|arm64.Build.0 = Release|Any CPU
406+
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Store|x64.ActiveCfg = Release|Any CPU
407+
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Store|x64.Build.0 = Release|Any CPU
408+
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Store|x86.ActiveCfg = Release|Any CPU
409+
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Store|x86.Build.0 = Release|Any CPU
410+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Debug|arm64.ActiveCfg = Debug|arm64
411+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Debug|arm64.Build.0 = Debug|arm64
412+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Debug|arm64.Deploy.0 = Debug|arm64
413+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Debug|x64.ActiveCfg = Debug|x64
414+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Debug|x64.Build.0 = Debug|x64
415+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Debug|x64.Deploy.0 = Debug|x64
416+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Debug|x86.ActiveCfg = Debug|x86
417+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Debug|x86.Build.0 = Debug|x86
418+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Debug|x86.Deploy.0 = Debug|x86
419+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Preview|arm64.ActiveCfg = Preview|arm64
420+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Preview|arm64.Build.0 = Preview|arm64
421+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Preview|x64.ActiveCfg = Preview|x64
422+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Preview|x64.Build.0 = Preview|x64
423+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Preview|x86.ActiveCfg = Preview|x86
424+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Preview|x86.Build.0 = Preview|x86
425+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Release|arm64.ActiveCfg = Release|arm64
426+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Release|arm64.Build.0 = Release|arm64
427+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Release|arm64.Deploy.0 = Release|arm64
428+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Release|x64.ActiveCfg = Release|x64
429+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Release|x64.Build.0 = Release|x64
430+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Release|x64.Deploy.0 = Release|x64
431+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Release|x86.ActiveCfg = Release|x86
432+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Release|x86.Build.0 = Release|x86
433+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Release|x86.Deploy.0 = Release|x86
434+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Stable|arm64.ActiveCfg = Stable|arm64
435+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Stable|arm64.Build.0 = Stable|arm64
436+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Stable|x64.ActiveCfg = Stable|x64
437+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Stable|x64.Build.0 = Stable|x64
438+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Stable|x86.ActiveCfg = Stable|x86
439+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Stable|x86.Build.0 = Stable|x86
440+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Store|arm64.ActiveCfg = Store|arm64
441+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Store|arm64.Build.0 = Store|arm64
442+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Store|x64.ActiveCfg = Store|x64
443+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Store|x64.Build.0 = Store|x64
444+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Store|x86.ActiveCfg = Store|x86
445+
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Store|x86.Build.0 = Store|x86
405446
EndGlobalSection
406447
GlobalSection(SolutionProperties) = preSolution
407448
HideSolutionNode = FALSE
@@ -420,6 +461,7 @@ Global
420461
{6F431D82-A5FF-4833-B5E4-702E1E523126} = {A188C26B-E731-4E0B-9D17-D21CEBD9B43F}
421462
{8F60FD8E-1921-47D6-97B0-D26D7B3A4999} = {A188C26B-E731-4E0B-9D17-D21CEBD9B43F}
422463
{6FA07816-DE0A-4D49-84E8-38E953A33C87} = {9F36C2AD-005D-4EA5-A1F1-6BC42773FC85}
464+
{1EE996D6-885E-4403-A461-26C7A4E14D26} = {A188C26B-E731-4E0B-9D17-D21CEBD9B43F}
423465
EndGlobalSection
424466
GlobalSection(ExtensibilityGlobals) = postSolution
425467
SolutionGuid = {0E62043C-A7A1-4982-9EC9-4CDB2939B776}

builds/azure-pipelines-release.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ jobs:
114114
- task: UseDotNet@2
115115
inputs:
116116
packageType: sdk
117-
version: 7.0.x
118-
includePreviewVersions: true
117+
version: 8.0.x
118+
includePreviewVersions: false
119119

120120
- task: CmdLine@2
121121
inputs:
@@ -240,8 +240,8 @@ jobs:
240240
- task: UseDotNet@2
241241
inputs:
242242
packageType: sdk
243-
version: 7.0.x
244-
includePreviewVersions: true
243+
version: 8.0.x
244+
includePreviewVersions: false
245245

246246
- task: CmdLine@2
247247
inputs:

src/Files.App (Package)/Files.Package.wapproj

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<ProjectGuid>8f60fd8e-1921-47d6-97b0-d26d7b3a4999</ProjectGuid>
66
<TargetPlatformVersion>10.0.22621.0</TargetPlatformVersion>
77
<TargetPlatformMinVersion>10.0.19041.0</TargetPlatformMinVersion>
8-
<AssetTargetFallback>net7.0-windows$(TargetPlatformVersion);$(AssetTargetFallback)</AssetTargetFallback>
8+
<AssetTargetFallback>net8.0-windows$(TargetPlatformVersion);$(AssetTargetFallback)</AssetTargetFallback>
99
<DefaultLanguage>en-US</DefaultLanguage>
1010
<GenerateAppInstallerFile>False</GenerateAppInstallerFile>
1111
<AppxAutoIncrementPackageRevision>False</AppxAutoIncrementPackageRevision>
@@ -98,14 +98,23 @@
9898
<Content Include="Package.appinstaller" />
9999
</ItemGroup>
100100
<ItemGroup>
101+
<ProjectReference Include="..\Files.App.Server\Files.App.Server.csproj">
102+
<SkipGetTargetFrameworkProperties>True</SkipGetTargetFrameworkProperties>
103+
<PublishProfile>Properties\PublishProfiles\win-$(Platform).pubxml</PublishProfile>
104+
</ProjectReference>
101105
<ProjectReference Include="..\Files.App\Files.App.csproj">
102106
<SkipGetTargetFrameworkProperties>True</SkipGetTargetFrameworkProperties>
103-
<PublishProfile>Properties\PublishProfiles\win10-$(Platform).pubxml</PublishProfile>
107+
<PublishProfile>Properties\PublishProfiles\win-$(Platform).pubxml</PublishProfile>
104108
</ProjectReference>
105109
</ItemGroup>
106110
<ItemGroup>
107111
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.4.231115000" IncludeAssets="build" />
108112
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.2428" IncludeAssets="build" />
109113
</ItemGroup>
110114
<Import Project="$(WapProjPath)\Microsoft.DesktopBridge.targets" />
115+
<Target Name="RemoveOutOfProcWinMD" BeforeTargets="_GenerateCurrentProjectAppxManifest">
116+
<ItemGroup>
117+
<_AppxWinmdFilesToHarvest Condition="'%(FileName)' == 'Files.App.Server'" Remove="@(_AppxWinmdFilesToHarvest)" />
118+
</ItemGroup>
119+
</Target>
111120
</Project>

src/Files.App (Package)/Package.appxmanifest

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@
160160
<ActivatableClass ActivatableClassId="Files.App.BackgroundTasks.UpdateTask" ThreadingModel="both" />
161161
</InProcessServer>
162162
</Extension>
163+
<Extension Category="windows.activatableClass.outOfProcessServer">
164+
<OutOfProcessServer ServerName="Files.App.Server" uap5:IdentityType="activateAsPackage" uap5:RunFullTrust="true">
165+
<Path>Files.App.Server\Files.App.Server.exe</Path>
166+
<Instancing>singleInstance</Instancing>
167+
<ActivatableClass ActivatableClassId="Files.App.Server.AppInstanceMonitor" />
168+
</OutOfProcessServer>
169+
</Extension>
163170
</Extensions>
164171

165172
<Capabilities>

src/Files.App.BackgroundTasks/Files.App.BackgroundTasks.csproj

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
<Project Sdk="Microsoft.NET.Sdk">
33

44
<PropertyGroup>
5-
<TargetFramework>net7.0-windows10.0.22621.0</TargetFramework>
5+
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
66
<DefaultLanguage>en-US</DefaultLanguage>
77
<TargetPlatformMinVersion>10.0.19041.0</TargetPlatformMinVersion>
88
<IsTrimmable>true</IsTrimmable>
99
<Configurations>Debug;Release;Stable;Preview;Store</Configurations>
1010
<Platforms>x86;x64;ARM64</Platforms>
11-
<RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
11+
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
1212
</PropertyGroup>
1313

1414
<PropertyGroup>
@@ -17,6 +17,14 @@
1717
<CsWinRTGeneratedFilesDir>$(MSBuildProjectDirectory)\bin\$(Platform)\$(Configuration)</CsWinRTGeneratedFilesDir>
1818
</PropertyGroup>
1919

20+
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
21+
<DefineConstants>TRACE;DEBUG;NETFX_CORE</DefineConstants>
22+
</PropertyGroup>
23+
<PropertyGroup Condition="'$(Configuration)' != 'Debug'">
24+
<DefineConstants>TRACE;RELEASE;NETFX_CORE</DefineConstants>
25+
<Optimize>true</Optimize>
26+
</PropertyGroup>
27+
2028
<ItemGroup>
2129
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.4" />
2230
</ItemGroup>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Diagnostics;
2+
3+
namespace Files.App.Server;
4+
5+
public sealed class AppInstanceMonitor
6+
{
7+
private static int processCount = 0;
8+
9+
public static void StartMonitor(int processId)
10+
{
11+
var process = Process.GetProcessById(processId);
12+
Interlocked.Increment(ref processCount);
13+
process.EnableRaisingEvents = true;
14+
process.Exited += Process_Exited;
15+
}
16+
17+
private static void Process_Exited(object? sender, EventArgs e)
18+
{
19+
if (sender is Process process)
20+
{
21+
process.Dispose();
22+
23+
if (Interlocked.Decrement(ref processCount) == 0)
24+
{
25+
Program.ExitSignalEvent.Set();
26+
}
27+
}
28+
}
29+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>WinExe</OutputType>
5+
<DefaultLanguage>en-US</DefaultLanguage>
6+
<AppxBundleAutoResourcePackageQualifiers>Scale|DXFeatureLevel</AppxBundleAutoResourcePackageQualifiers>
7+
<AppxDefaultResourceQualifiers>Language=en-US;af;ar;bg;ca;cs-CZ;da;da-DK;de-DE;el;en-GB;es-ES;es-419;fa-IR;fi-FI;fil-PH;fr-FR;he-IL;hi-IN;hu-HU;id-ID;it-IT;ja-JP;ka;ko-KR;lt;lv-LV;nb-NO;nl-NL;or-IN;pl-PL;pt-BR;pt-PT;ro-RO;ru-RU;sk-SK;sv-SE;ta;th-TH;tr-TR;uk-UA;vi;zh-Hans;zh-Hant</AppxDefaultResourceQualifiers>
8+
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
9+
<TargetPlatformMinVersion>10.0.19041.0</TargetPlatformMinVersion>
10+
<ImplicitUsings>enable</ImplicitUsings>
11+
<Nullable>enable</Nullable>
12+
<Configurations>Debug;Release;Stable;Preview;Store</Configurations>
13+
<Platforms>x86;x64;arm64</Platforms>
14+
<SelfContained>true</SelfContained>
15+
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
16+
<RuntimeIdentifier Condition="'$(Platform)' == 'x86'">win-x86</RuntimeIdentifier>
17+
<RuntimeIdentifier Condition="'$(Platform)' == 'x64'">win-x64</RuntimeIdentifier>
18+
<RuntimeIdentifier Condition="'$(Platform)' == 'arm64'">win-arm64</RuntimeIdentifier>
19+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
20+
<CsWinRTComponent>true</CsWinRTComponent>
21+
<CsWinRTWindowsMetadata>10.0.22621.0</CsWinRTWindowsMetadata>
22+
<ApplicationManifest>app.manifest</ApplicationManifest>
23+
<PublishReadyToRun Condition="'$(Configuration)' == 'Debug'">False</PublishReadyToRun>
24+
<PublishReadyToRun Condition="'$(Configuration)' != 'Debug'">True</PublishReadyToRun>
25+
<PublishReadyToRunComposite Condition="'$(Configuration)' != 'Debug'">True</PublishReadyToRunComposite>
26+
<PublishTrimmed Condition="'$(Configuration)' == 'Debug'">False</PublishTrimmed>
27+
<PublishTrimmed Condition="'$(Configuration)' != 'Debug'">True</PublishTrimmed>
28+
</PropertyGroup>
29+
30+
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
31+
<DefineConstants>TRACE;DEBUG;NETFX_CORE</DefineConstants>
32+
</PropertyGroup>
33+
<PropertyGroup Condition="'$(Configuration)' != 'Debug'">
34+
<DefineConstants>TRACE;RELEASE;NETFX_CORE</DefineConstants>
35+
<Optimize>true</Optimize>
36+
</PropertyGroup>
37+
38+
<ItemGroup>
39+
<Manifest Include="app.manifest" />
40+
<TrimmerRootAssembly Include="Files.App.Server" />
41+
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.4" />
42+
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.1.647-beta" PrivateAssets="all" />
43+
</ItemGroup>
44+
45+
<ItemGroup>
46+
<None Include="..\Files.App.Server\bin\$(Platform)\$(Configuration)\$(TargetFramework)\win-$(Platform)\Files.App.Server.winmd">
47+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
48+
<Link>Files.App.Server.winmd</Link>
49+
<Visible>false</Visible>
50+
</None>
51+
</ItemGroup>
52+
53+
<ItemGroup>
54+
<ProjectReference Include="..\Files.Shared\Files.Shared.csproj" />
55+
</ItemGroup>
56+
57+
</Project>

src/Files.App.Server/Helpers.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System.Runtime.CompilerServices;
2+
using System.Runtime.InteropServices;
3+
using WinRT;
4+
5+
namespace Files.App.Server;
6+
7+
unsafe partial class Helpers
8+
{
9+
[UnmanagedCallersOnly(CallConvs = [typeof(CallConvStdcall)])]
10+
public static int GetActivationFactory(void* activatableClassId, void** factory)
11+
{
12+
const int E_INVALIDARG = unchecked((int)0x80070057);
13+
const int CLASS_E_CLASSNOTAVAILABLE = unchecked((int)0x80040111);
14+
const int S_OK = 0;
15+
16+
if (activatableClassId is null || factory is null)
17+
{
18+
return E_INVALIDARG;
19+
}
20+
21+
try
22+
{
23+
IntPtr obj = Module.GetActivationFactory(MarshalString.FromAbi((IntPtr)activatableClassId));
24+
25+
if ((void*)obj is null)
26+
{
27+
return CLASS_E_CLASSNOTAVAILABLE;
28+
}
29+
30+
*factory = (void*)obj;
31+
return S_OK;
32+
}
33+
catch (Exception e)
34+
{
35+
ExceptionHelpers.SetErrorInfo(e);
36+
return ExceptionHelpers.GetHRForException(e);
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)