When i retract my solution several files are not deleted including my custom master. Probably something simple but i want it deleted so that visual studio doesn't complain every time i deploy about deployment conflicts that it needs to resolve. Do i need to set something in the element.xml?

<File Path="Master_Pages\FamilyCare.master" Url="FamilyCare.master" IgnoreIfAlreadyExists="False"/>

3 Answers 3


When you deploy a file to a gallery using the File CAML element, SharePoint does not automatically remove the file when you deactivate the feature (or retract the solution). Presumably this is to prevent parts of the site that rely on the presence of that file from breaking if you were to accidentally deactivate the feature.

To get around it, you should attach a feature receiver to the feature that deploys your custom master page. In the "FeatureDeactivating" event, you can take care of removing the file manually. Something like this:

public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
   var site = properties.Feature.Parent as SPSite;
    var gallery = site.GetCatalog(SPListTemplateType.MasterPageCatalog);

    if (gallery != null) {
  • 1
    I prefer setting the old, original masterpage back as default masterpage, so before deleting, first set masterpage to i.e. v4.master. Aug 24, 2011 at 9:57
  • I agree with Ernst. You should re-set master page to original out-of-the-box master page so, hopefully, your custom master page is free to be deleted.
    – Aaronster
    Feb 5, 2015 at 14:35

If you set the Type to GhostableInLibrary, then the file will be Ghosted in the library. Thus, when you come to redeploy the solution, the file in the library will reference the physical file in the SharePoint Root directory, and will always be up to date.

  • This does not cure deployment conflicts.
    – user6993
    Feb 19, 2012 at 0:59

Have you tried setting "IgnoreIfAlreadyExists" to TRUE? If I remember correctly, that will cause your solution to overwrite the existing file. I seem to remember thinking that it seemed backwards - what it's actually saying is 'ignore if the file already exists and overwrite it anyway'

From MSDN:

IgnoreIfAlreadyExists - Optional Boolean. TRUE to provision the view even if the file aready exists at the specified URL; otherwise, FALSE.

  • If it's set to false, it'll error. If it's True, it'll ignore and carry on. Does what it says on the tin.
    – James Love
    Aug 23, 2011 at 16:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.