Skip to content

Latest commit

 

History

History
96 lines (74 loc) · 2.77 KB

SelfContained.md

File metadata and controls

96 lines (74 loc) · 2.77 KB

Self-Contained

What is 'Self-Contained'?

Windows App SDK can be deployed via MSIX or self-contained, aka WinAppSDK/MSIX and WinAppSDK/SelfContained.

See the Self-Contained spec for more details.

How to detect if Windows App SDK is deployed Self-Contained?

If necessary, use WindowsAppRuntime::SelfContained::IsSelfContained() to detect if the current process is using WindowsAppSDK deployed via SelfContained (vs MSIX).

NOTE: The implementation assumes Windows App SDK is in use. Failure to detect WindowsAppSDK/MSIX is thus assumed to be WindowsAppSDK/SelfContained.

#include<WindowsAppRuntime.SelfContained.h>voidJustDoIt() { if (::WindowsAppRuntime::SelfContained::IsSelfContained()) { printf("WindowsAppSDK/SelfContained"); } else { printf("WindowsAppSDK/MSIX"); } }

Unit and Functional Testing

Unit and Functional Tests using alternative test packages (not Integration Tests using the real MSIX packages) need to call ::WindowsAppRuntime::VersionInfo::TestInitialize() with a nonexistent alternative (test) framework package family name BEFORE calling IsSelfContained() to simulate running in a self-contained deployment.

#include"pch.h" #include<WindowsAppRuntime.SelfContained.h> #include<WindowsAppRuntime.VersionInfo.h>namespaceTB= ::Test::Bootstrap; namespaceTP= ::Test::Packages; namespaceTest::MyFeature { classMyFeatureTests { public:BEGIN_TEST_CLASS(SelfContainedTests) TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") TEST_CLASS_PROPERTY(L"RunFixtureAs:Class", L"RestrictedUser") END_TEST_CLASS() TEST_CLASS_SETUP(ClassSetup) { ::TB::SetupPackages(); ::TB::SetupBootstrap(); constauto c_testFrameworkPackageFamilyName{ L"Test.Framework.PackageFamilyName_1234567890abc" }; ::WindowsAppRuntime::VersionInfo::TestInitialize(c_testFrameworkPackageFamilyName); returntrue; } TEST_CLASS_CLEANUP(ClassCleanup) { ::WindowsAppRuntime::VersionInfo::TestShutdown(); ::TB::CleanupBootstrap(); ::TB::CleanupPackages(); returntrue; } TEST_METHOD(TestThis) { ...insert your test code here... } ...

Alternatively, replace

::WindowsAppRuntime::VersionInfo::TestInitialize(c_testFrameworkPackageFamilyName); 

with

::WindowsAppRuntime::VersionInfo::TestInitialize(::TP::WindowsAppRuntimeFramework::c_PackageFamilyName); 

to simulate running in a non-self-contained environment (i.e. Windows App SDK via MSIX packages).

See test\common\Test_SelfContained.cpp for more examples using IsSelfContained().

close