我想在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