我试图在Teamcity服务器上使用MSBUILD更改web.config中的connectionString.以前我在调用它的目标中使用了该属性:
<PropertyGroup>
<UpdateWebConfigCode>
<![CDATA[
public static void ScriptMain()
{
XmlDocument wcXml = new XmlDocument();
wcXml.Load(@"TCM.MVC.UI\Web.config");
XmlElement root = wcXml.DocumentElement;
XmlNodeList connList = root.SelectNodes("//connectionStrings/add");
XmlElement elem;
foreach (XmlNode node in connList)
{
elem = (XmlElement)node;
switch (elem.GetAttribute("name"))
{
case "TCMBaseConnectionString":
elem.SetAttribute("connectionString", "Data Source=server-name;Initial Catalog=TCMCentral;User ID=user;Password=something");
break;
}
}
wcXml.Save(@"TCM.MVC.UI\Web.config");
}
]]>
</UpdateWebConfigCode>
Run Code Online (Sandbox Code Playgroud)
然后我会在目标中调用它:
<Target Name="UpdateWebConfig">
<Script Language="C#" Code="$(UpdateWebConfigCode)" Imports="System.Xml" />
</Target>
Run Code Online (Sandbox Code Playgroud)
但这不断引发错误.我意识到这可能有点过时但无法找到任何替代它....任何建议?
我最终使用了MSBuildCommunityTasks XmlUpdate属性.以下是我的目标:
<Target Name="UpdateWebConfig">
<XmlUpdate XmlFileName="C:\TCM.NET\Current\TCM.MVC.UI\web.config" XPath="configuration/connectionStrings/add[@name='TCMBaseConnectionString']/@connectionString" Value="Data Source=server-name;Initial Catalog=TCMCentral;User ID=user;Password=something" />
</Target>
Run Code Online (Sandbox Code Playgroud)
这对我很有用.
| 归档时间: |
|
| 查看次数: |
1833 次 |
| 最近记录: |