禁止将EF配置文件发布到bin文件夹 [英] Disable publish of EF configuration files to bin folder

查看:262
本文介绍了禁止将EF配置文件发布到bin文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

直到现在我再也没有遇到过需要发布与EntityFramework引用的项目一起提供的XML配置文件的事情。

I never came across the needs until now to do something about publishing of the XML configuration files that come with EntityFramework referenced projects.

这些配置文件包含的连接字符串也在启动项目的 Web.config 内-我们现在不希望这样做。

Those configuration files contain connection strings that are also within the Web.config of the start-up project - which we do not want right now.

我知道这些配置文件在VS中时对于EF和模型是必不可少的,但是由于连接字符串来自 Web.config 而不是 Models.dll.config 是否有一种简单的方法可以在发布前将其删除? (我知道我们可以手动执行此操作,但是宁愿将其自动化)。

I understand that those configuration files are mandatory for EF and models while they are within VS, but since the connection string is taken from the Web.config and not Models.dll.config is there an easy way to remove them pre-publish? (I know we can do it manually but would rather automate the process).

我提到的文件位于DLL文件夹中的所有DLL中。该网站。

The files that I are in mention reside within the \bin folder among all the DLLs of the site.

如果有人可以确认并在以下两个示例之一中显示一个,我将不胜感激:

I would appreciate if someone could confirm and show an on either one of the two examples:


  • 在发布时(如果可能)从bin文件夹中完全删除文件

  • 在发布时(如果可能)从文件中删除连接字符串

推荐答案

5分钟后我找到了答案-并不完美,所以如果有人有更好的解决方案,请

I've found an answer 5 minutes later - it's not perfect so if anyone has a better solution please go ahead.

在.NET Framework中;

In .NET Framework;

删除所有 .dll.config 文件用于修改发布配置文件。

The way to remove all .dll.config files is to modify the publish profile.

< PropertyGroup> 内包括以下内容:

< ExcludeFilesFromDeployment> bin\ * .dll.config< / ExcludeFilesFromDeployment>

这红色 \bin\ 文件夹中的多余配置文件。

and it'll exclude the redundant configuration files from the \bin\ folder.

对于.NET Core,以下将起作用;

For .NET Core, the following will work;

在您的解决方案中,编辑proj( csproj )文件,并在内添加以下内容ItemGroup 标记。

Inside your solution, edit the proj (csproj) file, adding the below inside ItemGroup tag.

< Content Update =" entityframework.dll.config" CopyToPublishDirectory =从不 />

这篇关于禁止将EF配置文件发布到bin文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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