admin管理员组文章数量:1296465
I am working on a .NET 4.8 application, I updated the packages Microsoft.Configuration.ConfigurationBuilders
(Environment, Json, UserSecrets) from version 2.0 to 3.0. I have also updated my app.config
file to reflect the latest version, shown here:
<configBuilders>
<builders>
<add name="Environment" type="Microsoft.Configuration.ConfigurationBuilders.EnvironmentConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Environment, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="Secrets"
userSecretsFile="./App_Data/secrets.xml"
mode="Greedy"
type="Microsoft.Configuration.ConfigurationBuilders.UserSecretsConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.UserSecrets, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</builders>
</configBuilders>
The structure of the secrets.xml file is given below:
<root>
<secrets ver="1.0">
<secret name="App:UserKey" value="Hello World"/>
</secrets>
</root>
Before the update, when the version was 2.0. I was able to read the value from the secrets.xml
file specified in the app.config
key userSecretsFile
:
var userKey = System.Configuration.ConfigurationManager.AppSettings["App:UserKey"];
After the update from version 2 to 3, this code does not work anymore and returns an empty string. I read the update guide but none of it provides troubleshooting guidance. I tried to update the path from ./App_Data/secrets.xml
to ~/App_Data/secrets.xml
for testing even then I get an empty string in the variable userKey
. I also tried updating the structure of the secrets.xml
file to the one given below but still no success
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="App:UserKey" value="Hello World" />
</appSettings>
</configuration>
It seems that there could be an issue with how the UserSecrets
package reads the path of the userSecretsFile
in version 2 vs version 3. If I switch back to version 2 everything works as expected.
I also read this Stackoverflow post which talks about the same problem and I am doing things as suggested in the old posts but not sure what else needs to be added/updated.
Update:
I looked inside the path \bin\Debug\net48\win7-x86\App_Data
for the secrets/xml
file and it wasn't there so in visual studio I right clicked the file and updated the property Copy to Output Directory
from Do not copy
to Copy if newer
and it worked but I didn't had to do this in the previous version? Is this like an undocumented step that needs to happen for version 3?
本文标签:
版权声明:本文标题:c# - .NET v4.8: updating the Microsoft.Configuration.ConfigurationBuilders to version 3.0 does not work - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741638253a2389764.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论