Windows Registry equivalent support for Linux in .Net 5

Sruti Ranjan Majhi 1 Reputation point
2021-11-22T11:52:13.587+00:00

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.

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,399 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,288 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Ken Tucker 5,846 Reputation points
    2021-11-22T12:30:48.303+00:00

    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


  2. Bruce (SqlWork.com) 56,846 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 system

    But 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


  3. Bruce (SqlWork.com) 56,846 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.

    0 comments No comments

  4. Petrus 【KIM】 456 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"
    }
    
    0 comments No comments