produce (one) release executable
-
26-05-2021 - |
Вопрос
I have written a little console application that uses s#arp. I can create an executable using the configuration manager and selecting release. I understand that the dlls are needed and that there is apparently no easy way to ‘bind’ (?) everything into one executable:
Is there at least a way to hide:
NHibernate.config
So that the db’s connection string is hidden? I remember that it is possible to encrypt Web.config for asp.net. Maybe something similar is possible?
Any feedback would be very much appreciated. Many thanks in advance.
Решение
You would need to configure the connection string property in code to decrypt, SharpArch provides following overload which allows adding properties to your config:
NHibernateSession.Init(
sessionStorage,
new[] { Server.MapPath("~/bin/Suteki.TardisBank.Infrastructure.dll") },
new AutoPersistenceModelGenerator().Generate(),
Server.MapPath("~/NHibernate.config"),
// You can get all the values from your config and use here,
// if you dont want a config file at all, or just decrypt the
// connection string and provide that value dictionary:
new System.Collections.Generic.Dictionary<string, string>
{
{
NHibernate.Cfg.Environment.ConnectionString, DecryptConnectionString()
}
}, null);
Where the decrypt method DecryptConnectionString() gets the connection string from wherever you like, be it an encrypted config section from app.config or hard coded string.
As Corbin said, this makes it more complicated for average Joe to figure out the connection string, but it can be done, if you are going to be distributing this then I would look into not connecting to the db directly.
Look into ILMerge if you want 1 executable with dlls inside it.