■ 패키지(PACKAGE)/언패키지드(UNPACKAGED) 모드 여부를 구하는 방법을 보여준다.
▶ RuntimeHelper.cs
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 |
using System.Runtime.InteropServices; using System.Text; namespace TestProject; /// <summary> /// 런타임 헬퍼 /// </summary> public class RuntimeHelper { //////////////////////////////////////////////////////////////////////////////////////////////////// Import ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Private #region 현재 패키지 전체 명칭 구하기 - GetCurrentPackageFullName(packageFullNameLength, packageFullNameStringBuilder) /// <summary> /// 현재 패키지 전체 명칭 구하기 /// </summary> /// <param name="packageFullNameLength">패키지 전체 명칭 길이</param> /// <param name="packageFullNameStringBuilder">패키지 전체 명칭 문자열 빌더</param> /// <returns>처리 결과</returns> [DllImport("kernel32", CharSet = CharSet.Unicode, SetLastError = true)] private static extern int GetCurrentPackageFullName(ref int packageFullNameLength, StringBuilder packageFullNameStringBuilder); #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region MSIX 여부 - IsMSIX /// <summary> /// MSIX 여부 /// </summary> /// <remarks> /// true : Package /// false : Unpackaged /// </remarks> public static bool IsMSIX { get { var length = 0; return GetCurrentPackageFullName(ref length, null) != 15700L; } } #endregion } |
▶ MainPage.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?xml version="1.0" encoding="utf-8"?> <Page x:Class="TestProject.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" FontFamily="나눔고딕코딩" FontSize="16"> <TextBlock Name="textBlock" HorizontalAlignment="Center" VerticalAlignment="Center" /> </Page> |
▶ MainPage.xaml.cs
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 |
using Microsoft.UI.Xaml.Controls; namespace TestProject; /// <summary> /// 메인 페이지 /// </summary> public sealed partial class MainPage : Page { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainPage() /// <summary> /// 생성자 /// </summary> public MainPage() { InitializeComponent(); this.textBlock.Text = RuntimeHelper.IsMSIX.ToString(); } #endregion } |