Visual Studio 2019 ã RC ã«å°éããã¨ãã話ã ã£ãã®ã§ãæ¤è¨¼ç¨ã«ä½¿ã£ã¦ãããã·ã³ã«ã¤ã³ã¹ãã¼ã«ãã¦æ¢å WPF ã¢ããªã® .NET Core 3.0 移è¡ãã©ã®ãããã®ã³ã¹ãã§è¡ããã®ã試ãã¾ããã
ã«ãã«ãæ¸ãã¦ããããã« .NET Core 3.0 ã Visual Studio 2019 RC ã§ä½¿ãã«ã¯ããã¬ãã¥ã¼çã® .NET Core ã使ãããã«è¨å®ãå¤ããå¿ è¦ãããã¾ãã
çå±ã¨ãã¦ã¯åããã¾ãããã¾ãã¾ãã¯ã¾ãããããã¤ã³ãã§ãããè¨å®ãå¤ãã㨠.NET Core 3.0 åãã®ããã¸ã§ã¯ããèªã¿è¾¼ãã§ãã«ãåºæ¥ãããã«ãªãã¾ããã
.NET Core 3.0 ã® Win Forms / WPF 対å¿ã«ã¤ãã¦èª¿ã¹ã¦ã¿ãã¨ãã»ã¨ãã© dotnet new wpf
ã¨ãã§ä½ã£ãã³ã¼ããåããã¦ããã ãã ã£ãã®ã§ãæ¬å½ã«ãã¤ã°ã¬ã¼ã·ã§ã³å¯è½ãªã®ãæªããæã£ã¦ã¾ããã
ãªã®ã§ãä»å㯠Windows Store ã«ãå ¬éãã¦ã以ä¸ã® WPF ã¢ããªã移è¡å¯¾è±¡ã«ãã¾ããã
ãã®ã¢ããªã¯ WPF ã ãã§ã¯ãªã Win Forms ã®ã³ã³ããã¼ã«ã WindowsFormsHost
ã使ã£ã¦ãã¹ããã¦ãã¦ãä»ã«ã WinRT ã®æ©è½ãé¨åçã«ä½¿ã£ã¦ããããããã®ã§ã移è¡ã§ããªãããã¨æã£ã¦ãã¾ãããæ´ã« P/Invoke ã COM (RCW) ã使ãã¾ãã£ã¦ãã¾ãã
çµè«ããè¨ãã¨ãæ¢åã®ã³ã¼ããå¤æ´ãããã¨ãªãå ¨ã¦ã®æ©è½ã移è¡ã§ãã¾ãããå®éã«è¡ã£ãä½æ¥å 容ãæ°ã«ãªãæ¹ãããã¨æãã®ã§ã移è¡ç¨ã® Pull Request ãä½æãã¦ããã¾ããã
å¤æ´ããã®ã¯å®è³ª csproj ãã¡ã¤ã«ã ãã§ããDesktop Bridge ã使ã£ã¦ããã¨ãããã±ã¼ã¸ã³ã°æã« Self-contained ãæå®ããå¿ è¦ããã£ãã®ã§ãwapproj ãå°ãå¤ãã£ã¦ãã¾ãã
PR ãè¦ãã¨ç°¡åããã«è¦ããã¨æãã¾ãããä½æ¥ä¸ã¯å²ã¨ã¯ã¾ã£ãã®ã§æé ãæ®ãã¾ãã
SDK ãã¼ã¹ã®ããã¸ã§ã¯ãå
ã³ã¼ãã¯å
¨ã¦ GitHub ã§ç®¡çãã¦ããã®ã§ããã©ã³ããä½æãã¦æ¢åã®ããã¸ã§ã¯ããã¡ã¤ã«ãç´æ¥å¼ãæ¹æ³ã§ä½æ¥ãã¾ãããcsproj 㯠dotnet new wpf
ã§çæããããã®ããå§ãã¾ããã
çæããã csproj ã¯ä»¥ä¸ã®ããã«ã·ã³ãã«ãª SDK ãã¼ã¹ã¨ãªãã¾ãã
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop"> <PropertyGroup> <OutputType>WinExe</OutputType> <TargetFramework>netcoreapp3.0</TargetFramework> <UseWPF>true</UseWPF> </PropertyGroup> </Project>
ä¸ã®ã³ãã³ããå®è¡ãã㨠WPF åãã®ããã¸ã§ã¯ãã«ãªãã¾ãããWin Forms ãå¿
è¦ãªå ´å㯠UseWindowsForms
ã追å ããã°ãããããã§ããããã¥ã¡ã³ãã«ä¸¡æ¹ã¨ãè¨å®å¯è½ã¨ããã¾ãã
csproj ã SDK ãã¼ã¹ã«æ¸ãæããå¾ã« Visual Studio ã§ããã¸ã§ã¯ããéãã¨ãèªåçã« xaml ãã¡ã¤ã«ç³»ã追å ãã¦ããã¾ããããªã®ã§ csproj ã¯ãããµãªã¨ç½®ãæããæ¹ãå¹çãè¯ãã§ãããã
Visual Studio ãéããå¾ã¯å¿
è¦ãª NuGet ããã±ã¼ã¸ãã¤ã³ã¹ãã¼ã«ãã¦ããã¾ããæ¢åã® WPF ã¢ããªã±ã¼ã·ã§ã³ã¯å¤§æµã¯ packages.config
ã使ã£ã¦ããã¨æãã¾ããããã®ã¾ã¾ç§»è¡ããã«ã«ã¼ãã¨ãªãããã±ã¼ã¸ã ã追å ããã¨ã·ã³ãã«ã«ãªãã¾ãã*1
ï¼å¿ è¦ã§ããã°ï¼ã¿ã¼ã²ãããã©ãããã©ã¼ã ãåºå®
SDK ãã¼ã¹ã®ããã¸ã§ã¯ãã§ã¯ããã©ã«ã㧠Any CPU ã¨ãªãã®ã§ããã©ãããã©ã¼ã ã«ä¾åãã dll ã使ã£ã¦ããå ´åã«åé¡ã¨ãªãã¾ãããªã®ã§æ示çã«ãã©ãããã©ã¼ã ãè¨å®ãã¦ããã¾ããã
<PropertyGroup> <Platforms>x86;x64</Platforms> <Platform>x64</Platform> </PropertyGroup>
ãã®è¨å®ã§ x86 㨠x64 ããã«ãã®å¯¾è±¡ã¨ãªãã¾ããããã©ã«ã㯠x64 ã«ãã¦ããã¾ããã
NuGet ã®è¦åãæå¶
ã¾ã .NET Core 3.0 ã«å¯¾å¿ãã NuGet ããã±ã¼ã¸ã¯å°ãªãã®ã§ãã¡ããã¡ãã以ä¸ã®ãããªè¦åãåºã¾ãã
warning NU1701: ããã±ã¼ã¸ 'AvalonEdit 5.0.4' ã¯ããã¸ã§ã¯ãã®ã¿ã¼ã²ãã ãã¬ã¼ã ã¯ã¼ã¯ '.NETCoreApp,Version=v3.0' ã§ã¯ãªã '.NETFramework,Version=v4.6.1' ã使ç¨ãã¦å¾©å ããã¾ããããã®ããã±ã¼ã¸ã¯ã使ç¨ãã¦ããããã¸ã§ã¯ãã¨ã®å®å ¨ãªäºææ§ããªãå¯è½æ§ãããã¾ãã
ãã¡ãã§ã¯å¯¾å¿ã§ããªãã®ã§ã©ããããããªãã§ãããæ°ã .NET Core 3.0 ã® WPF ã¯æ¢åã®ã³ã¼ãã¨äºææ§ããããããã®ã§ã対å¿ããã¾ã§ã¯è¦åãç¡è¦ããããã«ãã¾ãã
該å½ã®ã¨ã©ã¼ã³ã¼ã NU1701 ã NoWarn
ã«æå®ããã°ä¸ã®è¦åã¯åºãªããªãã¾ãã
è¨å®ããã¨ãããã½ãªã¥ã¼ã·ã§ã³ã¨ã¯ã¹ããã¼ã©ã¼ã®ä¾åé¢ä¿ã«ã¤ãã¦ããè¦åãæ¶ãã¾ããã
使ã£ã¦ããããã±ã¼ã¸ã .NET Core 3.0 ã«å¯¾å¿ããã NoWarn
ãæ¶ãã°è¯ãã§ãããã*2
WinRT ã®åç §ãä¿®æ£
ä»åã®ã¢ããªã§ã¯èªåèµ·åã®ããã« StartupTask
ã使ã£ã¦ãã¾ããããã¡ãã WinRT ã§æä¾ããã¦ãã API ãªã®ã§ãåç
§è¨å®ã追å ã§å¿
è¦ã«ãªãã¾ããä»åã®ä½æ¥ã§ä¸çªã¯ã¾ã£ãã®ãããã§ãã
API ãå®ç¾©ããã¦ãã Windows.winmd
ã¯ä»¥ä¸ã®ãµã³ãã«ããã£ãã®ã§ç°¡åã§ããã
ã¤ã³ã¹ãã¼ã«ãã¦ãã Windows SDK 㯠17763 ã ã£ãã®ã§ããã¹ã¯å°ãéãã¾ãããã£ã¦ããã¨ã¯åãã§ãã
ããã¾ã§éã Visual Studio ããåç
§ã®è¿½å ãè¡ã£ã¦ãè¯ãããã§ãããããã®å ´åã«ã¯ HintPath
ãç¸å¯¾ãã¹ã«ãªãã®ãå«ãªã®ã§ææ¸ããã¾ããã
<ItemGroup> <Reference Include="Windows"> <HintPath>$(MSBuildProgramFiles32)\Windows Kits\10\UnionMetadata\10.0.17763.0\Windows.winmd</HintPath> <Private>False</Private> </Reference> </ItemGroup>
ãã㧠WinRT ã® API ã¯åç
§ã§ããããã«ãªãã¾ããã使ãããã«ã¯ System.Runtime.WindowsRuntime.dll
ãåç
§ã«è¿½å ããªãã¨ããã¾ããããã®ã©ã¤ãã©ãªã«ã¯ IAsyncOperation<T>
ã® Awaiter å®è£
ãå
¥ã£ã¦ããã®ã§ã追å ããªã㨠await ã使ããªãã¾ã¾ã§ãã
調ã¹ãã¨å¤§ä½ã¯ Reference Assemblies å ã«ãã dll ãåç §ããã¨æ¸ãã¦ããã®ã§ããããã® dll ã使ã㨠Desktop Bridge ã§ããã±ã¼ã¸ã³ã°ããéã«ã¢ããªãèµ·åããªããªãã¾ãã
$(MSBuildProgramFiles32)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll
ããã±ã¼ã¸ã³ã°åã ã¨åãã®ã§åå ç¹å®ã«è¦å´ãã¾ãããã¨ã©ã¼ã¡ãã»ã¼ã¸ãè¯ãããããªãæãã ã£ãã®ã§ãåç §ãä¸ã¤ãã¤å¤ãã¦ç¹å®ãã¾ããã
解決æ¹æ³ã¨ãã¦ã¯ NuGet 㧠.NET Core 3.0 ã«å¯¾å¿ãããã¼ã¸ã§ã³ãå ¬éããã¦ããã®ã§ããã£ã¡ãã¤ã³ã¹ãã¼ã«ããã° Desktop Bridge ã§ããã±ã¼ã¸ã³ã°ãã¦ãåé¡ãªãåãã¾ããã
ã¡ãªã¿ã« Windows Community Toolkit ã§ã¯ NuGet çãåç
§ããã¦ããã®ã§ãã¤ã³ã¹ãã¼ã«ããã°ç¹ã«æ°ã«ãããã¨ãªã await ãªã©ã使ããç¶æ
ã«ãªãã¾ããWindows Community Toolkit èªä½ã¯ 6.0.0-preview
ãã .NET Core 3.0 ã¸ã®å¯¾å¿ãè¡ããã¦ãã¾ãã
ããã¾ã§ã®å¯¾å¿ã§ .NET Core 3.0 ã¸ã®ç§»è¡ã¯å®äºã¨ãªãã¾ããWinRT ã使ã£ã¦ããªããã°ãã£ã¨æ¥½ã§ããã
Desktop Bridge ããã¸ã§ã¯ããä¿®æ£
Desktop Bridge ã«ä½¿ãããã¸ã§ã¯ãã¯å¤§ããå¤æ´ç¹ã¯ãªãã§ãããSelf-contained ã«å¯¾å¿ããè¨å®ã«ãªã£ã¦ããªãã¨ãããªãã®ã§ãä¸åº¦ã¢ããªã±ã¼ã·ã§ã³ãåç §ãç´ãã¨ç°¡åã«å¯¾å¿ã§ããã¯ãã§ãã
ããããã£ã«ã¯èªå·±å®çµã¨ããè¨å®ãå¢ãã¦ããã®ã§ true ã«ãªã£ã¦ãããã¨ã確èªãã¾ãã
ãã®ç¶æ
ã§ãã«ããã㨠RuntimeIdentifiers
ãå¿
è¦ã¨ããã¨ã©ã¼ã«ãªãã®ã§ãWPF ã¢ããªã±ã¼ã·ã§ã³å´ã® csproj ã«ä»¥ä¸ã®ããã«ã¿ã¼ã²ããã¨ãªã RID ã追å ãã¾ãã
ç¾å®çã«ã¯ win-x86
㨠win-x64
ã®åºå®å¤ã§è¯ãã¨æãã¾ãã
<RuntimeIdentifiers>win-x86;win-x64</RuntimeIdentifiers>
å度ãã«ããè¡ãã¨ä»åº¦ã¯æåããã®ã§ãVisual Studio ããç´æ¥ãããã°å®è¡ãè¡ããããã«ãªãã¾ãã
ãµã¤ããã¼ãã«ä½¿ã appxbundle 㨠Store æåºã«ä½¿ã appxupload ãããã¾ã§éãçæã§ãã¾ãã
ã©ã³ã¿ã¤ã 㯠x86 㨠x64 ã®ä¸¡æ¹ãå«ã¾ãã¦ããã®ã§ appxupload ã®ãµã¤ãºã¯ 85MB ãããã«ãªãã¾ããããã©ã³ã¿ã¤ã ãã¤ã³ã¹ãã¼ã«ãã¦ããªã PC ã§å®è¡ã¾ã§è¡ãã¾ããã
WinRT å¨ãã§ã¤ã¾ããã¾ããããå
¨ä½çã«è¦ãã¨ã¹ã ã¼ãºã«ç§»è¡ãè¡ããã¨æãã¾ããVisual Studio 2019 RC 㯠Go Live ãä»ãã¦ããã®ã§ããã®ã¾ã¾ Store ã«æåºãã¦ãåé¡ãªãããã§ãã RTM ãå¾
ã¡ã¾ãã Go Live ãä»ããã®ã¯ VS ã ã㧠.NET Core 3.0 ã¯ãã¬ãã¥ã¼ã®ã¾ã¾ãªã®ã§ããããç¡çã§ããã