{"id":473,"date":"2014-04-14T10:30:00","date_gmt":"2014-04-14T10:30:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/visualstudio\/2014\/04\/14\/using-visual-studio-to-build-universal-xaml-apps\/"},"modified":"2022-10-03T10:48:27","modified_gmt":"2022-10-03T17:48:27","slug":"using-visual-studio-to-build-universal-xaml-apps","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/visualstudio\/using-visual-studio-to-build-universal-xaml-apps\/","title":{"rendered":"Using Visual Studio to build Universal XAML Apps"},"content":{"rendered":"<p>At the Build conference, we announced the release of the new converged Windows Phone 8.1 and Windows 8.1 platforms. As a developer, this means you can now build XAML and HTML universal apps that run on both Phone and Tablets by sharing a significant amount of code and content. To enable building universal apps, we added a number of new features to Visual Studio as part of the <a href=\"http:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=42307\">Visual Studio Update 2 RC<\/a>.<\/p>\n<p>You have two ways to learn more about these features. One way is through this blog post. The other way is by watching my <a href=\"https:\/\/channel9.msdn.com\/Events\/Build\/2014\/3-591\">Build talk<\/a> that covers all of the material you will see here in more detail:<\/p>\n<p>There is no right or wrong way here, so pick either the video or the blog depending on how much time you have. Without further delay, let\u2019s take a quick look at universal apps!<\/p>\n<h2>Creating Universal Apps<\/h2>\n<p>To help you get started with building universal apps in C#, C++, and JS, we created new project templates that contain the basic structure and behind-the-scenes configurations to allow you to share code and content:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2014\/04\/2744.NewProjectTemplates_thumb_69CCFC60.png\"><img decoding=\"async\" style=\"float: none; margin-left: auto; margin-right: auto; border-width: 0px;\" title=\"New Project Templates\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2014\/04\/2744.NewProjectTemplates_thumb_69CCFC60.png\" alt=\"New Project Templates\" width=\"640\" height=\"442\" border=\"0\" \/><\/a><\/p>\n<p>If you already have an existing Windows 8.1 application, you can use the \u201cAdd Windows Phone 8.1\u201d command to add a new Windows Phone 8.1 project and a shared project to the solution. A similar option is also available if you have a Windows Phone 8.1 application, and wanted to add support for Windows 8.1.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/4\/2018\/10\/5481.AddWindowsPhone8.1commandinSolutionExplorer_62ADBFE8.png\"><img decoding=\"async\" style=\"float: none; margin-left: auto; margin-right: auto; border-width: 0px;\" title=\"'Add Windows Phone 8.1' command in Solution Explorer\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2014\/04\/1373.AddWindowsPhone8.1commandinSolutionExplorer_thumb_5B8E8370.png\" alt=\"'Add Windows Phone 8.1' command in Solution Explorer\" width=\"558\" height=\"480\" border=\"0\" \/><\/a><\/p>\n<h2>Structure of Universal Apps<\/h2>\n<p>A universal app is a collection of three projects \u2013 a Windows Store project, a Windows Phone project and a Shared project \u2013 enclosed in a solution folder that is optional. The Windows Store and Windows Phone projects are platform projects and are responsible for creating the application packages (.appx) targeting the respective platforms. These projects contain assets that are specific to the platform being targeted.<\/p>\n<p>The Shared project contains assets that are shared between the Windows Store and Windows Phone projects. The set of item types (.cs, xaml, .xml, .png, .resw, etc.) supported by the shared projects is the same as the platform projects. Shared projects by themselves don\u2019t have a binary output but their contents are imported by the platform projects and used as part of the build process to generate the Windows Store and Windows Phone application packages (.appx).<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2014\/04\/7506.SeparateprojectsforWindows8.1andWindowsPhone8.1_thumb_72505BAA.png\"><img decoding=\"async\" style=\"float: none; margin-left: auto; margin-right: auto; border-width: 0px;\" title=\"Separate projects for Windows 8.1 and Windows Phone 8.1\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2014\/04\/7506.SeparateprojectsforWindows8.1andWindowsPhone8.1_thumb_72505BAA.png\" alt=\"Separate projects for Windows 8.1 and Windows Phone 8.1\" width=\"421\" height=\"480\" border=\"0\" \/><\/a><\/p>\n<h2>Writing code in the Shared project<\/h2>\n<p>While developing your universal app, you will mostly be writing code that runs on both platforms. If required, you can also write platform specific code in the Shared projects using #if and #endif directives. By default, we have predefined the following conditional compilation constants that you could use to write platform specific code.<\/p>\n<table style=\"width: 400px;\" border=\"1\" cellspacing=\"0\" cellpadding=\"5\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"39\">C#<\/td>\n<td valign=\"top\" width=\"166\">WINDOWS_APP<\/td>\n<td valign=\"top\" width=\"193\">WINDOWS_PHONE_APP<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"39\">C++<\/td>\n<td valign=\"top\" width=\"167\">WINAPI_FAMILY_PC_APP<\/td>\n<td valign=\"top\" width=\"194\">WINAPI_FAMILY_PHONE_APP<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<h2>Context switcher in the editor<\/h2>\n<p>While writing code in a Shared project, you can use the project context switcher in the navigation bar to select the platform you are actively targeting, which in turn drives the intellisense experience in the code editor.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/4\/2018\/10\/0564.UniversalAppsXAML-PrjStructure-Project%20Context%20Switcher.png\"><img decoding=\"async\" style=\"border-width: 0px; margin-right: auto; margin-left: auto; float: none;\" title=\"Project Context Switcher\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2014\/04\/7180.4ProjectContextSwitcher_thumb_6D6DA7EE.png\" alt=\"Project Context Switcher\" width=\"826\" height=\"161\" border=\"0\" \/><\/a><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2014\/04\/6740.5Intellisense_thumb_2D378E74.png\"><img decoding=\"async\" style=\"border-width: 0px; margin-right: auto; margin-left: auto; float: none;\" title=\"Intellisense\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2014\/04\/6740.5Intellisense_thumb_2D378E74.png\" alt=\"Intellisense\" width=\"828\" height=\"244\" border=\"0\" \/><\/a><\/p>\n<h2>Switching startup projects using debug target dropdown<\/h2>\n<p>We have also added the ability to quickly switch the startup projects in the debug target dropdown that now enumerates all the possible projects in the solution that you might want to deploy to a device or emulator\/simulator.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2014\/04\/6862.Switchstartupprojectinthedebugtargetdropdown_thumb_042F8029.png\"><img decoding=\"async\" style=\"float: none; margin-left: auto; margin-right: auto; border-width: 0px;\" title=\"Switch startup project in the debug target dropdown\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2014\/04\/6862.Switchstartupprojectinthedebugtargetdropdown_thumb_042F8029.png\" alt=\"Switch startup project in the debug target dropdown\" width=\"640\" height=\"265\" border=\"0\" \/><\/a><\/p>\n<h2>Sharing code across Universal Apps<\/h2>\n<p>You can use class libraries to share your code across different universal apps. For C# and Visual Basic, we have improved the existing Portable Class Libraries (PCLs) to also support Windows Runtime and XAML when targeting Windows 8.1 and Windows Phone 8.1 platforms. Check out this <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/the-next-generation-of-net\/\">blog for more details on PCL improvements<\/a>.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2014\/04\/8103.ImprovedPortableClassLibraries_thumb_0AE289AC.png\"><img decoding=\"async\" style=\"float: none; margin-left: auto; margin-right: auto; border-width: 0px;\" title=\"Improved Portable Class Libraries\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2014\/04\/8103.ImprovedPortableClassLibraries_thumb_0AE289AC.png\" alt=\"Improved Portable Class Libraries\" width=\"305\" height=\"480\" border=\"0\" \/><\/a><\/p>\n<p>For C++, you can use the new Class Library project templates under \u201cUniversal Apps\u201d with shared projects to share your code between Windows 8.1 and Windows Phone 8.1 class libraries.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/4\/2018\/10\/2555.ClassLibraryprojecttemplatesforC_03C34D34.png\"><img decoding=\"async\" style=\"float: none; margin-left: auto; margin-right: auto; border-width: 0px;\" title=\"Class Library project templates for C \" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2014\/04\/2577.ClassLibraryprojecttemplatesforC_thumb_1195932F.png\" alt=\"Class Library project templates for C \" width=\"310\" height=\"317\" border=\"0\" \/><\/a><\/p>\n<p>I hope you found this overview of building XAML universal apps useful. If you have any questions or comments, please feel free to post below or contact us via <a href=\"http:\/\/social.msdn.microsoft.com\/Forums\/wpapps\/en-us\/home?category=wpapps\">forums<\/a> or <a href=\"http:\/\/visualstudio.uservoice.com\/forums\/121579-visual-studio\/category\/44115-xaml-tools\">UserVoice<\/a> . Stay tuned for another blog explaining the new XAML tooling features we have added in Visual Studio to support Windows Phone 8.1 applications.<\/p>\n<table style=\"width: 670px;\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"199\"><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2014\/04\/2703.image_thumb_04344586.png\"><img decoding=\"async\" style=\"border-width: 0px;\" title=\"image\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2014\/04\/2703.image_thumb_04344586.png\" alt=\"image\" width=\"145\" height=\"137\" border=\"0\" \/><\/a><\/td>\n<td valign=\"top\" width=\"469\"><strong>Author<\/strong>: Navit Saxena, Program Manager<\/p>\n<p>Navit Saxena is a Program Manager on the Visual Studio team. For over five years, Navit has been focused on XAML tooling in Visual Studio and Blend. He enjoys building Windows &amp; Windows Phone apps and is always looking for ways to improve the XAML developer tools.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>At the Build conference, we announced the release of the new converged Windows Phone 8.1 and Windows 8.1 platforms. As a developer, this means you can now build XAML and HTML universal apps that run on both Phone and Tablets by sharing a significant amount of code and content. To enable building universal apps, we [&hellip;]<\/p>\n","protected":false},"author":13,"featured_media":255385,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[155],"tags":[5,137,129,653,126,133],"class_list":["post-473","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-visual-studio","tag-csharp","tag-html","tag-universal-apps","tag-visual-basic","tag-visual-studio-2013","tag-xaml"],"acf":[],"blog_post_summary":"<p>At the Build conference, we announced the release of the new converged Windows Phone 8.1 and Windows 8.1 platforms. As a developer, this means you can now build XAML and HTML universal apps that run on both Phone and Tablets by sharing a significant amount of code and content. To enable building universal apps, we [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/473","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/comments?post=473"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/473\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media\/255385"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media?parent=473"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/categories?post=473"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/tags?post=473"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}