0

I am currently converting a .Net Framework class library to a .Net Standard class library. In Framework we used app.config and had transform files to hold the environment specific data such as connection strings for the environment (Prod, Test, Dev).

I have scoured SO and Google for this answer but keep coming up empty. What is the best way to store and retrieve this data in a .Net Standard class library? At this point I don't care if I have a bit of code that populates properties based on my Build Settings or if I have a file sitting next to the DLL that houses this data. I'm just needing a way to connect to ServerA in dev and ServerB in prod.

I'll have either a .Net Core or .Net Framework project that references this DLL and asks this DLL for data but I want this library to house it's own DB connection, not passing it from the hundreds of apps calling it.

Mr. Anderson
  • 165
  • 2
  • 10

1 Answers1

0

Turns out System.Configuration.ConfigurationManager was added back in .NETStandard 2.0.

Just pull it in from nuget and compile the .NETStandard 2.0 class library project.

Then, the library will work across projects using standard config files:

  • Net Core 2.0 projects use app.config
  • Web projects work from web.config
  • Console and Windows apps work with app.config

(This is of course assuming you're going to .NET Standard 2.0)

Then, here's a post I found that discusses how to use ConfigurationManager in case you need some examples.

hmiedema9
  • 948
  • 4
  • 17