app-config 相关问题

.NET应用程序配置文件包含特定于应用程序的设置。

为 Azure 静态 Web 应用程序 (React MSAL) 配置应用程序设置

我正在了解每个环境的 React 应用程序中的 MSAL 身份验证。 authConfig.ts 从“@azure/msal-browser”导入{配置}; import { envConfig } from "./config&qu...

回答 1 投票 0

MDriven:找不到方法:Eco.Persistence.SyncVersion

我们有一个遗留解决方案,该解决方案始于 10 多年前的 ECO times。包含模型工程1个,生态空间工程1个,WinForms工程1个,ASP.NET工程1个。 我们现在需要...

回答 1 投票 0

如何在 C# 窗口 exe 中创建自己的配置文件?

我创建了一个带有连接 mqtt 代理的 C# windows 应用程序,以便在计算机中安装应用程序后。配置文本文件可以在安装文件下看到配置mqtt IP地址,端口

回答 0 投票 0

struts2 java web 应用程序的应用程序属性

我是 Struts2 框架的新手,我正在尝试添加一些配置属性,如 applicationId、timeout 等,这些属性将用于调用一些第 3 方 API。在一个Springboot项目中,我们...

回答 1 投票 0

SendKeys:发送到某个应用程序时,它不适用于所有计算机

第一次来电的长期听众。 Windows 10/11 .Met 4.52 Sendkeys 命令 我有一个使用 sendkeys 命令的简单应用程序,它是用 VBNet 框架 4.5.2 编写的,旨在发送

回答 0 投票 0

为.net core 3.1 web api应用程序添加app.config。

我正在把我的项目从.net framework转移到.net core 3.1 web api上。.net似乎不包含app.config文件,我需要添加它。我添加了一个,但它的不识别。有没有一种方法来添加...

回答 1 投票 0

app.config中的<runtime>有什么作用?

我刚刚为我的Console应用程序更新了一些nuget包,现在我的app.config有这个。

回答 1 投票 0

如何用App.config连接C#与Db?

我需要使用app.config.连接C#与SQL Server数据库,我的代码是: public partial class Form1 : Form { string connectionString = ConfigurationManager.ConnectionStrings["Conn"]。我的代码是: public partial class Form1 : Form { string connectionString = ConfigurationManager.ConnectionStrings["Conn"]...。

回答 3 投票 4

为什么尝试加载 System.Configuration.AppSettingsSection 配置部分失败?

My App.Config(删除其他内容)如下所示: 我的 App.Config(删除其他东西)看起来像这样: <configuration> <configSections> <section name="Settings" type="System.Configuration.AppSettingsSection, System.Configuration" /> </configSections> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" /> </startup> <connectionStrings> ... </connectionStrings> <appSettings> ... </appSettings> <Settings> <add key="something" value="5"/> </Settings> </Configuration 我有一个使用 System.Configuration.AppSettingsSection 作为键值对的自定义配置部分是我所需要的。 但是,当我尝试使用以下代码访问它时: var settings = (NameValueCollection)ConfigurationManager.GetSection("Settings"); 我得到一个例外: System.TypeInitializationException HResult=0x80131534 Message=The type initializer threw an exception. Source=... Inner Exception 1: ConfigurationErrorsException: An error occurred creating the configuration section handler for Settings: Could not load file or assembly 'System.Configuration' or one of its dependencies. The system cannot find the file specified. Inner Exception 2: FileNotFoundException: Could not load file or assembly 'System.Configuration' or one of its dependencies. The system cannot find the file specified. 为什么不能利用System.Configuration?我基于我在网上看到的代码,所以如果有更简洁的方法来获得相同的效果,我很乐意更改它 - 我只是想避免在不需要时编写自定义配置部分类。 正如评论中提到的那样,问题是执行文件夹中不存在System.Configuration.dll。 我发现在 VS 中添加对 DLL/程序集的引用时,属性包含一个“复制本地”选项,该选项导致将副本作为构建的一部分进行复制,而不是依赖于已安装的框架版本。 这解决了我的问题。我确实 not 但是理解为什么我需要这样做。分发框架 DLL 的副本似乎不是一个好主意。我会暂时不接受我的答案,以防其他人可以提供更全面的解释why 而不仅仅是how. 异常是由于这个: System.Configuration.TypeUtil.GetImplicitType 中的第 52 行 https://github.com/dotnet/runtime/blob/main/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/TypeUtil.cs 如果删除程序集名称,它将起作用,因为您的类型声明中不会有逗号。

回答 2 投票 0

我如何让我的c#控制台应用程序用app.config运行?

这对我来说是很奇怪的,尽管我确信我错过了一些简单而基本的东西。我有一个控制台应用程序,从app.config中读取SQL连接。它在Visual Studio中运行良好。当我...

回答 1 投票 1

stackoverflow删除我的所有帖子。您的编辑器是-1投票机。您就像美国警察

由于智商低的编辑者正在投票回答我的问题-1,我讨厌stackoverflow。

回答 1 投票 -3

哪里需要覆盖应用配置数据?

我有一个控制台应用程序,需要存储LastRunDate(上次运行的时间)。这是计算机上所有用户的通用日期。每次用户运行此应用程序时,此值都应更新。 ...

回答 2 投票 1

如何在同一解决方案中从.NET Framework类库项目访问属于.NET Core Web API项目的appSettings.json?

