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的工作流程。當您將其添加到工作流程中時,右鍵單擊該活動,然後轉到屬性,然後將「DropLocation」(VB表達式)粘貼到屬性「BinaryLocation」中。注意:您需要創建一個BuildEngineStub類實現IBuildEngine接口以使用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
}
感謝您的支持。在這個階段我有點困惑; XML的這個片段放在哪裏?任何其他修改的TFS構建定義,以適應? –
你對MSBuild的熟悉程度如何?您可以將此目標放置在您的構建定義中,也可以從「BeforeDropBuild」目標中調用它。 – Danny
-1:他爲什麼要用這個?他正在使用TFS 2010. –