You can exclude files with the extension or modification of the file name in the web.config file. See the documentation for the buildproviders element in web.config . You can add the extension and map it to System.Web.Compilation.ForceCopyBuildProvider or add the file name and use System.Web.Compilation.IgnoreFileBuildProvider
The buildproviders section has the following structure:
<buildProviders> <add /> <clear/> <remove /> </buildProviders>
You can also exclude files or folders by modifying the project file. In the PropertyGroup element, you can add ExcludeFilesFromDeployment and ExcludeFoldersFromDeployment elements to exclude the necessary elements.
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <ExcludeFilesFromDeployment>File1.aspx;File2.aspx</ExcludeFilesFromDeployment> <ExcludeFoldersFromDeployment>Folder1;Folder2</ExcludeFoldersFromDeployment> </PropertyGroup>
See the answers to this question for more information: Exclude files from a website in Visual Studio
UPDATE:. In response to the revised requirement that you can do this globally, in all projects and solutions, I suggest you create a target file that can be imported into project files. In the target file, you can define the exclusions of the files and folders that you want to create.
To simplify the delivery of this build target to all your solutions, you can create a NuGet package containing the target file and modify your .csproj files accordingly.
This is essentially the approach used by SlowCheetah to extend the process of converting web.config to other .config files; The NuGet package provides a custom .targets file that extends the build process.
Initial setup is an effort, but if you support many solutions or teams, this might be the best approach.
source share