Cannot add appsettings.json inside WPF project .net core 3.0

前端 未结 3 368
梦谈多话
梦谈多话 2020-12-29 09:06

I am creating a WPF project using .net Core 3.00, and I am having trouble adding the item appsettings.json file to my project which is to be used

3条回答
  •  有刺的猬
    2020-12-29 09:21

    It's no requirement to switch to an appsettings.json file in .NET Core. You may still use the very same "old" XML-based App.config file in a WPF app that targets .NET Core if you want to.

    Just add a new configuration file (Project->Add New Item->Application Configuration File) to your project and name it "App.config". If you then add the following contents to it:

    
    
       
        
      
    
    

    ...you should be able to get the connection string at runtime using the ConfigurationManager API:

    ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString;
    

    The default WPF template should include the System.Configuration.ConfigurationManager package by default.

提交回复
热议问题