开发者

Open a windows phone 7 application In Emulator using Command Line

Is there a way to open a Windows Phone 7 Application in emulator using command line?

I know that there already exists a question related to this here, but I want a simple way to start a wp7 application (having the xap file) from command line without modify the code of the application.

I know that this is possible for XNA applications (info here) but I do not know if this is possible for apps made under Silverlight framework?!

Later edit - problem RESOLVED

Looking deeply, the Justin blog seemed to be very ok for this problem I've had. Anyway I had to make some small changes: changed the line:

Platform WP7SDK = dsmgrObj.GetPlatforms().Single(p => p.Name == "New Windows Mobile 7 SDK");

into line:

Platform WP7SDK = dsmgrObj.GetPlatforms().Single(p => p.Name == "Windows Phone 7");

I used a foreach for retrieving the platform names:

 // iterate over all platforms and write their names
 foreach (Platform p in dsmgrObj.GetPlatfor开发者_StackOverflowms().ToList<Platform>())
 {
    Console.WriteLine("Platform: " + p.Name);
 }

and the line:

WP7Device = WP7SDK.GetDevices().Single(d => d.Name == "Windows Phone 7 Emulator");

into line:

WP7Device = WP7SDK.GetDevices().Single(d => d.Name == "Windows Phone Emulator");

Used again a foreach :

 // iterate over all devces and write their names
                foreach (Device d in WP7SDK.GetDevices().ToList<Device>())
                {
                    Console.WriteLine("Device: " + d.Name);
                }


As mentioned you should follow Justin Angel's blog post. The end result is a very simple command line application which you run to, amongst other things, install your XAP file to the emulator/phone and start this application.

There is one thing I would modify though. Justin's app uninstalls the previous version of your application before installing the new one. This removes all files in isolated storage, including the IsolatedStorageSettings resource. I made the following changes to update the the phone application if it already exists.

// ... code to get command line parameters, device instance etc ...

if (WP7Device.IsApplicationInstalled(appID)) {
    Console.WriteLine("Found {0} XAP on Windows Phone 7 Emulator/Device...", appName);
    app = WP7Device.GetApplication(appID);
    app.TerminateRunningInstances();
    app.UpdateApplication("NormalApp", 
                           appLocation + @"\ApplicationIcon.png", 
                           appLocation + @"\Bin\" + configuration + @"\" + appName + @".xap");

     Console.WriteLine("{0} XAP Updated from Windows Phone 7 Emulator/Device...", appName);
} else {
    // Install XAP
    Console.WriteLine("Installing {0} XAP to Windows Phone 7 Emulator/Device...", appName);
    app = WP7Device.InstallApplication(appID,
                                       appID,
                                       "NormalApp",
                                       appLocation + @"\ApplicationIcon.png",
                                       appLocation + @"\Bin\" + configuration + @"\" + appName + @".xap");
     Console.WriteLine("{0} XAP installed to Windows Phone 7 Emulator...", appName);
}
// Launch Application 
Console.WriteLine("Launching {0} on Windows Phone 7 Emulator...", appName);
app.Launch();
Console.WriteLine("Launched {0} on Windows Phone 7 Emulator...", appName);

Cheers, Alasdair

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