如何在Visual Studio 2015的一种解决方案中跨多个ASP.NET CORE项目共享诸如appsettings.json之类的配置文件? [英] How can I share config file like appsettings.json across multiple ASP.NET CORE projects in one solution in Visual Studio 2015?

查看:125
本文介绍了如何在Visual Studio 2015的一种解决方案中跨多个ASP.NET CORE项目共享诸如appsettings.json之类的配置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个解决方案中,我有3个ASP.NET CORE项目,我想在这些项目中的一个配置文件(如appsettings.json)中共享连接字符串信息.

I have 3 ASP.NET CORE projects in one solution and I want to share connection string information in one config file like appsettings.json across these projects.

如何在Visual Studio 2015中执行此操作?

How can I do this in Visual Studio 2015 ?

推荐答案

您可以像这样在每个项目上使用绝对路径(我假设appsettings.json文件位于解决方案的根目录中(例如global.json)):

You can use absolute path on each project like this(I assume appsettings.json file is in the solution root directory(like global.json) ):

var settingPath = Path.GetFullPath(Path.Combine(@"../../appsettings.json")); // get absolute path
var builder = new ConfigurationBuilder()
        .SetBasePath(env.ContentRootPath)
        .AddJsonFile(settingPath);

请参见 https://github.com/aspnet/Configuration/issues/440

这篇关于如何在Visual Studio 2015的一种解决方案中跨多个ASP.NET CORE项目共享诸如appsettings.json之类的配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