There is not an equivalent to the registry in Linux. What are you storing in the registry? First thought is to use a config file but depending on what is stored maybe there is a better way
Windows Registry equivalent support for Linux in .Net 5
We are planning to Move our existing C# .Net framework supported application to .Net 5 or .Net 6 and will be platform indepedent (for now Windows and Linux).
The .Net framework implementaion currently depends on Windows Registry to store few information. Was unable to find any equivalent mechanism to store the same in the Linux platform. Basically i am looking for an similar functionality like "preference" class does in Java.
Any help is appreciated and Thanks in advance.
4 answers
Sort by: Most helpful
-
-
Bruce (SqlWork.com) 71,101 Reputation points
2021-11-22T16:09:39.353+00:00 Linux uses configuration files rather than a registry. Historically there were two locations
~/.programname - user config, for example git uses ~/.gitrc
/etc/programname/ - global systemBut as the number of files has gone up and security increased, there is no true consensus.
~/.config/ is now a popular location for user configuration file.
Global config file location varies by how changeable. See
https://refspecs.linuxfoundation.org/FHS_3.0/fhs/index.html
Note: is also common to use environment variables to define the location of the config files
-
Bruce (SqlWork.com) 71,101 Reputation points
2021-11-22T23:23:59.697+00:00 .net 6 focuses more on reading configuration (app settings) then setting them. there is an azure app setting provider (pushing cloud), but not much for local storage. as dotnet applications are usually deployed to a folder (except on MacOs), typically you can do a read/write appsettings.json file. see all the configuration builder options.
in unix/linux/MacOs there a read only filesystems, where system applications go, and folders for local hardware applications, and read/write folders for data. Of course MacOs has a folder for UI applications, but command line follow the unix conventions, and home-brew has its own conventions.
note: there may be a nuget package that does what you want, but I don't know of one.
-
Petrus 【KIM】 461 Reputation points
2021-11-23T00:53:42.1+00:00 Use the JSON file Rather than Registry. There is not an equivalent...
[DataContract] public class SomeInfo { [DataMember] public string KeyName { get; set; } } public class ConfigManager { public SomeInfo LoadFromJson(string sFilePath) { var vJsonText = File.ReadAllText(sFilePath); // .NET CORE var vOption = new JsonSerializerOptions { WriteIndented = true, PropertyNamingPolicy = null, IgnoreNullValues = true, Encoder = JavaScriptEncoder.Create(UnicodeRanges.All) }; return JsonSerializer.Deserialize<SomeInfo>(vJsonText, vOption); } } --- JSON FILE { "KeyName" : "Value" }