C# 实体框架是否需要类库中自动生成的app.config?

C# 实体框架是否需要类库中自动生成的app.config?,c#,visual-studio,entity-framework,nuget,app-config,C#,Visual Studio,Entity Framework,Nuget,App Config,我已经在Visual Studio中安装了via。在我安装此软件包的每个项目中,都会出现一个app.config文件,该文件与以下内容完全相同: <?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <section name="entityFramework" type="System.Data.Entity.Internal.Config

我已经在Visual Studio中安装了via。在我安装此软件包的每个项目中,都会出现一个
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>


我想知道这些信息是否只在启动项目(以及单元测试项目)中才有必要。我是否可以从类库项目中删除
app.config
文件,该项目仅使用
DbContext

是的,您可以从项目中删除它们,并将其保留在启动项目中。但是您的主项目也应该有EF包的引用。因此,当您调试或构建发行版时,您的卫星dll将实际使用启动项目的app.config文件


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

是的,您可以从项目中删除它们,并将其保留在启动项目中。但是您的主项目也应该有EF包的引用。因此,当您调试或构建发行版时,您的卫星dll将实际使用启动项目的app.config文件


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

您是否尝试过删除它,并看到发生了什么?我还无法执行此操作。一旦我尝试了它,我会发布我的结果,当时没有人提供答案。你尝试过删除它,看看会发生什么吗?我还没能做到。一旦我尝试了,我会发布我的结果,当时没有人提供答案。