2012-11-16 146 views
5

我對windows phone開發非常陌生。我想開發一個應用程序,當我將Windows 8手機連接到我的筆記本電腦時將會啓動該應用程序。我按照這個教程(http://justinangel.net/WindowsPhone7EmulatorAutomation),並能夠連接到我的Windows 7手機/模擬器,但我無法連接到我的Windows 8手機或模擬器。有沒有其他方式連接到Windows 8手機?連接到Windows Phone 8使用控制檯應用程序

請讓我知道,如果有這方面的任何可能的解決方案,

謝謝

回答

7

我沒有得到一個機會,但更新這個博客帖子。 Delvis Gomez(我的一位同事)已經更新了最終的代碼示例,並將其自由分發。我將來會更新WP8的博客文章,但同時這裏有一個關於如何自動化WP8 Emulator的非常詳細的文檔代碼片段。

此外,請確保添加對像Microsoft.SmartDevice.MultiTargeting.Connectivity所需的新DLL的引用。

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading; 
using System.IO; 
using System.Reflection; 

// Libraries needed to connect to the Windows Phone X Emulator 
using Microsoft.SmartDevice.Connectivity; 
using Microsoft.SmartDevice.Connectivity.Interface; 
using Microsoft.SmartDevice.MultiTargeting.Connectivity; 
using System.Globalization; 
using System.Collections.ObjectModel; 


namespace AutomatedUnitTestDriver 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      MultiTargetingConnectivity connectivity = new MultiTargetingConnectivity(CultureInfo.CurrentUICulture.LCID); 

      // Get a connectable device for a specific Device ID (from the CoreCon datastore) 
      string deviceId = "5E7661DF-D928-40ff-B747-A4B1957194F9"; 
      ConnectableDevice connectableDevice = connectivity.GetConnectableDevice(deviceId); 
      Console.WriteLine("Found Connectable Device \'" + connectableDevice.Name + "\' for Device id {" + connectableDevice.Id + "}."); 

      // Connect to the Device 
      Console.WriteLine("Connecting to Device..."); 
      IDevice iDevice = connectableDevice.Connect(); 
      Console.WriteLine("Done!"); 

      // Check if the application is already install, if it is remove it (From WMAppManifect.xml) 
      Guid appID = new Guid("{b6635769-b7ac-41a5-915d-5a7b0ae34481}"); 

      if (iDevice.IsApplicationInstalled(appID)) 
      { 
       Console.WriteLine("Uninstalling application..."); 
       iDevice.GetApplication(appID).Uninstall(); 
       Console.WriteLine("Done!"); 
      } 

      Guid productId = appID; 
      Guid instanceId = appID; 
      string applicationGenre = "NormalApp"; 
      string iconPath = @"C:\Share\LatestAPI\TestCode\Automated\AutomatedUnitTests\Bin\Debug\ApplicationIcon.png"; 
      string xapPackage = @"C:\Share\LatestAPI\TestCode\Automated\AutomatedUnitTests\Bin\Debug\AutomatedUnitTests.xap"; 

      // Install the application 
      Console.WriteLine("Installing the application..."); 
      IRemoteApplication remoteApplication = iDevice.InstallApplication(appID, appID, applicationGenre, iconPath, xapPackage); 
      Console.WriteLine("Done!"); 

      // Launch the application 
      Console.WriteLine("Starting the application..."); 
      remoteApplication.Launch(); 

      int startStopWaitTime = 1000; // msec 
      int executionWaitTime = 180000; // msec 

      // Note that IRemoteApplication has a 'IsRunning' method but it is not implemented. 
      // So, for the moment we sleep few msec. 
      Thread.Sleep(startStopWaitTime); 
      Console.WriteLine("Done!"); 

      // Allow application to complete 
      Console.WriteLine("Application is running! Waiting few seconds..."); 
      Thread.Sleep(executionWaitTime); 

      try 
      { 
       IRemoteIsolatedStorageFile remoteIsolatedStorageFile = remoteApplication.GetIsolatedStore(); 
       string sourceDeviceFilePath = (object)Path.DirectorySeparatorChar + "TestResults.trx"; 
       string targetDesktopFilePath = @"C:\Share\LatestAPI\TestCode\Automated\AutomatedUnitTests\Bin\Debug\" + "TestResults.trx"; 
       remoteIsolatedStorageFile.ReceiveFile(sourceDeviceFilePath, targetDesktopFilePath,true); 
      } 
      catch (Exception exception) 
      { 
       Console.WriteLine("Exception \'" + exception.Message + "\' reading file from device."); 
      } 

      // Terminate application 
      Console.WriteLine("Terminating the application..."); 
      remoteApplication.TerminateRunningInstances(); 

      Thread.Sleep(startStopWaitTime); 
      Console.WriteLine("\nDone!"); 

      // Disconnect from the emulator 
      Console.WriteLine("Disconnecting Device..."); 
      iDevice.Disconnect(); 
      Console.WriteLine("\nDone!"); 
     } 
    } 
} 
+0

非常感謝您的答覆和解決方案。我對windows phone開發非常陌生,這對我來說是一個巨大的幫助。謝謝! – user1720839

+0

我在哪裏可以找到dll。我發現Microsoft.Smartdevice.Connectivity.dll(我用它爲wp7),但我沒有Microsoft.SmartDevice.MultiTargeting.Connectivity。有任何想法嗎? –

+0

它可以在Windows 8機器上的Windows Phone 8上運行。但對於Windows 7它不工作。 –

0

我不得不實施接受的解決方案,因爲我錯過了引用這些命名空間的麻煩:

Microsoft.SmartDevice.Connectivity.Interface 
Microsoft.SmartDevice.MultiTargeting.Connectivity 

此處,我發現他們:

C:\Windows\Microsoft.NET\assembly\GAC_MSIL\ 
    Microsoft.SmartDevice.Connectivity.Interface\ 
    v4.0_11.0.0.0__b03f5f7f11d50a3a\ 
    Microsoft.Smartdevice.Connectivity.Interface.dll 

C:\Windows\Microsoft.NET\assembly\GAC_MSIL\ 
    Microsoft.SmartDevice.MultiTargeting.Connectivity\ 
    v4.0_11.0.0.0__b03f5f7f11d50a3a\ 
    Microsoft.Smartdevice.MultiTargeting.Connectivity.dll 

請注意,這些路徑,尤其是v4.0_11.0.0.0__b03f5f7f11d50a3a部件,在您的系統上可能會有所不同。在項目中添加對這些DLL的引用,並且一切都應該正常工作。

相關問題