Currently, my application automatically encrypts its own App.config file the first time the application is launched.
I’m using the ConfigurationManager class as demonstrated in this article:
Now I want the App.config to already be encrypted before the application launches the first time.
Reason why is that I have added an installer to my solution and I don’t want an installer that drops an un-encrypted App.config. I want the process to be automated.
(only thing I came up with so far is attaching an .exe to the Post-Build Event, but isn’t there a more straight forward way?)
First Option: Using built in MSBuild Exec Task execute own utility program which is able to encrypt configuration file.
Second Option: Own MSBuild task
I believe you can write a simple
MSBuildTask which will findApp.Configfile and then encrypt it whilst Solution build.EncryptConfig.targetscsprojfile by<Import Project="EncryptConfig.targets" />DependsOnTargetsfor standardAfterBuildtargets in csproj:4) Write own task and execute it in
EncryptConfig.targetsHow-to write own task: