{"id":75,"date":"2010-01-20T15:07:00","date_gmt":"2010-01-20T20:07:00","guid":{"rendered":"http:\/\/www.dontpapanic.com\/blog\/?p=75"},"modified":"2010-01-20T15:07:00","modified_gmt":"2010-01-20T20:07:00","slug":"editing-a-sharepoint-master-page-in-visual-studio-2010","status":"publish","type":"post","link":"https:\/\/www.dontpapanic.com\/blog\/?p=75","title":{"rendered":"Editing a SharePoint Master Page in Visual Studio 2010"},"content":{"rendered":"<p>I\u2019ll be the first to agree that the best tool for editing a SharePoint master page is SharePoint Designer (SPD).&#160; SPD is able to display both a code and \u201cWYSIWYG\u201d view of the master even if objects on the page are referenced using virtual directories, relative addresses, or addresses that contain dynamic placeholders.&#160; Because Visual Studio can\u2019t open a SharePoint site in place it is unable to provide the same level of editing support. But the problem is that a master page edited in SPD is \u201ccustomized\u201d and can only be used for that one site (or a single site collection if publishing features have been enabled.) So it has become a best practice to create a custom master in a separate SPD development environment, export it to the file system, and then deploy it in production as an \u201cuncustomized\u201d master page using a feature in a solution. (I documented how to deploy an SPD 2007 master page as a feature in a previous blog <a href=\"http:\/\/www.dontpapanic.com\/blog\/?p=36\" target=\"_blank\">here<\/a>.) <\/p>\n<p>Editing master pages in SPD 2010 continues to be the best practice, but it can be cumbersome for small changes to Enterprise master pages already deployed via a Feature. Sometimes its just not practical to upload the master to a Development site master page gallery, edit it in SPD 2010, and then download the edited copy to be packaged in Visual Studio 2010 and re-deployed to an Enterprise. In those cases it would be nice to make a quick edit in VS 2010. But VS 2010 is unable to interpret the master page in the context of a live site and defaults to the standard code view editor when opening a master page.&#160; This leads to two specific limitations that make even simple edits more difficult.&#160; As you can see from the screen shots below there is no support for expansion\/contraction of code sections and Intellisense support is greyed out. <\/p>\n<p><a href=\"http:\/\/www.dontpapanic.com\/blog\/images\/EditingaSharePointMasterPageinVisualStud_D6F1\/NoExpansion.png\"><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"NoExpansion\" border=\"0\" alt=\"NoExpansion\" src=\"http:\/\/www.dontpapanic.com\/blog\/images\/EditingaSharePointMasterPageinVisualStud_D6F1\/NoExpansion_thumb.png\" width=\"622\" height=\"484\" \/><\/a> <\/p>\n<p><a href=\"http:\/\/www.dontpapanic.com\/blog\/images\/EditingaSharePointMasterPageinVisualStud_D6F1\/NoIntellisense.png\"><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"NoIntellisense\" border=\"0\" alt=\"NoIntellisense\" src=\"http:\/\/www.dontpapanic.com\/blog\/images\/EditingaSharePointMasterPageinVisualStud_D6F1\/NoIntellisense_thumb.png\" width=\"623\" height=\"484\" \/><\/a> <\/p>\n<p>This makes it even more difficult to edit master pages in a code only view. To avoid these limitations you will need to tell VS 2010 which editor to use when opening the master page.&#160; To do this Right-Click on the Master page to be edited in the <strong>Solution Explorer<\/strong> and select <strong>Open With\u2026<\/strong> from the context menu.&#160; A dialog will open showing all the different Editors that are available.&#160; Highlight the <strong>Master Page Editor (Default)<\/strong> entry and click <strong>OK<\/strong> to open the Master page using the Master Page Editor in place of the Source Code (Text) Editor.&#160; (Note: Although the Master Page Editor is set as the default just clicking on the master page in Solution Explorer will actually use the Source Code (Text) Editor.&#160; The screenshot below shows the master page after it has been manually loaded into the Master Page Editor using the Open With\u2026 menu.&#160; Notice the presence of both Expansion\/Contraction Outlining and Intellisense. <\/p>\n<p><a href=\"http:\/\/www.dontpapanic.com\/blog\/images\/EditingaSharePointMasterPageinVisualStud_D6F1\/MasterPageEditor.png\"><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"MasterPageEditor\" border=\"0\" alt=\"MasterPageEditor\" src=\"http:\/\/www.dontpapanic.com\/blog\/images\/EditingaSharePointMasterPageinVisualStud_D6F1\/MasterPageEditor_thumb.png\" width=\"623\" height=\"618\" \/><\/a> <\/p>\n<p>A similar problem exists when opening .aspx pages that are not stored in the _Layouts virtual directory.&#160; You can enable full code editing of these pages by using OpenWith\u2026 and choosing <strong>Web Form Editor (default)<\/strong>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I\u2019ll be the first to agree that the best tool for editing a SharePoint master page is SharePoint Designer (SPD).&#160; SPD is able to display both a code and \u201cWYSIWYG\u201d view of the master even if objects on the page are referenced using virtual directories, relative addresses, or addresses that contain dynamic placeholders.&#160; Because Visual &hellip; <a href=\"https:\/\/www.dontpapanic.com\/blog\/?p=75\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Editing a SharePoint Master Page in Visual Studio 2010<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[20,19,6],"class_list":["post-75","post","type-post","status-publish","format-standard","hentry","category-sharepoint-2010-dev","tag-branding","tag-development","tag-sharepoint_2010"],"_links":{"self":[{"href":"https:\/\/www.dontpapanic.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/75","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dontpapanic.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dontpapanic.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dontpapanic.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dontpapanic.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=75"}],"version-history":[{"count":0,"href":"https:\/\/www.dontpapanic.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/75\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dontpapanic.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=75"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dontpapanic.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=75"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dontpapanic.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=75"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}