未加星标

Windows 10 1607, UWP Apps Packaged with ‘Companion’ Desktop Apps

字体大小 | |
[系统(windows) 所属分类 系统(windows) | 发布者 店小二05 | 时间 2016 | 作者 红领巾 ] 0人收藏点击收藏

This post follows on from a few earlier posts around desktop app conversion and desktop apps packaged in .appx format for the windows Store (or other means of deployment).

The long list of posts ishere but I’d pull out 3-4 as below.

yesterday’s post about calling UWP APIs from a desktop app thisprevious post where I started from source code and built out a .appx package for a blank WPF app thisprevious post where I took the source for ‘Open Live Writer’ and tried to make it into a .appx packaged app thisprevious post with a video which walks through using the Desktop App Converter (DAC) from start to finish. As an aside, since that earlier post ‘Open Live Writer’ is now in the Windows Store packaged as a UWP app which is very cool to see
Windows 10 1607, UWP Apps Packaged with ‘Companion’ Desktop Apps

Across those posts I’ve written pieces around;

How a desktop app can use quite a number of UWP APIs without having to do anything special. How a desktop app packaged as a UWP app can use more UWP APIs (i.e. those requiring a ‘package identity’). How the Visual Studio gallery has a template that can help you go around the deploy->debug cycle when working on these apps. How you can use the Desktop App Converter to take an existing setup/MSI and get to a .appx package.

and these ideas fall nicely into the categories of ‘Convert’ and ‘Enhance’ as explained in this great post on the Windows blog;

“Choosing the path forward for existing desktop apps”

which is well worth a detailed read as it covers a lot of areas in a short article.

One thing that I haven’t written about is the idea that a ‘desktop app’ and a ‘UWP app’ can both sit in the same application package to be deployed to a user’s machine.

This is what the Windows blog article refers to as the ‘Extend’ phase and the blog points to this this sample on github;

App Service Bridge Sample

The essential idea here is that you might hit a situation where you can build out most of your functionality into a UWP app but maybe there’s some code that’s not easy to migrate or maybe the UWP doesn’t have the APIs that you need and that code has to stay packaged in a desktop app.

The sample shows how such a desktop app and a UWP app can be packaged into a single .appx and deployed together and it also shows how they can then communicate with each other (via App Services) such that one can lean on the other to gain functionality.

In the sample, the UWP app launches the desktop app and Windows 10 1607 introduced the FullTrustProcessLauncher API to facilitate this but it’s also possible to go in the other direction and have the desktop app launch the UWP app.

I like samples but I also like to pull things apart for myself and so I did a quick walk-through of what’s needed to get started with this and I’m sharing that below. It’s not adding anything to the sample other than a step-by-step build up of something similar.

Note that in the walk through here I’m not concentrating on the possible dependencies of my desktop app, I’m purely thinking about how to get started…

Step 1 Make a Blank WPF Application

I did a quick File->New project and made a blank WPF application that displays ‘Hello World’. I gave it a UI which is a TextBlock;

<Grid> <Viewbox> <TextBlock x:Name="txtDisplay" /> </Viewbox> </Grid>

and some code behind;

public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); this.Loaded += OnLoaded; } void OnLoaded(object sender, RoutedEventArgs e) { this.DisplayText("Default Text"); } void DisplayText(string text) { this.Dispatcher.Invoke( () => { this.txtDisplay.Text = text; } ); } } Step 2 Make a Blank UWP Application

Into the same solution, I added a new UWP application. I set it to use the 14393 SDK as both minimum/maximum versions and I gave it a UI which is just a button;

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <Button Content="Click Me" Click="OnClick" /> </Grid>

and some code behind which doesn’t do anything;

public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); } void OnClick(object sender, RoutedEventArgs e) { } }

I now have 2 projects in the solution as per the screenshot below;


Windows 10 1607, UWP Apps Packaged with ‘Companion’ Desktop Apps
Step 3 Get the WPF App into the UWP App’s Package

I need to make sure that when the UWP app’s .appx package is built, it includes the binaries for the WPF app.

I made sure that the WPF app would build first using the ‘Project Dependencies’ dialog;


Windows 10 1607, UWP Apps Packaged with ‘Companion’ Desktop Apps

and then tried to make sure that the outputs from the build would be copied using this post-build action on the UWP project;

xcopy /S /Y $(SolutionDir)bin\$(ConfigurationName)\MyWpfApp.exe “$(TargetDir)\AppX\”

Note that I’m not at all sure that this would work when it comes to creating a package for Store via Visual Studio it might need more manual work to get that working but I think this will work for me while deploying and debugging from Visual Studio itself.

Note also that, initially, I copied everything from the output folder of the WPF app to the Appx folder of the UWP. That proved to be a bad idea as the copy ended up overwriting things like Windows.md because the WPF app’s output folder has one of those in it and I then found that I wandered into weird exceptions that were a bit tricky to diagnose. Hence, I ended up just copying the .EXE from the WPF app for now.

Step 4 Referencing the Windows UWP Desktop Extensions

The FullTrustProcessLauncher API is part of the Windows 10 Desktop extension SDK and so there’s a need to reference that extension before using the API;


Windows 10 1607, UWP Apps Packaged with ‘Companion’ Desktop Apps
Step 5 Make the API Call to Launch the Desktop App

I can now change the code-behind in the UWP app so as to launch the desktop app when the button is pressed;

async void OnClick(object sender, RoutedEventArgs e) { await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync(); }

but the app’s going to need to know which executable it is and so there’s a need to change the manifest to tell it.

Step 6 Manifest Changes

I opened up the manifest for the UWP app in the XML editor and made a number of changes to it.

Firstly, I changed the target such that I was only targeting the desktop device fami

本文系统(windows)相关术语:三级网络技术 计算机三级网络技术 网络技术基础 计算机网络技术

主题: WindowsWPFUWVisual StudiVisual StudioXML
分页:12
转载请注明
本文标题:Windows 10 1607, UWP Apps Packaged with ‘Companion’ Desktop Apps
本站链接:http://www.codesec.net/view/482207.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(windows) | 评论(0) | 阅读(41)