Changing my projects Json file to A Yaml file using Microsoft

191 Views Asked by At

I am using Microsoft.Extensions.Configuration and would like to change from Json to Yaml do to an sdk change. I have tried just changing .json to .yml and that did not work. I also tried to change AddJsonFile to AddYamlFile both did not work and I commented out the different attempts below.

using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AppiumTestingofmobileapps.Utility
{
    public static class ConfigurationBuilder
    {
        public static IConfiguration InitConfig()
        {
            //var config = new 

            ConfigurationBuilder().AddJsonFile("appsettings.test.json").Build();
            //var config = new ConfigurationBuilder().AddJsonFile("browserstack.yml").Build();
            //var config = new ConfigurationBuilder().AddYamlFile("browserstack.yml").Build();
            return config;
 
2

There are 2 best solutions below

3
Georgi Georgiev On BEST ANSWER

From what I saw there no default addYamlFile extension method in Microsoft.Extensions.Configuration.ConfigurationBuilder ConfigurationBuilder Class for yaml but I saw that there is a Microsoft.Extensions.Configuration.Yaml that you can Install from nuget.

0
Ilya Chumakov On

NetEscapades.Configuration.Yaml can be used for that, it provides a YAML configuration provider with AddYamlFile method:

public static IWebHost BuildWebHost(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .ConfigureAppConfiguration(builder => 
        {
            builder.AddYamlFile("appsettings.yml", optional: false);
        })
        .UseStartup<Startup>()
        .Build();