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

◇◆丶佛笑我妖孽 提交于 2019-12-23 09:37:01

问题


When I publish an ASP.NET Web Application in Visual Studio 2012/2013/2015, Visual Studio will also publish the packages.config (from NuGet) and any *.edmx.diagram files (from Entity Framework), by default.

I know that I can go into the project and individually switch the properties for these files from Build Action Content to Build Action None, however, I have to do this for each project that I use Entity Framework, or any other NuGet-provided package.

I can configure the publishing process to exclude files on a project-by-project basis, but is it possible to tell Visual Studio 2012/2013/2015 globally to exclude these files, across all projects?


回答1:


You can exclude files by extension or filename modifying properties in the web.config file. Look at the documentation for the buildproviders element in web.config. You can add the extension and map it to the System.Web.Compilation.ForceCopyBuildProvider, or add the filename and use the 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 your project file. Within a PropertyGroup element, you can add ExcludeFilesFromDeployment and ExcludeFoldersFromDeployment elements to exclude the desired items.

<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 details: Exclude files from web site publish in Visual Studio

UPDATE: In answer to the revised requirement that you be able to do this globally, across all projects and solutions, I'd suggest that you create a build target file that you could import into your project files. Within the target file, you can identify the file and folder exclusions you want to make.

To make it easier to deliver this build target to all of your solutions, you could create a NuGet package that contains the target file and modifies your .csproj files accordingly.

This is essentially the approach used by SlowCheetah to extend the web.config transform process to other .config files; the NuGet package delivers a custom .targets file that extends the build process.

The initial setup is an effort, but if you're supporting a lot of solutions or teams, it might be the best approach.



来源:https://stackoverflow.com/questions/31459951/can-i-stop-visual-studio-2012-from-ever-publishing-packages-config-and-ef-diagr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!