天天看點

windows桌面應用程式_如何将Windows桌面應用程式轉換為通用Windows應用程式

windows桌面應用程式_如何将Windows桌面應用程式轉換為通用Windows應用程式

windows桌面應用程式

windows桌面應用程式_如何将Windows桌面應用程式轉換為通用Windows應用程式

With Windows 10’s Anniversary Update, Microsoft is making it possible for developers to convert traditional Windows desktop applications to Universal Windows Platform (UWP) applications. But anyone can do this with any app–not just developers.

借助Windows 10的周年更新 ,Microsoft使開發人員可以将傳統的Windows桌面應用程式轉換為通用Windows平台(UWP)應用程式。 但是任何人都可以使用任何應用程式執行此操作,而不僅僅是開發人員。

With Windows 10’s converter, just give it a .msi or .exe file and it’ll spit out a .appx package. You can then sideload this app on your own PC, or–if you’re the application’s developer–you can submit the resulting UWP app to the Windows Store. This feature will arrive for everyone with Windows 10’s Anniversary Update, bringing many “legacy” applications to the Windows Store.

使用Windows 10的轉換器,隻需為其提供.msi或.exe檔案,它就會吐出.appx程式包。 然後,您可以在自己的PC上側面加載此應用程式,或者-如果您是該應用程式的開發人員-您可以将生成的UWP應用程式送出到Windows應用商店。 Windows 10周年更新将為所有人提供此功能, 進而将許多“舊版”應用程式帶到Windows應用商店 。

為什麼要這樣做 (Why You’d Want to Do This)

This feature is the end result of Microsoft’s Project Centennial, which is designed to bring those “legacy” Win32 and .NET Windows desktop applications to the Windows Store and the new Universal Windows Platform.

此功能是Microsoft Project Centennial的最終結果,該項目旨在将這些“舊版” Win32和.NET Windows桌面應用程式引入Windows應用商店和新的通用Windows平台。

You might wonder why anyone would want to convert a desktop application to a new UWP app. For one thing, only UWP apps are allowed in the Windows Store. This allows developers to get a lot more eyes on their apps, not to mention single-click installation, easy purchasing, and automatic updates.

您可能想知道為什麼有人會想要将桌面應用程式轉換為新的UWP應用程式。 一方面,Windows應用商店中僅允許使用UWP應用。 這使開發人員可以更加關注自己的應用程式,更不用說單擊安裝,輕松購買和自動更新了。

Microsoft’s new UWP application platform is sandboxed, but desktop apps you convert are not. These applications will have full access to your system, just like a traditional desktop application. As Microsoft’s documentation says: “As a UWP app, your app is able to do the things it could do as a classic desktop app. It interacts with a virtualized view of the registry and file system that’s indistinguishable from the actual registry and file system.”

Microsoft的新UWP應用程式平台已沙盒化,但您轉換的桌面應用程式卻沒有。 這些應用程式将具有對系統的完全通路權限,就像傳統的桌面應用程式一樣。 正如Microsoft的文檔所述 :“作為UWP應用,您的應用能夠執行其作為經典桌面應用所能做的事情。 它與系統資料庫和檔案系統的虛拟化視圖進行互動,這與實際的系統資料庫和檔案系統沒有差別。”

局限性 (The Limitations)

There are some important limitations here. First, you can only do this on the Windows 10 Anniversary Update. For now, it’ll work with Windows 10 Insider Preview build 14316 and higher, so you’ll need to join the Windows Insider program and use an Insider Preview build of Windows 10.

這裡有一些重要的限制。 首先,您隻能在Windows 10周年更新中執行此操作。 目前,它可與Windows 10 Insider Preview内部版本14316和更高版本一起使用,是以您需要加入Windows Insider程式并使用Windows 10 Insider Preview内部版本 。

This feature also requires either the Professional or Enterprise editions of Windows 10. Windows 10 Home users won’t be able to use the Desktop App Converter. As of build 14316, it only worked on Windows 10 Enterprise, but support for Windows 10 Professional is coming. Currently, this tool can only be used on 64-bit versions of Windows, and the resulting AppX package can only be installed on 64-bit versions of Windows. This will change in future Insider builds of Windows 10.

此功能還需要Windows 10的專業版或企業版。Windows 10家庭使用者将無法使用Desktop App Converter。 從内部版本14316開始,它僅适用于Windows 10 Enterprise,但即将支援Windows 10 Professional。 目前,此工具隻能在Windows的64位版本上使用,并且生成的AppX軟體包隻能在Windows的64位版本上安裝。 這将在Windows 10的将來Insider版本中改變。

The resulting applications are intended for Windows 10 PCs. They won’t work on Windows 10 Mobile smartphones, Xbox One, HoloLens, Surface Hub, and the other Windows 10 platforms that run UWP apps. However, if you’re a developer, Microsoft offers a path to getting your desktop application into a cross-platform UWP application: “If you choose to move all of your app’s functionality out of the full-trust partition of the app and into the app container partition, then your app will be able to run on any Windows 10 device.”

