TFS Team Build 2010 不会自动转换您的 Web.configs。您需要在构建过程模板中添加自定义工作流活动来完成此操作。
Edwald Hofman 有一篇很好的博客解释了如何修改 TFS 2010 构建过程模板,所以我不会在这里深入讨论。
http://www.ewaldhofman.nl/post/2010/04/29/Customize-Team-Build-2010-e28093-Part-4-Create-your-own-activity.aspx
在您弄清楚如何将自定义活动添加到您的构建过程模板后,将以下活动添加到您的工作流程中,我在“将文件拖放到放置位置”之后添加了该活动。它利用 Microsoft.Web.Publishing.Tasks 程序集(位于:C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web)来执行转换:
/// <summary>
/// Transforms configuration files using TransformXml
/// </summary>
[BuildActivity(HostEnvironmentOption.All)]
public sealed class WebConfigTransform : CodeActivity
{
#region Public Properties
/// <summary>
/// The binaries folder
/// </summary>
[RequiredArgument]
public InArgument<string> BinariesLocation { get; set; }
#endregion
#region Overrides of CodeActivity
/// <summary>
/// When implemented in a derived class, performs the execution of the activity.
/// </summary>
/// <param name="context">The execution context under which the activity executes.</param>
protected override void Execute(CodeActivityContext context)
{
var binariesFolder = context.GetValue(BinariesLocation);
foreach (var sourceFolder in Directory.GetDirectories(Path.Combine(binariesFolder, "_PublishedWebsites")))
{
var sourceFile = Path.Combine(sourceFolder, "Web.config");
if (File.Exists(sourceFile))
{
var filesToTransform = Directory.GetFiles(sourceFolder, "Web.*.config");
foreach (var fileToTransform in filesToTransform)
{
var tempSourceFile = Path.GetTempFileName();
var tempTransformFile = Path.GetTempFileName();
File.Copy(sourceFile, tempSourceFile, true);
File.Copy(fileToTransform, tempTransformFile, true);
var transformation = new TransformXml
{
BuildEngine = new BuildEngineStub(),
Source = tempSourceFile,
Transform = tempTransformFile,
Destination = fileToTransform
};
transformation.Execute();
}
}
}
}
#endregion
}
您需要将工作流程中的放置位置传递给它。当您将其添加到工作流时,右键单击活动,然后转到属性,并将“DropLocation”(VB 表达式)粘贴到属性“BinaryLocation”中
注意:您需要创建一个实现 IBuildEngine 接口的 BuildEngineStub 类才能使用 MSBuild 任务。这是我用的
public class BuildEngineStub : IBuildEngine
{
#region IBuildEngine Members
public bool BuildProjectFile(string projectFileName, string[] targetNames,
IDictionary globalProperties,
IDictionary targetOutputs)
{
throw new NotImplementedException();
}
public int ColumnNumberOfTaskNode
{
get { return 0; }
}
public bool ContinueOnError
{
get { return false; }
}
public int LineNumberOfTaskNode
{
get { return 0; }
}
public string ProjectFileOfTaskNode
{
get { return ""; }
}
public void LogCustomEvent(CustomBuildEventArgs e)
{
Console.WriteLine("Custom: {0}", e.Message);
}
public void LogErrorEvent(BuildErrorEventArgs e)
{
Console.WriteLine("Error: {0}", e.Message);
}
public void LogMessageEvent(BuildMessageEventArgs e)
{
Console.WriteLine("Message: {0}", e.Message);
}
public void LogWarningEvent(BuildWarningEventArgs e)
{
Console.WriteLine("Warning: {0}", e.Message);
}
#endregion
}