我想创建的应用程序是像connectionString等App.config文件数据…嵌入到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="data source=127.0.0.1;initial catalog=DataBase;persist security info=True;user id=abc;password=123;MultipleActiveResultSets=True;App=EntityFramework"" 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();
}
atfer删除app.config文件运行应用程序并按原样检索数据。
发布于 2017-08-03 13:23:01
您必须在app.config的属性中将app.config的生成操作设置为"Embedded Resource“。它将作为bin文件夹中的一个文件消失,并将包含在*.exe文件中
发布于 2017-08-03 13:20:10
App.config是可配置的-它应该是可配置的。如果您不想使用它,那么将值硬编码为常量(和/或将应用程序设置为默认值),并使用代码进行配置。
https://stackoverflow.com/questions/45485108
复制