Windows Phone 7 安裝封包檔 xap

  • 20021
  • 0

Windows Phone 7 安裝封包檔 xap

如果還在從事Windows Mobile 應用程式開發人員在完成開發後都會將專案封包成cab 檔,在來透過Active Sync 或 Windows Mobile Device Center把cab檔派遣到機器上,或是把cab檔放在手機裏開啓並安裝。


image

現在Windows Phone 7把封包檔以.xap格式的封裝取代.cab格式成為安裝檔案,.xap也是採用.zip檔案的封裝方式,其實把xap重新命名副檔名為.zip就可以解壓出所需的檔案,但是Windows Phone 7上的.xap檔將在安全沙箱中運行,使用者不會很簡單的取出.xap檔,讓程式的反編譯變得困難加強了應用程式的安全性減低被破解的機會。下面這篇文章是從xda 論壇解譯什麼xap

What's a .xap

A .xap is a simple, every day .zip file, renamed to .xap. Inside, it contains the app and all relevant dependencies. There are a number of possible .xml files that could be included inside the .xap to determine things like required security access level, to tell the system which .dll contains the main() for the application, etc.
I believe the .zip also provides a container for the virtual filesystem available to the app (not sure on that, it may be stored in a separate container, have to analyze more)
At least initially, .xaps will only be available for deployment through the Marketplace.
Regarding preloaded applications by OEM/MO: Requirements are much more strict in this regard now due to frequent end-user complaints about "slow, laggy, etc" Stock ROMs. I know every one of you reading this knows what I mean Preloaded App Requirements (which will be distributed as .xap) as follows:

  • Maximum of 6 preloaded applications on the device, not to exceed 60MB
  • All preloaded apps must pass Marketplace submission process (some extended APIs are available to OEM/MO so the process is slightly relaxed in that regard)
  • The application(s) and all future updates must be free of charge.
  • The apps must launch without dependency on network availability.
  • The apps must persist through a "hard reset".
  • The apps must be updatable and revocable (!!!!) through the Marketplace.
  • The apps must notify the user at first launch of any capabilities to be utilized and get user consent (to access compass, accelerometer, network, etc.)

原文轉貼 http://forum.xda-developers.com/showthread.php?t=649901

 

大家一定很好奇xap封包檔會包什麼東西,大家可以試著把xap檔改副檔名變為zip就可以看到了,其實他封包了如下圖紅框所示的檔案基本檔,如果在專案裡面有附加目錄及檔案也是會把他加入到xap檔裡,在Windows Phone 7 好處是不用在建立一個部署專案來產生封包檔直接按下建置就會自動把封包檔建好很方便。

image

接下我要分享我知道的三種方式來部署xap檔至機器上

1.我相信這種大家一定會如下圖所示就是從vs2010開發工具來部署測試

 image image

image

2.如果有安裝開發工具在C:\Program Files\Microsoft SDKs\Windows Phone\v7.0\Tools\XAP Deployment目錄下有一支執行檔XapDeploy.exe,點二下執行起來後在Target可以挑選裝置來源,xap文字方塊可以手動輸入位置或是透過Browse按鍵來登錄你的xap檔案路徑,接下來點下Deploy鈕來安裝檔案最後看到Status:顯示為XAP Deployment Complete 代表封包檔已經裝好了,此時可以從模擬器測試我們所部署的應用程式

image

3.寫一支PC端應用程式透過Windows Phone 7 CoreCon SDK 來安裝封包檔至機器順便啟動應用程式

3.1首先開啟vs2010新增一個空白專案在來加入WindowsForm應用程式專案和WindowsPhoneApplication專案

image

3.2在WindowsForm專案名稱按下滑鼠右鍵點選加入參考點瀏覽頁面搜尋位置到C:\Program Files\Common Files\microsoft shared\Phone Tools\CoreCon\10.0\Bin目錄下選取Microsoft.Smartdevice.Connectivity.dll加入參考

image

3.3在WindowsForm應用程式Form1上產生三個按鈕:連結、安裝、啟動

image

3.4打開Form1.CS在Form1 Calss裡面輸入下列代碼為共公變數

      DatastoreManager dsmgrObj;
      Device WP7Device;
      RemoteApplication app;

3.5在畫面連結鈕按二下輸入下列代碼

           //取得裝置來源訊息

          dsmgrObj = new DatastoreManager(1033);
            Platform WP7SDK = dsmgrObj.GetPlatforms().Single(p => p.Name == "Windows Phone 7");
            bool useEmulator = true;
            if (useEmulator)
                WP7Device = WP7SDK.GetDevices().Single(d => d.Name == "Windows Phone 7 Emulator");
            else
                WP7Device = WP7SDK.GetDevices().Single(d => d.Name == "Windows Phone 7 Device");

            //連結裝置來源
            WP7Device.Connect();

3.6在畫面安裝鈕按二下輸入下列代碼

           //此Guid為WindowsPhoneApplication的ProductID存放在WMAppManifest.xml

           Guid appID = new Guid("{ee74be39-883a-4672-b26a-e2896b29cba0}");

           //判斷此項應用軟體是否安裝
            if (WP7Device.IsApplicationInstalled(appID))
           {
               app = WP7Device.GetApplication(appID);

               //移除機器安裝過的軟體
               app.Uninstall();
           }

           //指定安裝的xap檔案到機器上
           app = WP7Device.InstallApplication(appID, appID, "NormalApp",
                                              @"C:\Users\Waigha-W7\Documents\Visual Studio 2010\Projects\InstallSolution\WindowsPhoneApplication1\WindowsPhoneApplication1\Bin\Debug\ApplicationIcon.png",
                                            @"C:\Users\Waigha-W7\Documents\Visual Studio 2010\Projects\InstallSolution\WindowsPhoneApplication1\WindowsPhoneApplication1\Bin\Debug\WindowsPhoneApplication1.xap");

 

3.7在畫面啟動鈕按二下輸入下列代嗎

//啟動安裝好的軟體

app.Launch();

3.8啟動WindowsForm1應用程式先按連結鍵看看模擬器是否有跑出來,接著按下安裝把軟體安裝至機器上,最後按下啟動看看模擬器是否有執行應用軟體

image

程式碼下載