1

I have a folder on my web application which is used to store user uploads, i.e. profile pictures, that sort of thing.

When I use WebDeploy, there is an option for "Leave extra files (Do not delete)" which when ticked makes sure that the profile pictures are not deleted.

What I am seeking is a way to ensure that even if that is unticked, a certain folder is safe from deletion. The reason for this being that I don't want another developer to accidentally disable the feature in future. Or me for that matter.

Any ideas? I have seen a few similar questions on here but nothing seems to be relevant to Visual Studio 2010, which is what I am using.

KingCronus
  • 4,509
  • 1
  • 24
  • 49
  • Have you tried excluding the folder? http://msdn.microsoft.com/en-us/library/ee942158.aspx#can_i_exclude_specific_files_or_folders_from_deployment I don't remember if this also makes sure that Web Deploy doesn't delete existing files in the folder. – tdykstra Nov 19 '12 at 13:23
  • What if you make that directory as virtual directory? Is it still deleted on wed deploy? – Mitul Dec 06 '12 at 14:45

2 Answers2

3

(I assume you're using publish profiles as per Visual Studio 2010 w/ the Azure SDK or Visual Studio 2012 RTM. If you're not, create an MSBuild file called ProjectName.wpp.targets in the project root and put content in that instead)

You can disable all forms of deletes by setting <SkipExtraFilesOnServer>true</SkipExtraFilesOnServer> in your publish profile (equivalent to the checkbox you mentioned).

To skip a particular directory, a comment on this question implies you can use the following syntax:

<ItemGroup>
  <ExcludeFoldersFromDeployment Include="FolderName" />
</ItemGroup>

But I've never seen that before and haven't tested it. Failing that, you can specify an explicit skip rule. "FolderName" is being skipped here - keep in mind that AbsolutePath is a regex:

<MsDeploySkipRules Include="SkipFolderName">
  <SkipAction>Delete</SkipAction>
  <ObjectName>dirPath</ObjectName>
  <AbsolutePath>FolderName$</AbsolutePath>
</MsDeploySkipRules>

NOTE: There are some scenarios in which skip rules don't work when using Visual Studio unless you also set UseMsDeployExe to true

Community
  • 1
  • 1
Richard Szalay
  • 83,269
  • 19
  • 178
  • 237
  • If I add `MsDeploySkipRules` to my publish file it complains about the `Include` attribute not being a valid attribute, if I remove it I can still publish but it doesn't honor the rule. – The Muffin Man Feb 12 '14 at 16:58
  • `MsDeploySkipRules` is an item, so it needs to be in an `ItemGroup`, rather than a `PropertyGroup`. – Richard Szalay Feb 12 '14 at 20:42
  • `Web deployment task failed. (Unrecognized skip directive 'skipaction'. Must be one of the following: "objectName," "keyAttribute," "absolutePath," "xPath," "attributes.."` – The Muffin Man Feb 12 '14 at 23:42
  • @TheMuffinMan - Are you running Visual Studio 2010 by any chance? You might need to install SP1 + the latest Azure SDK – Richard Szalay Feb 13 '14 at 02:21
  • I'm using the latest version of 2013 and I'm not currently using Azure. This is for deploying to my test server (Amazon EC2) – The Muffin Man Feb 13 '14 at 18:32
2

You can set specific rules on the target machines using the msdeploy.exe.configsettings file, there is also a msdeploy.exe.configsettings.example file in the same folder. The file is located in %program files%\IIS\Microsoft Web Deploy - folder see Web Deploy Rules

You can set Rules and skipDirectives here and enable whether they are defaulted so you get your expected default behaviour.