.net core mvc中其他类库获取appsettings.json
电脑版发表于:2019/7/26 13:23
appsetting:
{ "ApplicationSettings": { "DalAssemblyName": "INGEFDal" }, ... }
c#:
public StaticDalFactory() { IConfigurationBuilder builder = new ConfigurationBuilder(); builder.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json")); var root = builder.Build(); //这里将获取到INGEFDal var sampleConnectionString = root["ApplicationSettings:DalAssemblyName"]; assemblyname = sampleConnectionString; }
前提是需要引用其他的库
更多获取方式请参考
这些大佬们的讨论