我可以停止Visual Studio 2012+来发布packages.config和EF图文件吗? [英] Can I stop Visual Studio 2012+ from ever publishing packages.config and EF diagram files?

查看:111
本文介绍了我可以停止Visual Studio 2012+来发布packages.config和EF图文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Visual Studio 2012/2013/2015中发布ASP.NET Web应用程序时,Visual Studio还将发布 packages.config (来自NuGet)和任何 *.edmx.图文件(来自Entity Framework),默认情况下.

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.

我知道我可以进入项目并将这些文件的属性从 Build Action Content 分别切换为 Build Action None ,但是,我必须这样做对于我使用Entity Framework或任何其他NuGet提供的程序包的项目.

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.

我可以配置发布过程,以便逐个项目地排除文件,但是有可能告诉Visual Studio 2012/2013/2015 全局在所有项目中排除这些文件?

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?

推荐答案

您可以在web.config文件中通过扩展名或文件名修改属性来排除文件.查看文档,以了解Web中 buildproviders元素的文档.配置.您可以添加扩展并将其映射到System.Web.Compilation.ForceCopyBuildProvider,或者添加文件名并使用System.Web.Compilation.IgnoreFileBuildProvider

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

buildproviders部分具有以下结构:

The buildproviders section has the following structure:

<buildProviders> 
   <add />
   <clear/>
   <remove />
</buildProviders>

您还可以通过修改项目文件来排除文件或文件夹.在PropertyGroup元素内,可以添加ExcludeFilesFromDeployment和ExcludeFoldersFromDeployment元素以排除所需的项.

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>

有关更多详细信息,请参见此问题的答案:>排除网站上的文件在Visual Studio中发布

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.

要使将此构建目标轻松交付给所有解决方案,您可以创建一个包含目标文件的NuGet程序包,并相应地修改.csproj文件.

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.

这实际上是 SlowCheetah 所使用的方法将web.config转换过程扩展到其他.config文件; NuGet软件包提供了一个自定义.targets文件,该文件扩展了构建过程.

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.

这篇关于我可以停止Visual Studio 2012+来发布packages.config和EF图文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