jjzjj

appsettings

全部标签

c# - 从 .net 核心中的 appsettings.json 获取值(value)

不确定我在这里遗漏了什么,但我无法从我的.net核心应用程序中的appsettings.json获取值。我的appsettings.json为:{"AppSettings":{"Version":"One"}}启动:publicclassStartup{privateIConfigurationRoot_configuration;publicStartup(IHostingEnvironmentenv){_configuration=newConfigurationBuilder()}publicvoidConfigureServices(IServiceCollectionserv

c# - 从 .net 核心中的 appsettings.json 获取值(value)

不确定我在这里遗漏了什么,但我无法从我的.net核心应用程序中的appsettings.json获取值。我的appsettings.json为:{"AppSettings":{"Version":"One"}}启动:publicclassStartup{privateIConfigurationRoot_configuration;publicStartup(IHostingEnvironmentenv){_configuration=newConfigurationBuilder()}publicvoidConfigureServices(IServiceCollectionserv

c# - 如何使用最小起订量模拟 ConfigurationManager.AppSettings

我卡在了代码的这一点上,我不知道如何模拟:ConfigurationManager.AppSettings["User"];我必须模拟ConfigurationManager,但我不知道,我正在使用Moq.有人可以给我提示吗?谢谢! 最佳答案 我正在使用AspnetMvc4。刚才我写了ConfigurationManager.AppSettings["mykey"]="myvalue";在我的测试方法中,它运行良好。说明:测试方法在应用程序设置取自的上下文中运行,通常是web.config或myapp.config。Configur

c# - 如何使用最小起订量模拟 ConfigurationManager.AppSettings

我卡在了代码的这一点上,我不知道如何模拟:ConfigurationManager.AppSettings["User"];我必须模拟ConfigurationManager,但我不知道,我正在使用Moq.有人可以给我提示吗?谢谢! 最佳答案 我正在使用AspnetMvc4。刚才我写了ConfigurationManager.AppSettings["mykey"]="myvalue";在我的测试方法中,它运行良好。说明:测试方法在应用程序设置取自的上下文中运行,通常是web.config或myapp.config。Configur

c# - 如何检查 appSettings 键是否存在?

如何检查应用程序设置是否可用?即应用配置在代码文件中if(ConfigurationManager.AppSettings.ContainsKey("someKey")){//DoSomething}else{//DoSomethingElse} 最佳答案 MSDN:ConfigurationManager.AppSettingsif(ConfigurationManager.AppSettings[name]!=null){//Nowdoyourmagic..}或strings=ConfigurationManager.AppSe

c# - 如何检查 appSettings 键是否存在?

如何检查应用程序设置是否可用?即应用配置在代码文件中if(ConfigurationManager.AppSettings.ContainsKey("someKey")){//DoSomething}else{//DoSomethingElse} 最佳答案 MSDN:ConfigurationManager.AppSettingsif(ConfigurationManager.AppSettings[name]!=null){//Nowdoyourmagic..}或strings=ConfigurationManager.AppSe

c# - 从 .NET 中的 app.config 或 web.config 读取设置

我正在开发一个C#类库,它需要能够从web.config或app.config文件中读取设置(取决于DLL是否从ASP.NETWeb应用程序或Windows窗体应用程序引用)。我发现了ConfigurationSettings.AppSettings.Get("MySetting")有效,但该代码已被Microsoft标记为已弃用。我读过我应该使用:ConfigurationManager.AppSettings["MySetting"]但是,System.Configuration.ConfigurationManager类在C#类库项目中似乎不可用。执行此操作的最佳方法是什么?

c# - 从 .NET 中的 app.config 或 web.config 读取设置

我正在开发一个C#类库,它需要能够从web.config或app.config文件中读取设置(取决于DLL是否从ASP.NETWeb应用程序或Windows窗体应用程序引用)。我发现了ConfigurationSettings.AppSettings.Get("MySetting")有效,但该代码已被Microsoft标记为已弃用。我读过我应该使用:ConfigurationManager.AppSettings["MySetting"]但是,System.Configuration.ConfigurationManager类在C#类库项目中似乎不可用。执行此操作的最佳方法是什么?

c# - Docker 中 .NET Core 应用程序的 appSettings.json?

我在docker容器中运行.net核心应用程序。这是我的docker文件(只是为了构建一个开发环境):FROMmicrosoft/dotnet:1.0.1-sdk-projectjsonENVASPNET_ENVDevelopmentCOPYbin/Debug/netcoreapp1.0/publish//root/EXPOSE5000/tcpENTRYPOINTdotnet/root/AVP.WebApi.dll我在/publish/文件夹中有一个appSettings.Development.json文件。如果我构建并运行这个Docker文件,我最终会遇到一个奇怪的问题,即.NET

c# - Docker 中 .NET Core 应用程序的 appSettings.json?

我在docker容器中运行.net核心应用程序。这是我的docker文件(只是为了构建一个开发环境):FROMmicrosoft/dotnet:1.0.1-sdk-projectjsonENVASPNET_ENVDevelopmentCOPYbin/Debug/netcoreapp1.0/publish//root/EXPOSE5000/tcpENTRYPOINTdotnet/root/AVP.WebApi.dll我在/publish/文件夹中有一个appSettings.Development.json文件。如果我构建并运行这个Docker文件,我最终会遇到一个奇怪的问题,即.NET