我想在TeamCity服务器上使用MSBUILD在我的web.config中更改connectionString。以前我有使用属性在目标调用此:更改带有msbuild的connectionstrings
<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>
然后,我会叫它目标:
<Target Name="UpdateWebConfig">
<Script Language="C#" Code="$(UpdateWebConfigCode)" Imports="System.Xml" />
</Target>
但这种不断抛出一个错误。我意识到这可能是有点过时,但无法找到任何东西来取代它....任何建议?
杰米,感谢您的帮助。我最终在MSBuildCommunityTasks中使用了XmlUpdate属性。请参阅下面的答案。再次感谢。 Andrew – abarr 2010-07-06 13:26:32