Can I stop Visual Studio 2012+ from ever publishing pack.config and EF files?

When I publish an ASP.NET web application in Visual Studio 2012/2013/2015, Visual Studio will also publish packages.config (from NuGet) and any *. edmx. Charts (from Entity Framework) by default.

I know that I can enter the project and individually switch the properties for these files from Content Consolidation to Create Action No , however I have to do this for every project that I use Entity Framework, or any other package supplied by NuGet.

I can configure the publishing process to exclude files in stages, but is it possible to call Visual Studio 2012/2013/2015 to globally exclude these files in all projects?

+6
source share
1 answer

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.

+4
source

All Articles