Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Introduction to Visual Studio<br /> The tool for Windows phone developers<br />
Projects and Solutions<br />
Topics<br />Creating and running programs<br />A simple Visual Studio project<br />Assembly files and executable files<br ...
Program creation<br />Programs are written by programmers using a high level language (for example C#) <br />They are then...
.NET Software Development Kit<br />The .NET SDK is a free download:<br />http://msdn.microsoft.com/en-us/netframework/aa56...
Using the command prompt<br />The compiler provided with Visual Studio can also be used from the command prompt<br />6<br />
Programs and Visual Studio<br />You could write every program you ever want to write using the notepad editor and command ...
Visual Studio<br />Visual Studio is a complicated beast to use<br />But you don’t have to press all the buttons at the sta...
Projects and Solutions<br />The first thing we are going to look at is how Visual Studio organises things for us<br />We a...
Demo 1: Creating a Simple Project<br />Demo<br />10<br />
The Empty Program<br />using System;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceSimpleProje...
Using multiple source files<br />If we want to write a simple console application we now know how to do it<br />We could a...
Demo 2: Adding a new class<br />Demo<br />13<br />
Projects and source files<br />namespaceSimpleProject<br />{<br />classProgram<br />    {<br />staticvoid Main(string[] ar...
Projects and Namespaces<br />The Main method can use the Library class directly because they are both in the same namespac...
Demo 3: Creating namespaces<br />Demo<br />16<br />
Adding resources to a project<br />We can add resources to a project<br />These are managed by Visual Studio<br />We can c...
Copying Resources<br />The “Build Action” element of the resource properties tells Visual Studio what to do with the conte...
Using copied resources<br />Bitmap b = newBitmap("Bitmap1.bmp");<br />Since the resource is just a file held in the same d...
Embedding Resources<br />If you want to guarantee that a resource can be found you can embed it in the program file<br />I...
Using embedded resources<br />Assemblyassembly;<br />StreamimageStream;<br />assembly = Assembly.GetExecutingAssembly();<b...
Demo 4: Using Resources<br />Demo<br />22<br />
Programs and Assemblies<br />We have seen that a “program” file can contain resources such as bitmaps<br />This is because...
ildasm<br />The Intermediate Language Disassembler is a program supplied with the .NET Framework<br />It allows us to look...
Starting ildasm<br />The ildasm program is a Windows application<br />It runs from the Visual Studio Command line <br />Yo...
Ildasm in action<br />Ildasm lets you navigate the classes in an assembly<br />The display on the right is our resource di...
The Assembly Manifest<br />The assembly contains a manifest section that describes what is inside  the assembly<br />You c...
Demo 5: Using ildasm<br />Demo<br />28<br />
Creating libraries<br />At the moment we just have a single program<br />However, we can also create library assemblies th...
Creating a library<br />A library project is created from the library template in Visual Studio<br />30<br />
Dynamically Loaded Libraries<br />The elements in a library are only loaded when they are used<br />When a method in a cla...
System Libraries and References<br />System.Console.WriteLine("Hello World");<br />A program will make use of system resou...
System Assembly References<br />The references initially assigned to an assembly are determined by the project template<br...
Building an application<br />When we build an application Visual Studio creates the assemblies <br />Above you can see the...
Visual Studio Solutions<br />A Visual Studio solution can contain a number of projects<br />You create additional projects...
Creating a new project in a solution<br />You can add projects by using right click on the solution in Solution Explorer<b...
Projects in Solution Explorer<br />This shows a version of SimpleProject that also contains a DisplayLibrary which perform...
Linking Projects<br />Although the projects are in the same solution they are not linked<br />If you want to use the outpu...
Multi-project build output<br />When we build a multi-project solution all the required assemblies are copied into the out...
Manifest external references<br />You can use ildasm to find the external assemblies that an assembly uses<br />This is th...
Demo 6: A Multi-Project Solution<br />Demo<br />41<br />
Windows Phone Solutions<br />A Silverlight Windows Phone solution only contains a single project<br />This contains all th...
Windows Phone Solutions<br />An XNA Windows Phone solution contains two projects<br />One of these holds all the assets us...
Windows Phone deployment<br />Before a Windows Phone program can run it must be transferred into the target<br />This can ...
Output Files for an application<br />These are the files that make up the AddingMachine application<br />These include the...
The XAP File<br />The XAP file is a container that holds everything needed to run the application<br />It is a Zip archive...
Running the XAP file<br />When you press the “run” button in Visual Studio the XAP file is copied to the target device<br ...
Review<br />Visual Studio brings together code and assets into a project file that describes an assembly<br />An assembly ...
Debuggingprograms<br />
Topics<br />The Windows Phone emulator<br />Deploying to the emulator<br />Debugging with Visual Studio<br />Adding breakp...
The Windows Phone Emulator<br />The Windows Phone emulator runs as a program on your Windows PC<br />It contains the same ...
Deploying to the Emulator<br />Visual Studio lets you select the target device for your program when it runs<br />The emul...
Emulator Features<br />The emulator does not contain the complete Windows Phone experience<br />It does have the browser a...
Emulator Performance<br />The emulator is not a reliable way of predicting how a program will perform on a real device<br ...
Visual Studio debugging<br />Visual Studio provides an exceptional debugging experience<br />This experience extends to Wi...
Breakpoint<br />You set a breakpoint at a statement where you want the program to pause<br />When the program reaches the ...
Setting a Breakpoint<br />To set a breakpoint just double click in the left margin of the statement<br />The statement is ...
Hitting a Breakpoint<br />The next time the statement is obeyed the program will break<br />The statement at the breakpoin...
Viewing Variable Contents<br />You can view the contents of a variable in the program by resting the cursor on the variabl...
Single Stepping a program<br />You can step through code a line at a time<br />The current position is highlighted in yell...
Program Control<br />Start or resume the program running<br />Execute a single statement and step into a method call<br />...
Managing Breakpoints<br />Visual Studio provides a Breakpoint window you can use to manage all the breakpoints you set in ...
The Immediate Window<br />The Immediate Window lets you view and change the values of variables<br />You can even call met...
Demo 1: Debugging <br />AddingMachine<br />Demo<br />64<br />
Design for Debug<br />privatevoidcalculateResult(){resultTextBlock.Text =        (float.Parse(firstNumberTextBox.Text) + f...
Review<br />The Windows Phone emulator shows the behaviour of the phone but not performance<br />You can set breakpoints i...
Exercise1: Buildingthe time trackeruser interface<br />
Exercise 2: debugging a brokenprogram<br />
Upcoming SlideShare
Loading in …5
×

WP7 HUB_Introducción a Visual Studio

856 views

Published on

Fase 3.2

Published in: Education
  • Be the first to comment

  • Be the first to like this

WP7 HUB_Introducción a Visual Studio

  1. 1. Introduction to Visual Studio<br /> The tool for Windows phone developers<br />
  2. 2. Projects and Solutions<br />
  3. 3. Topics<br />Creating and running programs<br />A simple Visual Studio project<br />Assembly files and executable files<br />Visual Studio solutions<br />Linking assemblies<br />The XAP file<br />
  4. 4. Program creation<br />Programs are written by programmers using a high level language (for example C#) <br />They are then compiled into a lower level language which then runs<br />Microsoft .NET uses an intermediate language (MSIL) to allow programs to be more portable<br />To create a simple program you just need the compiler to create the compiled code<br />4<br />
  5. 5. .NET Software Development Kit<br />The .NET SDK is a free download:<br />http://msdn.microsoft.com/en-us/netframework/aa569263.aspx<br />It contains the .NET runtime and a command line compiler<br />The compiler takes the source file in and creates an output file that can be run<br />As long as it doesn’t find any errors in the program<br />5<br />
  6. 6. Using the command prompt<br />The compiler provided with Visual Studio can also be used from the command prompt<br />6<br />
  7. 7. Programs and Visual Studio<br />You could write every program you ever want to write using the notepad editor and command prompt compiler<br />But this would be hard work<br />Visual Studio is an “Integrated Development Environment” for creating programs<br />Edit program source<br />Build the solution<br />Debug the solution<br />7<br />
  8. 8. Visual Studio<br />Visual Studio is a complicated beast to use<br />But you don’t have to press all the buttons at the start<br />8<br />
  9. 9. Projects and Solutions<br />The first thing we are going to look at is how Visual Studio organises things for us<br />We are going to start with a look at the Visual Studio project<br />To do this we are going to create a very simple project which just contains one program file and runs at the command prompt<br />9<br />
  10. 10. Demo 1: Creating a Simple Project<br />Demo<br />10<br />
  11. 11. The Empty Program<br />using System;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceSimpleProject{classProgram {staticvoid Main(string[] args) { } }}<br />11<br />
  12. 12. Using multiple source files<br />If we want to write a simple console application we now know how to do it<br />We could add new methods to the Program class and new classes to the source file<br />However, we often want to spread a development over several source files<br />This allows us to reuse code and also work independently from each other<br />12<br />
  13. 13. Demo 2: Adding a new class<br />Demo<br />13<br />
  14. 14. Projects and source files<br />namespaceSimpleProject<br />{<br />classProgram<br /> {<br />staticvoid Main(string[] args)<br /> {<br />Library l = newLibrary();<br /> }<br /> }<br />}<br />We can now use the Library class in our main program<br />14<br />
  15. 15. Projects and Namespaces<br />The Main method can use the Library class directly because they are both in the same namespace<br />A namespace is a way you can logically group code together<br />Stops programmers getting name clashes<br />If the namespace of the library class is different from the program the compiler will raise an error<br />15<br />
  16. 16. Demo 3: Creating namespaces<br />Demo<br />16<br />
  17. 17. Adding resources to a project<br />We can add resources to a project<br />These are managed by Visual Studio<br />We can control what Visual Studio does with the resource when the program is built<br />copy the resource to the output directory<br />embed the resource in the program file<br />17<br />
  18. 18. Copying Resources<br />The “Build Action” element of the resource properties tells Visual Studio what to do with the content when the program is built<br />We have told Visual Studio that the bitmap is content and should be copied into the output directory<br />18<br />
  19. 19. Using copied resources<br />Bitmap b = newBitmap("Bitmap1.bmp");<br />Since the resource is just a file held in the same directory as the program we can load it directly<br />This statement loads the bitmap resource into a bitmap called b<br />The program can then display it<br />19<br />
  20. 20. Embedding Resources<br />If you want to guarantee that a resource can be found you can embed it in the program file<br />It then becomes part of the executable program<br />To do this you change the resource properties<br />20<br />
  21. 21. Using embedded resources<br />Assemblyassembly;<br />StreamimageStream;<br />assembly = Assembly.GetExecutingAssembly();<br />imageStream = <br />assembly.GetManifestResourceStream("Bitmap2.bmp");<br />Bitmap b = newBitmap(imageStream);<br />To load the bitmap we now have to get a stream from the assembly resources<br /> We can then construct the bitmap from it<br />21<br />
  22. 22. Demo 4: Using Resources<br />Demo<br />22<br />
  23. 23. Programs and Assemblies<br />We have seen that a “program” file can contain resources such as bitmaps<br />This is because in .NET a program file is actually a .NET assembly file<br />An assembly file is a container which can hold a collection of items <br />We can look inside an assembly using the ildasm tool<br />23<br />
  24. 24. ildasm<br />The Intermediate Language Disassembler is a program supplied with the .NET Framework<br />It allows us to look inside assemblies and see what is there<br />It can also show you the Microsoft Intermediate Language (MSIL) statements the compiler produced for your program<br />24<br />
  25. 25. Starting ildasm<br />The ildasm program is a Windows application<br />It runs from the Visual Studio Command line <br />You open the command line from the programs menu:<br />All Programs>Microsoft Visual Studio 10>Visual Studio Tools<br />25<br />
  26. 26. Ildasm in action<br />Ildasm lets you navigate the classes in an assembly<br />The display on the right is our resource display app<br />You can see all the methods in each class<br />The “ctor” method is the constructor for the class<br />26<br />
  27. 27. The Assembly Manifest<br />The assembly contains a manifest section that describes what is inside the assembly<br />You can see the Bitmap2.bmp resource<br />27<br />
  28. 28. Demo 5: Using ildasm<br />Demo<br />28<br />
  29. 29. Creating libraries<br />At the moment we just have a single program<br />However, we can also create library assemblies that can provided behaviours for other assemblies<br />A library assembly is stored in a file with the language extension .dll<br />It does not contain a Main method<br />29<br />
  30. 30. Creating a library<br />A library project is created from the library template in Visual Studio<br />30<br />
  31. 31. Dynamically Loaded Libraries<br />The elements in a library are only loaded when they are used<br />When a method in a class is called the class will be loaded into memory and the Just In Time compiler converts it into machine code for execution<br />This reduces the amount of memory needed by the program and avoids wasting time compiling un-needed code<br />31<br />
  32. 32. System Libraries and References<br />System.Console.WriteLine("Hello World");<br />A program will make use of system resources as it runs<br />System resources are deployed as dynamically loaded assemblies<br />The system assemblies are held centrally by the operating system in the “Global Assembly Cache” <br />32<br />
  33. 33. System Assembly References<br />The references initially assigned to an assembly are determined by the project template<br />These are the references that are assigned to a simple project<br />You can add others<br />33<br />
  34. 34. Building an application<br />When we build an application Visual Studio creates the assemblies <br />Above you can see these in the output folder<br />This folder also contains debug information which is used by Visual Studio<br />The release version does not include this<br />34<br />
  35. 35. Visual Studio Solutions<br />A Visual Studio solution can contain a number of projects<br />You create additional projects just by adding them to the solution<br />The projects do not need to be the same type<br />You can have multiple executable assemblies in a single solution<br />35<br />
  36. 36. Creating a new project in a solution<br />You can add projects by using right click on the solution in Solution Explorer<br />36<br />
  37. 37. Projects in Solution Explorer<br />This shows a version of SimpleProject that also contains a DisplayLibrary which performs the display<br />The two projects are separate and each produce assemblies<br />One is a library and the other an executable<br />37<br />
  38. 38. Linking Projects<br />Although the projects are in the same solution they are not linked<br />If you want to use the output of one project in another you must add a reference to the project output<br />38<br />
  39. 39. Multi-project build output<br />When we build a multi-project solution all the required assemblies are copied into the output folder<br />The SimpleProject assembly will contain a reference to the DisplayLibrary assembly<br />39<br />
  40. 40. Manifest external references<br />You can use ildasm to find the external assemblies that an assembly uses<br />This is the manifest for SimpleProject<br />40<br />
  41. 41. Demo 6: A Multi-Project Solution<br />Demo<br />41<br />
  42. 42. Windows Phone Solutions<br />A Silverlight Windows Phone solution only contains a single project<br />This contains all the images used for the icons on the phone<br />It also uses all the Windows Phone references<br />42<br />
  43. 43. Windows Phone Solutions<br />An XNA Windows Phone solution contains two projects<br />One of these holds all the assets used by the game itself<br />We can add other projects for Xbox and Windows PC versions<br />43<br />
  44. 44. Windows Phone deployment<br />Before a Windows Phone program can run it must be transferred into the target<br />This can be either a Windows Phone device or the emulator<br />All the content the application requires must be transferred as well<br />Along with any additional assemblies that make up the entire application code<br />44<br />
  45. 45. Output Files for an application<br />These are the files that make up the AddingMachine application<br />These include the images for use for the background, loading screen and icon <br />45<br />
  46. 46. The XAP File<br />The XAP file is a container that holds everything needed to run the application<br />It is a Zip archive with a manifest that describes its contents<br />46<br />
  47. 47. Running the XAP file<br />When you press the “run” button in Visual Studio the XAP file is copied to the target device<br />The device opens the archive, reads the manifest file and starts the application running<br />The XAP file is also the file that is sent to a customer who buys the program in Windows Marketplace<br />47<br />
  48. 48. Review<br />Visual Studio brings together code and assets into a project file that describes an assembly<br />An assembly can be either an executable program or a dynamically loaded library<br />Projects are brought together into solutions<br />If a project wants to use an external library it must explicitly link to this<br />The XAP file contains all the resources and code for deployment to the target device<br />48<br />
  49. 49. Debuggingprograms<br />
  50. 50. Topics<br />The Windows Phone emulator<br />Deploying to the emulator<br />Debugging with Visual Studio<br />Adding breakpoints<br />Single stepping code<br />Viewing and modifying variables<br />Using the Immediate Window in Visual Studio<br />Designing code for debugging<br />
  51. 51. The Windows Phone Emulator<br />The Windows Phone emulator runs as a program on your Windows PC<br />It contains the same software as a “real” phone, but built for the Windows PC platform<br />The emulator is supplied with the Windows Phone SDK <br />51<br />
  52. 52. Deploying to the Emulator<br />Visual Studio lets you select the target device for your program when it runs<br />The emulator is started the first time you deploy to it<br />It will then remain running until you stop it<br />52<br />
  53. 53. Emulator Features<br />The emulator does not contain the complete Windows Phone experience<br />It does have the browser and will provide the phone behaviours for things like placing calls and sending SMS messages<br />There are also some entries in the Address Book<br />It also contains an emulator of the Windows Phone camera<br />53<br />
  54. 54. Emulator Performance<br />The emulator is not a reliable way of predicting how a program will perform on a real device<br />The processor in a Windows PC may be more powerful than the one in the phone<br />The emulator is for functional testing only<br />If you have any concerns about performance you should ensure you run your program on a real device<br />54<br />
  55. 55. Visual Studio debugging<br />Visual Studio provides an exceptional debugging experience<br />This experience extends to Windows Phone<br />You can do all the debugging actions in Windows Phone that you can do with a Windows PC application<br />Breakpoints <br />Single Stepping<br />Viewing and modifying variables<br />55<br />
  56. 56. Breakpoint<br />You set a breakpoint at a statement where you want the program to pause<br />When the program reaches the breakpoint you get control and can take a look at what the program is doing<br />You can set breakpoints even when the program is running<br />56<br />
  57. 57. Setting a Breakpoint<br />To set a breakpoint just double click in the left margin of the statement<br />The statement is highlighted to indicate that a breakpoint has been set<br />57<br />
  58. 58. Hitting a Breakpoint<br />The next time the statement is obeyed the program will break<br />The statement at the breakpoint is highlighted<br />58<br />
  59. 59. Viewing Variable Contents<br />You can view the contents of a variable in the program by resting the cursor on the variable name in the code<br />You can also select variables to watch<br />59<br />
  60. 60. Single Stepping a program<br />You can step through code a line at a time<br />The current position is highlighted in yellow<br />The statement at the current position has not been executed yet<br />60<br />
  61. 61. Program Control<br />Start or resume the program running<br />Execute a single statement and step into a method call<br />Execute a single statement and step over method calls<br />Exit a method which was stepped into <br />Pause the program<br />Stop the program<br />61<br />
  62. 62. Managing Breakpoints<br />Visual Studio provides a Breakpoint window you can use to manage all the breakpoints you set in a program<br />You can also manipulate the properties of each breakpoint<br />62<br />
  63. 63. The Immediate Window<br />The Immediate Window lets you view and change the values of variables<br />You can even call methods inside your program<br />63<br />
  64. 64. Demo 1: Debugging <br />AddingMachine<br />Demo<br />64<br />
  65. 65. Design for Debug<br />privatevoidcalculateResult(){resultTextBlock.Text = (float.Parse(firstNumberTextBox.Text) + float.Parse(secondNumberTextBox.Text)).ToString();}<br />We could create our entire program behaviour in a single statement<br />However, this makes it much harder to take a look at the intermediate values and find out why our program is failing<br />65<br />
  66. 66. Review<br />The Windows Phone emulator shows the behaviour of the phone but not performance<br />You can set breakpoints in your Windows Phone programs to stop code at particular statements<br />You can view the contents of variables in the program<br />You can also view and modify program variables using the Immediate Window<br />66<br />
  67. 67. Exercise1: Buildingthe time trackeruser interface<br />
  68. 68. Exercise 2: debugging a brokenprogram<br />

×