How to exclude web.config when publishing with Visual Studio 2013?
Simply select the web.config properties and change 'Build Action' to 'None' and 'Copy To Output Directory' to 'Do Not copy'
I know this is an old post, with old answers but to me, both described solutions are wrong.
Web.config flavors induces a security risk when manipulating environments credentials, and the "Build Action"="None" solution, breaks the possibility to debug the project locally,as the Web.Config file will never be present in the "bin" directory.
A cleaner solution is what is described here :
https://docs.microsoft.com/fr-fr/aspnet/web-forms/overview/deployment/advanced-enterprise-web-deployment/excluding-files-and-folders-from-deployment
which is basically to create a ProjectName.wpp.targets file, containing a list of files / folders to exclude when publishing your project.
To remove the Web.config from a project named Blog you would need to create a file named Blog.wpp.targets with something like this:
File: Blog.wpp.targets
<?xml version="1.0" encoding="utf-8" ?>
<Project ToolsVersion="4.0"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ExcludeFromPackageFiles Include=".\Web.config">
<FromTarget>Blog.wpp.targets</FromTarget>
</ExcludeFromPackageFiles>
</ItemGroup>
</Project>
No need to change anything in your project or .csproj file.