问题
I never came across the needs until now to do something about publishing of the XML configuration files that come with EntityFramework referenced projects.
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.
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).
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:
- Remove the file completely from the bin folder on publish (if possible)
- Remove the connection string from the file on publish (if possible)
回答1:
I've found an answer 5 minutes later - it's not perfect so if anyone has a better solution please go ahead.
In .NET Framework;
The way to remove all .dll.config
files is to modify the publish profile.
Inside the <PropertyGroup>
include the following:
<ExcludeFilesFromDeployment>bin\*.dll.config</ExcludeFilesFromDeployment>
and it'll exclude the redundant configuration files from the \bin\
folder.
For .NET Core, the following will work;
Inside your solution, edit the proj (csproj
) file, adding the below inside ItemGroup
tag.
<Content Update="entityframework.dll.config" CopyToPublishDirectory="Never" />
来源:https://stackoverflow.com/questions/53266725/disable-publish-of-ef-configuration-files-to-bin-folder