■ 2개 프로젝트를 가진 솔루션을 사용해 WinUI 3 단일 배포 앱을 만드는 방법을 보여준다. (UNPACKAGED)
[TestLibrary 프로젝트]
▶ TestLibrary.csproj
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net8.0-windows10.0.19041.0</TargetFramework> <TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion> <RootNamespace>TestLibrary</RootNamespace> <RuntimeIdentifiers Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) >= 8">win-x86;win-x64;win-arm64</RuntimeIdentifiers> <RuntimeIdentifiers Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) < 8">win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers> <UseWinUI>true</UseWinUI> <EnableMsixTooling>true</EnableMsixTooling> <!-- 추가 --> <IsPublishable>false</IsPublishable> <!-- 추가 --> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240627000" /> <PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.756" /> </ItemGroup> </Project> |
▶ TestClass.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 System; namespace TestLibrary; /// <summary> /// 테스트 클래스 /// </summary> public class TestClass { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region 메시지 구하기 - GetMessage() /// <summary> /// 메시지 구하기 /// </summary> /// <returns>메시지</returns> public static string GetMessage() { return DateTime.Now.ToString(); } #endregion } |
[TestProject 프로젝트]
▶ TestProject.csproj
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 |
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>WinExe</OutputType> <TargetFramework>net8.0-windows10.0.19041.0</TargetFramework> <TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion> <RootNamespace>TestProject</RootNamespace> <ApplicationManifest>app.manifest</ApplicationManifest> <Platforms>x86;x64;ARM64</Platforms> <RuntimeIdentifiers Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) >= 8">win-x86;win-x64;win-arm64</RuntimeIdentifiers> <RuntimeIdentifiers Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) < 8">win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers> <PublishProfile>win-$(Platform).pubxml</PublishProfile> <UseWinUI>True</UseWinUI> <EnableMsixTooling>True</EnableMsixTooling> <WindowsPackageType>None</WindowsPackageType> <!-- 추가 --> <PublishSingleFile>True</PublishSingleFile> <!-- 추가 --> <SelfContained>True</SelfContained> <!-- 추가 --> <WindowsAppSDKSelfContained>True</WindowsAppSDKSelfContained> <!-- 추가 --> <PublishReadyToRun>False</PublishReadyToRun> <!-- 추가 --> <PublishTrimmed>False</PublishTrimmed> <!-- 추가 --> </PropertyGroup> <ItemGroup> <Content Include="Assets\SplashScreen.scale-200.png" /> <Content Include="Assets\LockScreenLogo.scale-200.png" /> <Content Include="Assets\Square150x150Logo.scale-200.png" /> <Content Include="Assets\Square44x44Logo.scale-200.png" /> <Content Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png" /> <Content Include="Assets\StoreLogo.png" /> <Content Include="Assets\Wide310x150Logo.scale-200.png" /> </ItemGroup> <ItemGroup> <PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240627000" /> <PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.756" /> <Manifest Include="$(ApplicationManifest)" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\TestLibrary\TestLibrary.csproj" /> </ItemGroup> <!-- Defining the "Msix" ProjectCapability here allows the Single-project MSIX Packaging Tools extension to be activated for this project even if the Windows App SDK Nuget package has not yet been restored. --> <ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'"> <ProjectCapability Include="Msix" /> </ItemGroup> <!-- Defining the "HasPackageAndPublishMenuAddedByProject" property here allows the Solution Explorer "Package and Publish" context menu entry to be enabled for this project even if the Windows App SDK Nuget package has not yet been restored. --> <PropertyGroup Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'"> <HasPackageAndPublishMenu>true</HasPackageAndPublishMenu> </PropertyGroup> </Project> |
▶ MainWindow.xaml
1 2 3 4 5 6 7 8 9 10 11 12 |
<?xml version="1.0" encoding="utf-8"?> <Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="TestProject"> <TextBlock Name="textBlock" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="24" /> </Window> |
▶ MainWindow.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 29 30 |
using Microsoft.UI.Xaml; using TestLibrary; namespace TestProject; /// <summary> /// 메인 윈도우 /// </summary> public sealed partial class MainWindow : Window { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainWindow() /// <summary> /// 생성자 /// </summary> public MainWindow() { InitializeComponent(); this.textBlock.Text = TestClass.GetMessage(); } #endregion } |
▶ App.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?xml version="1.0" encoding="utf-8"?> <Application x:Class="TestProject.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> </Application> |
▶ App.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 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 |
using Windows.Graphics; using Microsoft.UI.Xaml; namespace TestProject; /// <summary> /// 앱 /// </summary> public partial class App : Application { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 윈도우 /// </summary> private Window window; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - App() /// <summary> /// 생성자 /// </summary> public App() { InitializeComponent(); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 런칭시 처리하기 - OnLaunched(e) /// <summary> /// 런칭시 처리하기 /// </summary> /// <param name="e">이벤트 인자</param> protected override void OnLaunched(LaunchActivatedEventArgs e) { this.window = new MainWindow(); this.window.AppWindow.Resize(new SizeInt32(800, 600)); this.window.Activate(); } #endregion } |
[배포 순서]
1. [비주얼 스튜디오]를 실행하고 상기 솔루션을 로드한다.
2. 비주얼 스튜디오에서 [Release], [x64], [TestProject(Unpackaged)] 항목을 선택하고 TestProject 프로젝트를 빌드한다.
3. [명령 프롬프트]를 실행한다.
4. [명령 프롬프트]에서 TestProject 프로젝트 폴더로 이동해 아래 명령을 실행한다.
▶ 실행 명령
1 2 3 |
D:\TestSolution\TestProject>dotnet publish -c Release -p:Platform=x64 -o .\bin\publish |
5. [명령 프롬프트]에서 TestProject 프로젝트 폴더의 bin\publish 하위 폴더로 이동해 아래 명령을 실행한다.
▶ 실행 명령
1 2 3 |
D:\TestSolution\TestProject\bin\publish>TestProject.exe |