我有一个单独的类库项目(.NET Framework 4.8),用于访问数据库。此类库是用Visual Basic(VB)编写的。最近,由于一项新要求,我不得不在...

回答 1 投票 1

app.config中的自定义配置部分-XML属性与元素的关系

我已经有一个基于配置的自定义配置部分,例如: [[[[] ] >> 据我所知,使用ConfigurationManager时无法将 values 放在app.config文件的xml节中>但是您有一个非常类似的选项来使用这样的配置结构: <DataSourcesConfig> <DataSources> <DataSource> <name value="test1"/> <connectionType value="Ethernet_TCP_Client"/> <protocolType value="Serial"/> <ipAddress value="127.0.0.1"/> <port value="12345"/> </DataSource> <DataSource> <name value="test2"/> <connectionType value="Ethernet_TCP_Client"/> <protocolType value="Serial"/> <ipAddress value="127.0.0.1"/> <port value="12346"/> </DataSource> </DataSources> </DataSourcesConfig> 首先,您需要定义一个ValueElement: public class ValueElement<T> : ConfigurationElement { [ConfigurationProperty("value", IsRequired = true)] public T Value => (T) this["value"]; } 下一步,像这样更改DataSource元素: public class DataSource : ConfigurationSection // It is section now { [ConfigurationProperty("name", IsRequired = true)] public ValueElement<string> Name => this["name"] as ValueElement<string>; [ConfigurationProperty("connectionType", IsRequired = true)] public ValueElement<string> ConnectionType => this["connectionType"] as ValueElement<string>; [ConfigurationProperty("protocolType", IsRequired = true)] public ValueElement<string> ProtocolType => this["protocolType"] as ValueElement<string>; [ConfigurationProperty("ipAddress", IsRequired = true)] public ValueElement<string> IPAddress => this["ipAddress"] as ValueElement<string>; [ConfigurationProperty("port", IsRequired = true)] public ValueElement<int> Port => this["port"] as ValueElement<int>; } 现在您可以在这样的代码中使用您的配置: var configuration = DataSourcesConfig.GetConfig(); var test1name = configuration.DataSources[0].Name.Value; // test1 as string var test2name = configuration.DataSources[1].Name.Value; // test2 as string var portForTest1 = configuration.DataSources[0].Port.Value // 12345 as int

回答 1 投票 0

如何针对Visual Studio中的不同环境使用不同的配置来部署Azure WebJob

我们有多个针对不同环境的Web Apps和WebJob,它们具有不同的配置,例如测试并发布。每个WebJob都使用Visual中的“发布为Azure WebJob”部署到Web应用程序...

回答 2 投票 3

如何使用外部.config文件解析键/值对

我在app.config文件中指定 ,我要添加 [[[[] ] >>>>> 我建议在 [C0中使用file属性(对应于AppSettingsSection.File属性)代替configSource 属性(对应于SectionInformation.ConfigSource属性) ] 部分。 appSettings不支持本节中的其他键,而configSource可能包含应用程序可能需要的其他键,也可能包含其他键(出于测试目的或任何其他原因,其他人可以添加/删除它们)。 appSettings属性改为允许在file部分中存在其他键。 您的appSettings文件可以是: app.config 现在可以通过打开命名的配置部分来访问这些值: [<?xml version="1.0" encoding="utf-8"?> <configuration> <appSettings file="ShareAppSettings.debug.config"> <add key="DpiAwareness" value="PerMonitorV2"/> </appSettings> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1"/> </startup> </configuration> 返回一个appSettings.Settings[] KeyValueConfigurationElement 并直接使用Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); AppSettingsSection appSettings = (AppSettingsSection)config.GetSection("appSettings"); var kvpClientID = appSettings.Settings["clientID"]; var kvpClientSecret = appSettings.Settings["clientSecret"]; var kvpCenantID = appSettings.Settings["tenantID"]; string clientID = kvpClientID.Value; -一个ConfigurationManager.AppSettings-返回指定键的值: NameValueCollection 请注意,使用string clientID = ConfigurationManager.AppSettings["clientID"]; string clientSecret = ConfigurationManager.AppSettings["clientSecret"]; string tenantID = ConfigurationManager.AppSettings["tenantID"]; 属性,您的file不需要(但不是禁止的)XML标头,它可以仅仅是: ShareAppSettings.debug.config

回答 1 投票 0

如何通过c#控制台应用程序中的App.config文件控制静态html页面的动态html表的样式?

我一直在努力做某事。我有一个控制台应用程序,用于查找某些文件(如果不存在)。因此,此应用程序将电子邮件发送到我的电子邮件ID。正常的SuccessBody.html ...

回答 2 投票 0

C#如何在app.config文件中指定appData文件路径

我正在使用log4net,我将日志文件保存在AppData文件中以用于Win XP / Vista等。到目前为止,这是我的app.config文件,我已指定名称softphone.log。 ew,我不确定如何...

回答 2 投票 18

如何发布.net Framework Windows服务

我有一个使用.net core构建的Windows服务,我可以使用发布配置文件进行发布,并且由于我使用appsettings,因此我也可以定位环境。试图找出解决方案...

回答 1 投票 0

使用登录的用户凭据运行.NET控制台应用程序

我编写了基于C#的控制台应用程序(具有SharePoint Managed Client对象模型),并在app.config(硬编码但以加密形式)中配置了凭据以运行应用程序,...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.