我编写了一个自定义 MSBuild 任务来从 MSSQL 存储过程生成模型代码。我想为我的任务使用与应用程序相同的配置来连接到数据库。我创建了一个看起来像这样的配置部分
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="CoreDataConnections" type="CoreData.ConfigHandler, CoreData"></section>
</configSections>
<CoreDataConnections>
<Connection Name="BillingDB" ConnectionString="Data Source=SERVER0;Initial Catalog=DB0;persist security info=False;user id=user;password=password;packet size=4096"/>
<Connection Name="ValidationDB" ConnectionString="data source=SERVER1;initial catalog=DB1;persist security info=False;user id=user;password=password;packet size=4096"/>
</CoreDataConnections>
</configuration>
并像这样从我的应用程序整天访问它:
Dictionary<string,string> Connections = (Dictionary<string,string>)ConfigurationSettings.GetConfig("CoreDataConnections");
但是,我的自定义任务看不到它,并GetConfig
返回null
.
我应该在这里做什么?我宁愿不必重写我的自定义配置部分处理程序,并且更感兴趣的是,例如,在 MSBuild 属性中指定 app.config 文件,但我会尽其所能。