我在 Visual Studio 2013 中有网站项目。我有两个发布配置文件,一个用于登台,另一个用于生产。在配置管理器中,我可以创建新的活动解决方案配置,但无法将新配置添加到下拉列表中,调试是唯一的选项。
因此,现在当我尝试使用生产配置文件进行发布时,web.config 会被 Web.Debug.Config 和 web.Production.Config 进行转换。
如何将新配置添加到下拉列表中?

我需要在运行时修改 a 的<configuration><system.diagnostics>部分,app.config以便我可以:
CustomTraceListener在<sharedListeners>元素下添加一个,这需要特殊的initializeData,只能在运行时确定。
将CustomTraceListener共享侦听器添加到<source><listeners>元素下的现有源。
将 持久化CustomTraceListener到其他程序集,这些程序集从配置文件加载其跟踪源和侦听器配置。
中的相关部分app.config目前看起来像这样:
<system.diagnostics>
<sources>
<source name="mysource" switchName="..." switchType="...">
<listeners>
<add name="console" />
<add name="customtracelistener" /> /// need to add new listener here
</listeners>
</source>
</sources>
<sharedListeners>
<add name="console" type="..." initializeData="..." />
<add name="customtracelistener" type="..." initializeData="..."> /// need to add custom trace listener here
<filter type="..." initializeData="Warning"/> /// with a filter
</add>
</sharedListeners>
<switches>
<add name="..." value="..." /> …Run Code Online (Sandbox Code Playgroud) 我根本无法让Visual Studio 2005找到System.Configuration.ConfigurationManager类.这是代码:
using System.Configuration;
...
x = ConfigurationSettings.AppSettings["MySetting"]
// The name 'ConfigurationManager' does not exist in the current context
x = System.Configuration.ConfigurationManager.AppSettings["MySetting"]
// The type or namespace name 'ConfigurationManager' does not exist in the
// namespace 'System.Configuration' (are you missing an assembly reference?)
Run Code Online (Sandbox Code Playgroud)
我绝对,积极做有一个参考System.Configuration项目,它肯定是在正确的项目.DLL版本为2.0.0.0,运行时版本为2.0.50727 - 与其他版本完全相同.我试过删除引用并重新添加它.奇怪的是,当它显示在项目的References'文件夹'中时,它显示为'System.configuration' - 带有小写'c'.
Visual Studio可以找到System.Configuration.ConfigurationSettings类,除了它已过时的警告之外没有任何问题.该项目是一个Web项目,代码位于WebControl的代码隐藏中.
有什么想法在这里发生了什么?
快速背景:我有一个VB.NET应用程序,我之前使用ConfigurationSettings.AppSettings从app.config读取,并收到一条错误消息,将其更改为System.Configuration.ConfigurationManager.AppSettings(因为第一种方式现已过时) )
我这样做了,我甚至在顶部引用了System.Configuration.dll和Imports语句,但是我收到了"Name ConfigurationManager not declared"错误消息.有什么建议?
代码:这很简单 - 我只是检查某些东西是否存在,如果存在,我会从中读取:
If Not Exists(ConfigurationManager.AppSettings.Get(rep & "Email")) Then
Return False
End If
message = ReadAllText(ConfigurationManager.AppSettings.Get(rep & "Email"))
Run Code Online (Sandbox Code Playgroud) 我想ConfigurationManager.AppSettings从MEF插件访问对象中的值,该插件有自己的app.config文件.
但是,加载插件后,app.config文件中的密钥不存在AppSettings.来自加载插件的应用程序的密钥仍然存在.
我注意到使用Settings.settings文件允许通过文件执行此app.config操作,因此必须以某种方式加载文件.
我的插件看起来像:
[Export(IPlugin)]
public class Plugin
{
public Plugin()
{
// reads successfully from app.config via Settings object
var value1 = Settings.Default["Key1"];
// returns null from app.config via ConfigurationManager
var value1 = ConfigurationManager.AppSettings["Key2"]
}
}
Run Code Online (Sandbox Code Playgroud)
该app.config如下所示:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="..." >
<section name="Plugin.Settings" type="..." />
</sectionGroup>
</configSections>
<appSettings>
<add key="Key2" value="Fails" />
</appSettings>
<applicationSettings>
<Plugin.Settings>
<setting name="Key1" serializeAs="String">
<value>Works</value> …Run Code Online (Sandbox Code Playgroud) 在我的程序的顶部,我有以下内容:
using System.Configuration;
Run Code Online (Sandbox Code Playgroud)
在我的代码中,我有以下内容:
int CompanyID = Convert.ToInt32(ConfigurationManager.AppSettings["CompanyId"]
.ToString());
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
The name 'ConfigurationManager' does not exist in the current context
Run Code Online (Sandbox Code Playgroud)
我不确定我错过了什么.
SQL Server 2016中的SQL Server配置管理器在哪里?
它不在SQL Server 2016的菜单组下.
(我安装了Developer Edition)
我已经为我的应用程序编写了一个自定义配置,但是我没有正确的方法来确定ConfigurationSection中是否不存在任何ConfigurationElement。
这是我的自定义配置app.config代码
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="ApplicationsSettings" type="App.Configuration.ConfigurationGroup, App.Configuration.Core">
<section name="DataExtractorSettings" type="App.Configuration.DataExtractorConfig, App.Configuration.Core" />
</sectionGroup>
</configSections>
<ApplicationsSettings>
<DataExtractorSettings>
<executionLog>
<enabled value="Y" />
<copyOnReportDirectory value="Y" />
<logFilePath value="D:\MyBatchProcessLog\MasterDataExtractor" />
</executionLog>
<eMail>
<fromEmailID value="gupta@gmail.com" />
<webURL value="http://PROD/login.aspx" />
</eMail>
<!--<parallelProcessing>
<allowed value="Y" />
<threds value="6" />
</parallelProcessing>-->
</DataExtractorSettings>
</ApplicationsSettings>
</configuration>
Run Code Online (Sandbox Code Playgroud)
类DataExtractorConfig
namespace App.Configuration
{
[SettingProperty(Name: "dataExtractorSettings")]
public class DataExtractorConfig : ConfigurationSection
{
[ConfigurationProperty("executionLog")]
public LogConfig ExecutionLog
{
get
{
if (base["executionLog"] != null)
{
return (LogConfig)base["executionLog"];
}
else
{ …Run Code Online (Sandbox Code Playgroud) .net c# configurationmanager app-config custom-configuration
是否可以在Saltsack中执行相同的操作,但是通过嵌入式功能(没有PowerShell解决方法)?
installation:
cmd.run:
- name: ./installation_script
wait for installation:
cmd.run:
- name: powershell -command "Start-Sleep 10"
- unless: powershell -command "Test-Path @('/path/to/file/to/appear')"
Run Code Online (Sandbox Code Playgroud) 尝试从 puppet 代理节点运行以下命令时:
puppet agent --test --verbose
Run Code Online (Sandbox Code Playgroud)
提示以下错误
错误:证书验证失败 [无法获得 CN=puppetmaster.example.com 的本地颁发者证书]
我已经在 /etc/hosts 文件中向我的主机添加了 FQDN。
.net ×4
c# ×4
app-config ×3
mef ×1
powershell ×1
puppet ×1
salt-stack ×1
sql-server ×1
vb.net ×1