生成的應用程式适用于Windows 10 PC。 它們不适用于Windows 10移動智能手機,Xbox One,HoloLens,Surface Hub和其他運作UWP應用的Windows 10平台。 但是,如果您是開發人員,Microsoft提供了一種将桌面應用程式轉換為跨平台UWP應用程式的途徑:“如果您選擇将應用程式的所有功能移出應用程式的完全信任分區,并移至應用程式的應用容器分區,那麼您的應用将可以在任何Windows 10裝置上運作。”

However, some types of application behavior aren’t supported. An application can’t require it be run as Administrator or use other types of low-level system access. Microsoft provides a list of behaviors that aren’t allowed.

但是,不支援某些類型的應用程式行為。 應用程式不能要求其以管理者身份運作或使用其他類型的低級系統通路權限。 Microsoft提供了不允許的行為清單。

如何設定桌面應用轉換器 (How to Set Up the Desktop App Converter)

Assuming you’re using a new enough build of the Windows 10 Insider Preview, you can download and install the Desktop App Converter from Microsoft’s Developer site. Download both the DesktopAppConverter.zip and BaseImage-14316.wim files. Extract the downloaded DesktopAppConverter.zip file to a folder on your computer and place the BaseImage file in the same directory. (If there’s a new build of Windows 10 available, you should see a new BaseImage file. You’ll need to use the BaseImage file with the same version number as your installed build of Windows 10.)

假設您正在使用足夠新的Windows 10 Insider Preview版本,則可以從Microsoft的Developer網站下載下傳并安裝Desktop App Converter 。 下載下傳DesktopAppConverter.zip和BaseImage-14316.wim檔案。 将下載下傳的DesktopAppConverter.zip檔案解壓縮到計算機上的檔案夾中,然後将BaseImage檔案放置在同一目錄中。 (如果有可用的Windows 10的新版本,則應該看到一個新的BaseImage檔案。您需要使用與已安裝的Windows 10的版本号相同的BaseImage檔案。)

You’ll also need to download and install the Windows 10 SDK.

您還需要下載下傳并安裝Windows 10 SDK 。

windows桌面應用程式_如何将Windows桌面應用程式轉換為通用Windows應用程式

Next, open a PowerShell window as Administrator. To do so, open the Start menu, search for “PowerShell,” right-click its shortcut, and select “Run as Administrator.”

接下來,以管理者身份打開PowerShell視窗。 為此,請打開“開始”菜單,搜尋“ PowerShell”,右鍵單擊其快捷方式,然後選擇“以管理者身份運作”。

Change PowerShell’s execution policy by running the following command. Agree to the change by typing

y

afterwards.

通過運作以下指令來更改PowerShell的執行政策。 稍後輸入

y

同意更改。

Run the command below, replacing

C:\Users\NAME\Downloads\DesktopAppConvertor

with the path to the directory on your computer:

運作以下指令,将

C:\Users\NAME\Downloads\DesktopAppConvertor

替換為計算機上目錄的路徑:

Set up the Desktop App Converter by running the following command:

通過運作以下指令來設定Desktop App Converter:

If you’re asked to reboot while running any of these commands, reboot your computer and then run the command again.

如果在運作這些指令時要求重新啟動計算機,請重新啟動計算機,然後再次運作該指令。

windows桌面應用程式_如何将Windows桌面應用程式轉換為通用Windows應用程式

如何轉換桌面應用程式 (How to Convert a Desktop Application)

You can now run the

DesktopAppConverter.ps1

script from an Administrator PowerShell window to convert a desktop application to a UWP application in a single command. You’ll need the application’s installer to do this. As an example, we’ll use VLC here.

現在,您可以從Administrator PowerShell視窗運作

DesktopAppConverter.ps1

腳本,以單個指令将桌面應用程式轉換為UWP應用程式。 您将需要應用程式的安裝程式來執行此操作。 例如,我們将在這裡使用VLC。

To view the detailed list of options, you can run the following command at any time:

要檢視選項的詳細清單,您可以随時運作以下指令:

Here’s a command you can use and adjust for your application:

這是您可以為應用程式使用和調整的指令:

.\DesktopAppConverter.ps1 -ExpandedBaseImage C:\ProgramData\Microsoft\Windows\Images\BaseImage-14316
 –Installer C:\Installer\MyApp.exe -InstallerArguments "/S" -Destination C:\Output\MyApp
 -PackageName "MyApp" -Publisher "CN=<publisher_name>" -Version 0.0.0.1 -MakeAppx -Verbose           

You’ll need to adjust the command to add your own publisher name, version, package name, and point it at the installer file and destination directory you prefer. The

-InstallerArguments "/S"

option here passes the

/S

switch to the installer, which makes many application installers install silently without any user input. Applications must be installable without any user input or you can’t convert them.

您需要調整指令以添加自己的釋出者名稱,版本,程式包名稱,并将其指向您喜歡的安裝程式檔案和目标目錄。 這裡的

-InstallerArguments "/S"

選項将

/S

開關傳遞給安裝程式,這使許多應用程式安裝程式在沒有任何使用者輸入的情況下靜默安裝。 應用程式必須可在沒有任何使用者輸入的情況下安裝,否則您将無法轉換它們。

