C# Exe文件中嵌入的配置文件

C# Exe文件中嵌入的配置文件,c#,app-config,C#,App Config,我想创建一个应用程序,它是App.config文件数据,比如connectionString等。。。嵌入到Exe文件中 当应用程序在创建exe文件和删除app.config文件后释放.exe文件时 如何在没有app.config文件的情况下运行应用程序 如何在.exe文件中嵌入app.config文件 我的配置文件: <?xml version="1.0" encoding="utf-8"?> <configuration> <configSections>

我想创建一个应用程序,它是App.config文件数据,比如connectionString等。。。嵌入到Exe文件中

当应用程序在创建exe文件和删除app.config文件后释放.exe文件时 如何在没有app.config文件的情况下运行应用程序

如何在.exe文件中嵌入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" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <connectionStrings>
    <add name="DataBaseEntities" connectionString="metadata=res://*/Model.DataBase.csdl|res://*/Model.DataBase.ssdl|res://*/Model.DataBase.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=127.0.0.1;initial catalog=DataBase;persist security info=True;user id=abc;password=123;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <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>
</configuration>

我的节目:

    public static void Main(string[] args)
    { 
        using (DataBaseEntities entities = new DataBaseEntities())
        {
            List<User> user= objEntities.UserTable.ToList();              
        }

        Console.ReadKey();
    }
publicstaticvoidmain(字符串[]args)
{ 
使用(DataBaseEntities=新DataBaseEntities())
{
List user=objenties.UserTable.ToList();
}
Console.ReadKey();
}

atfer Delete app.config文件运行应用程序并按原样检索数据。

app.config是配置文件-它是可配置的。如果您不想使用它,则将这些值硬编码为常量(和/或使用默认值设置应用程序),并使用代码进行配置

必须在app.config的属性中将app.config的生成操作设置为“嵌入式资源”。它将作为文件在bin文件夹中消失,并将包含在*.exe文件中

如果我弄错了,很抱歉:您希望在编译后编辑app.config。但是,一旦删除它,您就希望保留app.config?中的最后配置?。。。您应该考虑配置的用例。否则,我会将其保存为程序中的静态只读属性。如果内容更改,我猜exe的安全检查将失败。但我可能错了。有人能对此发表评论吗?先创建app.config文件,然后删除app.config文件,然后运行应用程序。它不起作用。它不会消失,如果被删除,应用程序将无法启动。