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
)来执行转换:
[BuildActivity(HostEnvironmentOption.All)]
public sealed class WebConfigTransform : CodeActivity
{
#region Public Properties
[RequiredArgument]
public InArgument<string> BinariesLocation { get; set; }
#endregion
#region Overrides of CodeActivity
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。当您将其添加到工作流中时,请右键单击活动,然后转到属性,并将“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
}