The application’s installer should be in its own directory without any other files, as the files in the same directory as the installer will be copied into the resulting .appx package.

應用程式的安裝程式應位于其自己的目錄中,沒有任何其他檔案,因為與安裝程式位于同一目錄中的檔案将被複制到生成的.appx包中。

For example, we’re using VLC here, so here’s the command we’d use:

例如,我們在這裡使用VLC,是以這是我們要使用的指令:

.\DesktopAppConverter.ps1 -ExpandedBaseImage C:\ProgramData\Microsoft\Windows\Images\BaseImage-14316
 –Installer C:\Users\chris\Downloads\vlc\vlc-2.2.2-win32.exe -InstallerArguments "/S" -Destination C:\Output\VLC
 -PackageName "VLC" -Publisher "CN=VideoLAN" -Version 0.2.2.2 -MakeAppx -Verbose           
windows桌面應用程式_如何将Windows桌面應用程式轉換為通用Windows應用程式

The tool will give you an .appx package, which is the UWP version of the app.

該工具将為您提供.appx包,這是應用程式的UWP版本。

windows桌面應用程式_如何将Windows桌面應用程式轉換為通用Windows應用程式

如何在不簽名的情況下安裝應用 (How to Install the App Without Signing It)

You’re normally required sign apps with a valid signature before they can be installed. Microsoft recommends creating a self-signed certificate and signing the app with that on your computer. You can do that using the instructions below, if you like.

通常,要求您先使用有效簽名對應用進行簽名,然後才能進行安裝。 Microsoft建議建立一個自簽名證書,并使用您計算機上的證書對應用程式進行簽名。 如果願意,可以按照以下說明進行操作。

However, if you just want to install the app on your own computer, you can do this yourself faster, without messing with any signatures. Windows 10 allows you to install apps without signing them if you’re installing an “unpackaged” app from a directory.

但是,如果您隻想在自己的計算機上安裝該應用程式,則可以自己完成此操作,而不會弄亂任何簽名。 如果從目錄中安裝“未打包”的應用程式,則Windows 10允許您安裝應用程式而無需對其進行簽名。

To do this, open a PowerShell window as Administrator and run the following command:

為此,請以管理者身份打開PowerShell視窗并運作以下指令:

You’ll find the AppxManifest.xml file next to the Application.appx file in the output directory you specified.

您可以在指定的輸出目錄中的Application.appx檔案旁邊找到AppxManifest.xml檔案。

You can now launch the application from your Start menu. It will be a “Windows app” instead of a “Desktop app,” but it will otherwise look and work like a normal desktop app.

現在,您可以從“開始”菜單啟動應用程式。 它将是“ Windows應用程式”,而不是“桌面應用程式”,但在外觀和工作方式上将與普通的桌面應用程式相似。

windows桌面應用程式_如何将Windows桌面應用程式轉換為通用Windows應用程式

如何簽名和安裝應用程式 (How to Sign and Install the App)

You don’t need to follow these instructions if you’ve already installed the application. This is the harder way.

如果您已經安裝了該應用程式,則無需遵循這些說明。 這是更困難的方法。

You can normally only install an .appx package if it has a valid signature. Microsoft recommends using the signtool.exe application included with the Windows 10 SDK to create a self-signed certificate, which will allow you to install and test the application on your own computer.

通常,隻有具有有效簽名的.appx軟體包才能安裝。 Microsoft建議使用Windows 10 SDK随附的signtool.exe應用程式來建立自簽名證書,該證書将允許您在自己的計算機上安裝和測試該應用程式。

Just open a Command Prompt window as Administrator and run the following commands to create a self-signed certificate and sign the .appx package with it:

隻需以管理者身份打開“指令提示符”視窗,然後運作以下指令來建立自簽名證書,并使用它對.appx包進行簽名:

Note that the publisher you specify–that’s the

"CN=Publisher"

–must match the publisher you specified earlier when creating the AppX file. So, continuing with our VLC example from above, we’d have to use

"CN=VideoLAN"

.

請注意,您指定的釋出者(即

"CN=Publisher"

必須與建立AppX檔案時先前指定的

"CN=Publisher"

者比對。 是以,從上面繼續我們的VLC示例,我們将不得不使用

"CN=VideoLAN"

You’ll be asked to enter a password. You can just leave the password blank.

系統将要求您輸入密碼。 您可以将密碼留白。

windows桌面應用程式_如何将Windows桌面應用程式轉換為通用Windows應用程式

You can now install the .appx package in a PowerShell (Administrator) window with the Add-AppxPackage command:

現在,您可以使用Add-AppxPackage指令在PowerShell(管理者)視窗中安裝.appx軟體包:

This feature can be used by anyone, but only developers–and maybe some system administrators–will want to go this route. Luckily, the process is extremely easy for developers.

任何人都可以使用此功能,但隻有開發人員(也許還有一些系統管理者)才願意采用此功能。 幸運的是,該過程對于開發人員而言非常容易。

翻譯自: https://www.howtogeek.com/250041/how-to-convert-a-windows-desktop-app-to-a-universal-windows-app/

windows桌面應用程式