App Settings to reference ADO Library via Variable Substitution. XML App.Config - c#

Is there a method of swapping the AppSettings on the XML on the app.config file, so that it gets the settings from the variables.
This is for a VSTEST 2019, EasyRepo, UI Test.
I have a bunch of sensitive settings on my app.config which i want to hide, and reference via my Azure Library.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="OnlineUsername" value="MyUserName" />
<add key="OnlinePassword" value="myPassword" />
<add key="OnlineCrmUrl" value="www.url.com" />
<add key="MfaSecretKey" value="" />
<add key="AzureKey" value="" />
etc...
I have attempted a file-transform task, and set the library for the reference of my App.Config file to be transformed. I also put the variables on the YAML it self, but did not work.
Is there a method of swapping the AppSettings on the XML on the app.config file, so that it gets the settings from the variables.

Related

c# App.Config file not transforming when building for Test deployment

I am using slow cheetah in my app such that I can have app.config files that will transform in the same manner as web.config transforms. I have used this in other projects with no issue, but for some reason in one of my projects, the cofing file is not changing.
A sample from my App.Test.config is the following:
<add key="timer" value="300" xdt:Locator="Match(key)" xdt:Transform="SetAttributes"/>
And the corresponding line in my App.config file is
<add key="timer" value="15"/>
The problem turned out that I did not include the <AppSettings> tag before the <Add> tag in the transform. So when the transform went to take place it would look for the key timer within <Configuration> and not <Configuration> <AppSettings>

App Settings from Web.config in WCF Service returning null

I am having an issue retrieving app settings from my web.config file in a WCF service I am creating. When calling my settings, I am retrieving a null value. Digging into the object also shows that there are no keys in AppSettings list.
This issue has a few posts around SO/Google, and I have incorporated all the suggestions, but to no avail. Here is my current position and what I have tried:
web.config:
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
<!-- CRM Creds -->
<add key="CrmUrl" value="[removed]"/>
<add key="CrmUser" value="[removed]"/>
<add key="CrmPass" value="[removed]"/>
</appSettings>...
Methods of calling the settings:
System.Web.Configuration.WebConfigurationManager.AppSettings["CrmUrl"]
System.Configuration.ConfigurationManager.AppSettings["CrmUrl"]
The file I am calling from is within a folder, whereas web.config is in the root. I understand WebConfigurationManager could find this regardless, but I am having no luck.
Code:
%projectfolder%/Client/Client.cs
Config: %projectfolder%/web.config
I have run out of things to try and have used up all my Google-fu. Any suggestions are appreciated.

how to access an XML file stored in the same directory as the DLL when DLL is installed in GAC

I have a dll project which have an xml file. [content of that dll project]
I have installed that dll in My GAC. In some method of that dll I needed to load that xml file. but I can't able to find the path or way by which I can load that xml,
My xml files looks like following
<Data>
<add key="Hostname" value="192.XXX.XXX.111" />
<add key="UserName" value="root123" />
<add key="Password" value="admin1234" />
<add key="SFTP_IncomingFileFolder" value="/root/Inbox/" />
<add key="SFTP_ArchivedFileFolder" value="/root/Archived/" />
<add key="SFTP_OutGoingFileFolder" value="/root/Outbox/" />
<add key="Local_IncomingFileFolder" value="D:\phpFiles2\Inbox\" />
<add key="Local_OutgoingFileFolder" value="D:\phpFiles2\Outbox\" />
<add key="Local_OutgoingArchive" value="D:\phpFiles2\Archived\" />
<add key="ApplicationFolderPath" value="D:\SFTP_Installation\" /><!-- where WinSCP.exe resides-->
</Data>
Expanding from the comments:
You cannot. When you install a DLL in the GAC, only that DLL gets copied into the GAC. You cannot avoid this, at least not in any supported way.
You mentioned in the comments that you want to let your DLL read configuration options. Some workable alternatives for that:
Store the settings in the registry.
Store the settings in the user profile directory.
Store the settings in C:\ProgramData.
Let the calling program (your PHP script) control the settings, and let that calling program read the settings from a file in the program's directory.
None of those options require any files in the same directory as your DLL.

App.config: appSettings "file" attribute is not reading from the Local.config

I have a test project, with an App.config that sets up default values for some settings. I want to override these settings at the local level so each developer can, for instance, use their own credentials.
In my App.config I have the following:
<appSettings file="Local.config">
<add key="Username" value="USERNAME"/>
<add key="Password" value="PASSWORD"/>
</appSettings>
in the Local.config (in the same directory) I have the following:
<appSettings>
<add key="Username" value="wayne"/>
<add key="Password" value="secret"/>
</appSettings>
When I run my test I expect that getting the value of Username would return "wayne" from the Local.config; instead, it's "USERNAME" from the App.config - it seems as though it's not actually detecting that I want to override settings in another file.
What am I doing wrong?
I hate to ask, but are you sure the Local.config is being copied to the output directory?

web.config transform elements not available through System.Configuration.ConfigurationManager

I have a web.config file that's transformed using a web.debug.config file. Trying to get access to these values through System.Configuration.ConfigurationManager.AppSettings is yielding nothing.
My web.config appSettings are empty.
<configuration>
<appSettings>
</appSettings>
</configuration>
My web.debug.config transform that's applied. Here's a sample.
<configuration>
<appSettings>
<add key="CommonURL" value="localhost/mysite/" xdt:Transform="Insert" />
</appSettings>
</configuration>
Here's the code to try and get this value, which returns null.
var cu = System.Configuration.ConfigurationManager.AppSettings["CommonURL"];
Any idea on why this could be?
Assuming that System.Configuration.ConfigurationManager.AppSettings is yielding nothing when you run from Visual Studio, then that is the expected behavior. You should add the CommonURL appSetting to your web.config file and change the entry in the web.debug.config to:
<add key="CommonURL" value="localhost/mysite/"
xdt:Transform="Replace" xdt:Locator="Match(key)" />
These changes will allow you to get the value specified in the web.config when you run from Visual Studio, and will allow that value to be replaced with what is defined in the web.debug.config when you execute the transform (for example, through the Publish function or through a custom MSBuild script). Keep in mind that the transforms are applied when you publish, not when you start running a debug or release build. The values that are in the web.config file are always the ones that are honored.

Categories