【问题标题】:Is autogenerated app.config in class library necessary for Entity Framework?实体框架需要类库中自动生成的 app.config 吗?
【发布时间】:2018-08-28 12:47:25
【问题描述】:

我已经在 Visual Studio 中通过NuGet Package Manager 安装了Entity Framework。在我安装这个包的每个项目中,都会出现一个app.config 文件,看起来就像这样:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    </configSections>
    <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
        <providers>
            <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
        </providers>
    </entityFramework>
    <connectionStrings>
        <add name="DatabaseContext" connectionString="data source=(LocalDb)\MSSQLLocalDB;initial catalog=Namespace.ContextName;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
    </connectionStrings>
</configuration>

我想知道这些信息是否仅在启动项目(和单元测试项目)中是必需的。我可以从只使用DbContext 的类库项目中删除app.config 文件吗?

【问题讨论】:

  • 你有没有试过删除它,看看会发生什么?
  • 我还做不到。一旦我尝试过,我会发布我的结果,当时没有人提供答案。

标签: c# visual-studio entity-framework nuget app-config


【解决方案1】:

是的,您可以将它们从您的项目中删除,然后将其保留在启动项目中。但是你的主项目也应该有一个对 EF 包的引用。因此,当您调试或构建版本时,您的附属 dll 将实际使用您启动项目的 app.config 文件。

记住...当您通过 nuget 升级 EF 或其他软件包时,它会再次添加 app.config 文件。

【讨论】:

    猜你喜欢
    • 2015-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-14
    • 1970-01-01
    相关资源
    最近更新 更多