[英]How can I share config file like appsettings.json across multiple ASP.NET CORE projects in one solution in Visual Studio 2015?
[英]Share variable in web.config Across Projects in a Solution in Visual Studio
我有一个包含3个项目的解决方案:ASP.net MVC 4.0,Share Library和Web Service项目。 我想将ASP.net mvc项目中Web.Config的appSettings中的一些关键值共享给Web服务项目。 我找到了这个答案,但现在对我有用。
任何人都可以给我一些想法。
非常感谢。
您可以将该信息存储到将在所有项目中共享的dll中:
创建一个新的类库项目:
例如,将您的类命名为MyConfiguration.cs
namespace CentralizedInformation
{
public static class MyConfiguration
{
public static string Value1 = "Test string value 1";
public static int Value2 = 2;
}
}
在您可以在所有项目中添加引用之后(项目->添加引用->浏览->浏览到CentralizedInformation.dll)
并将其添加到您的项目中(这里是一个mvc项目示例)
using CentralizedInformation;
//for asp net mvc project
protected void Application_Start()
{
string mySharedAccrossAllProjectsString = CentralizedInformation.MyConfiguration.Value1;
//put it wherever you need it session or anything else
}
Juste在其他项目中引用相同的内容,您就完成了。 当您要更新数据时,还可以重建项目...
该dll可能有一个配置文件,您可以以编程方式公开其所有数据。
我承认这是做这种简单事情的一种非常有趣且复杂的方法。 但这是一种方式^^
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.