在上一篇在VS2015 RC打開CTP中創建的工程,我們介紹了怎么在RC中打開CTP中創建的Universal 工程,這一篇我們來講下怎么將Windows 8.1/WP8.1的應用遷移到Universal Windows Platform上。
2015RC中,我們可以將8.1的應用遷移到統一平台上,進而使用新的API進行開發,下面我們使用wp8.1的應用作為例子講解下步驟。
1. 首先我們使用2015打開之前的工程。
2. 右鍵點擊工程,選擇“卸載項目”。
3. 右鍵點擊工程,選擇“編輯XXX.csproj”
4. 和上一篇一樣,取得平台版本號,路徑是“\Program Files (x86)\Windows Kits\10\Platforms\UAP”
下面就開始修改工程文件了
5. 找到個包含子節點TargetPlatformVersion、且值為8.1的PropertyGroup節點(其實一般第一個PropertyGroup就是了),進行下面的修改:
- 把Platform的值改成x86
- 添加TargetPlatformIdentifier節點,值為UAP
- 把TargetPlatformVersion的值改成4中取得的版本號
- 添加TargetPlatformMinVersion節點,值為4中的版本號
- 把MinimumVisualStudioVersion的值改成14
- 把ProjectTypeGuids的值改成{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
- 添加EnableDotNetNativeCompatibleProfile節點,值為true
6. 把所有的vs版本從12.0替換成14.0,這一步直接替換即可(CTRL+H)
7. 刪掉配置為AnyCPU的PropertyGroup節點
8. 查看剩下配置是Release的PropertyGroup節點,如果下面沒有UseDotNetNativeToolchain子節點的話,就動手加一個,值一定要是true, 即:<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
9. 如果是手機項目的話,還需要刪除下面這個節點
10. 現在重新加載我們的工程,會發現工程類型變成了Windows Universal了!下面還是需要修改manifest。
11. 打開manifest文件,首先我們需要替換掉所有的schema,把Package節點用下面這段替換。
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" IgnorableNamespaces= "uap mp">
對於Win8.1應用,還需要額外添加mp:PhoneIdentity的節點,如下,其中PhoneProductId就是Identity的Name, PhonePushedId目前是固定的值
<Identity Name="fe8a6971-8349-489b-8941-83dd308e9b9b" Publisher="CN=xxxxxxx" Version="1.0.0.0" /> <mp:PhoneIdentity PhoneProductId="fe8a6971-8349-489b-8941-83dd308e9b9b" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
12. 在Package下添加如下子節點,其中的版本號就是我們之前一直用的
<Dependencies> <TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.10069.0" MaxVersionTested="10.0.10069.0" /> </Dependencies>
13. 刪除Prerequisites節點
14. 檢查你的Resources節點,如果是用到了Scale和DXFeatureLevel的話,為他們加上uap命名空間,如下
<Resources> <Resource Language="x-generate"/> <Resource uap:Scale="180"/> <Resource uap:DXFeatureLevel="dx11"/> </Resources>
15. 檢查你的Capability節點,如果使用聲明了下列這些權限,需要加上uap命名空間。
- documentsLibrary
- picturesLibrary
- videosLibrary
- musicLibrary
- enterpriseAuthentication
- sharedUserCertificates
- removableStorage
- appointments
- contacts
如:
<Capabilities> <uap:Capability Name="documentsLibrary"/> <uap:Capability Name="removableStorage"/> </Capabilities>
16. 將VirsualElements節點及其子節點的命名空間改成uap
<uap:VisualElements DisplayName="App9" Square150x150Logo="Assets\Logo.png" Square44x44Logo="Assets\SmallLogo.png" Description="App9" BackgroundColor="transparent"> <uap:DefaultTile Wide310x150Logo="Assets\WideLogo.png" Square71x71Logo="Assets\Square71x71Logo.png"/> <uap:SplashScreen Image="Assets\SplashScreen.png"/> </uap:VisualElements>
對於Win8.1應用,這里需要注意的是,屬性Square{SIZE}Logo中的size有了變化,70x70變成了71x71, 30x30變成44x44.
舊的:
<m2:VisualElements … Square30x30Logo="Assets\SmallLogo.png" …> <m2:DefaultTile … Square70x70Logo="images/70x70.png"> </m2:VisualElements>
新的:
<uap:VisualElements … Square44x44Logo="Assets\SmallLogo.png" …> <uap:DefaultTile … Square71x71Logo="images/70x70.png"> </uap:VisualElements>
17. 檢查Extensions節點,為下列節點添加命名空間uap
- windows.accountPictureProvide
- windows.alarm
- windows.appointmentsProvider
- windows.autoPlayContent
- windows.autoPlayDevice
- windows.cachedFileUpdate
- windows.cameraSettings
- windows.fileOpenPicker
- windows.fileTypeAssociation
- windows.fileSavePicke
- windows.lockScreenCall
- windows.printTaskSettings
- windows.protocol
- windows.search
- windows.shareTarget
如:
<Extensions> <uap:Extension Category="windows.alarm"/> <uap:Extension Category="windows.search" EntryPoint="MyActivateableClassId.baz"/> <uap:Extension Category="windows.protocol"> <uap:Protocol Name="mailto" DesiredView="useHalf"> <uap:DisplayName>MailTo Protocol</uap:DisplayName> </uap:Protocol> </uap:Extension> </Extensions>
18. 為類型為chatMessageNotification的后台任務加上uap命名空間
如:
<Extension Category="windows.backgroundTasks" EntryPoint="Fabrikam.BackgroundTask" Executable="MyBackground.exe"> <BackgroundTasks ServerName="MyBackgroundTasks"> <uap:Task Type="chatMessageNotification"/> </BackgroundTasks> </Extension>
19. 修改PackageDependency,添加Publisher和MinVersion屬性
<Dependencies> <PackageDependency Name="Microsoft.VCLibs.120.00" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" MinVersion="12.0.30113.0" /> </Dependencies>
20. 將類型為gattCharacteristicNotification 和rfcommConnection的后台任務替換為Bluetooth類型。
<Extension Category="windows.backgroundTasks" EntryPoint="Fabrikam.BackgroundTask" Executable="MyBackground.exe"> <BackgroundTasks ServerName="MyBackgroundTasks"> <Task Type="bluetooth"/> </BackgroundTasks> </Extension>
21. 使用新的bluetooth capability替換bluetooth.rfcomm和bluetooth.genericAttributeProfile
舊的:
<Capabilities> <m2:DeviceCapability Name="bluetooth.rfcomm"> <m2:Device Id="any"> <m2:Function Type="serviceId:34B1CF4D-1069-4AD6-89B6-E161D79BE4D8"/> </m2:Device> </m2:DeviceCapability> <m2:DeviceCapability Name="bluetooth.genericAttributeProfile"> <m2:Device Id="any"> <m2:Function Type="name:heartRate"/> </m2:Device> </m2:DeviceCapability> </Capabilities>
新的:
<Capabilities> <uap:DeviceCapability Name="bluetooth"/> </Capabilities>
22. 刪除Windows.contact和windows.contactPicker擴展
23. 刪除VisualElements的ForgroundText和ToastCapable屬性
24. 刪除DefaultTitle的DefaultSize屬性
25. 刪除ApplicationView節點
26. 到此manifest文件就修改完了,保存吧!雖然看上去步驟有點多,其實17之后的很多步驟可能是用不到的
27. 下面我們需要刪除一些額外的文件
- 檢查解決方案目錄下的子目錄"\.vs\{project name}\v14",如果存在".suo"文件,刪掉它
- 刪除掉工程目錄下所有的后綴為.csproj.user文件
現在我們的工程就已經成功的遷移到了Universal Windows Platform了,但是對於很多應用來說,還是需要進一步修改code,因為Windows 10的很多API都有了變化。