Can I exclude a folder or files when I publish a web site in Visual Studio 2005? I have various resources that I want to keep at hand in the Solution Explorer, such as alte
Amazingly the answer for Visual Studio 2012 is not here:
The answer with green checkmark is not the answer.
The highest "upped" answer references an article from 2010 and says you have to edit your csproj project file which is now incorrect. I added the ExcludeFoldersFromDeployment XML element to my Visual Studio 2012 csproj file and it did nothing, the element was considered invalid, this is because ExcludeFoldersFromDeployment has been moved to the .pubxml file it looks like.
For Web Applications and Websites you edit the .pubxml file!
You can follow my answer or try this guide which I found later: http://www.leniel.net/2014/05/using-msdeploy-publish-profile-pubxml-to-create-an-empty-folder-structure-on-iis-and-skip-deleting-it-with-msdeployskiprules.html#sthash.MSsQD8U1.dpbs
Yes, you can do this not just for Website Projects but Websites too. I spent a long time on the internet looking for this elusive exclude ability with a Visual Studio Website (NOT Website project) and had previously concluded it was not possible but it looks like it is:
In your [mypublishwebsitename].pubxml file, found in ~/Properties/PublishProfiles for Web Application Projects and ~/App_Data/PublishProfiles for Websites, simply add:
File1.aspx;Folder2\File2.aspx
Folder1;Folder2\Folder2a
as children to the main
element in your .pubxml file. No need to add a new element not unless you are keying a specific build type, like release or debug.
BUT WAIT!!!
If you are removing files from your destination/target server with the following setting in your Publish configuration:
Then the Web Publish process will delete on your source/target server anything excluded, like an item you have delineated in your
and
!
MsDeploy Skip Rules to the rescue:
First, Web Publish uses something other than MSBuild to publish (called Task IO or something like that) but it has a bug and will not recognize skip rules, so you must add to your .pubxml:
MSDeploy
I would keep
in its own
, you would think you could just have one
element in your .pubxml but my Skip Rules were not being called until I moved
to its own
element. Yes, crazy, but the fact you need to do all this for Web Publish to exclude and also not delete a folder/file on your server is crazy.
Now my actual SkipRules, ExcludeFolders and ExcludeFiles declarations in my .pubxml:
Config
Photos
Temp
Web.config
AddCustomSkipRules
And now a the Skip Rules (
is a child of
in your .pubxml):
(You may be able to leave
empty to Skip for all actions but I didn't test that and am not sure.
Delete
dirPath
$(_DestinationContentPath)\\Config
Delete
dirPath
$(_DestinationContentPath)\\Photos
Delete
filePath
$(_DestinationContentPath)\\Web\.config
Delete
dirPath
$(_DestinationContentPath)\\Temp
And please, do not to forget to escape the .
in a filePath Skip rule with a backslash.