Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To do this in WorkFlow, you have to create a Custom Activity. There's quite a good article about it <a href="http://blogs.msdn.com/b/jimlamb/archive/2010/02/12/how-to-create-a-custom-workflow-activity-for-tfs-build-2010.aspx" rel="nofollow">here</a></p> <p>For this specific activity you need to create and Activity project (change it from <em>.Net 4 Client profile</em> to <em>.Net 4</em>) and reference <strong>Microsoft.Build.Framework</strong> and <strong>Microsoft.Build.Utilities.v4.0</strong> from the GAC and then <strong>Microsoft.Web.Publishing.Tasks</strong> from <em>%programfiles%\msbuild\Microsoft\VisualStudio\v10.0\WebApplications</em> (%programfiles(x86)% if you're on a 64bit system). </p> <p>When that's done, you add these two classes:</p> <p>First, there's a stub:</p> <pre><code>internal class BuildEngineStub : IBuildEngine { public bool BuildProjectFile(string projectFileName, string[] targetNames, System.Collections.IDictionary globalProperties, System.Collections.IDictionary targetOutputs) { throw new NotImplementedException(); } public int ColumnNumberOfTaskNode { get { throw new NotImplementedException(); } } public bool ContinueOnError { get { throw new NotImplementedException(); } } public int LineNumberOfTaskNode { get { throw new NotImplementedException(); } } public void LogCustomEvent(CustomBuildEventArgs e) { } public void LogErrorEvent(BuildErrorEventArgs e) { } public void LogMessageEvent(BuildMessageEventArgs e) { } public void LogWarningEvent(BuildWarningEventArgs e) { } public string ProjectFileOfTaskNode { get { throw new NotImplementedException(); } } } </code></pre> <p>Then theres the activity class it self:</p> <pre><code>[BuildActivity(HostEnvironmentOption.Agent)] public sealed class WebConfigTransform : CodeActivity { private const string WEB_CONFIG = "Web.config"; private const string WEB_CONFIG_TRANSFORM_FORMAT = "Web.{0}.config"; private IBuildEngine _buildEngine { get { return new BuildEngineStub(); } } [RequiredArgument] public InArgument&lt;string&gt; TransformationName { get; set; } [RequiredArgument] public InArgument&lt;string&gt; SourceFolder { get; set; } [RequiredArgument] public InArgument&lt;string&gt; DestinationFolder { get; set; } protected override void Execute(CodeActivityContext context) { var transformationName = context.GetValue(this.TransformationName); var sourceFolder = context.GetValue(this.SourceFolder); var destinationFolder = context.GetValue(this.DestinationFolder); var source = Path.Combine(sourceFolder, WEB_CONFIG); var destination = Path.Combine(destinationFolder, WEB_CONFIG); var destinationbackup = string.Format("{0}.bak", destination); var transform = Path.Combine(sourceFolder, string.Format(WEB_CONFIG_TRANSFORM_FORMAT, transformationName)); if(!File.Exists(source)) throw new ArgumentException("Web.config file doesn't exist in SourceFolder"); if (!File.Exists(transform)) throw new ArgumentException("Web.config transformation doesn't exist in SourceFolder"); if (File.Exists(destination)) { File.Copy(destination, destinationbackup); File.Delete(destination); } var transformation = new TransformXml(); transformation.Source = new TaskItem(source); transformation.Destination = new TaskItem(destination); transformation.Transform = new TaskItem(transform); transformation.BuildEngine = _buildEngine; if (transformation.Execute()) { File.Delete(destinationbackup); } else { File.Copy(destinationbackup, destination); File.Delete(destinationbackup); } } } </code></pre> <p>The reason for the <strong>BuildEngineStub</strong> is that the <strong>TransformXml</strong> class uses it to do logging.</p> <p>The only thing you need to be careful about is that the <strong>TransformXml.Execute</strong> function locks the source configuration file until the build process is finished.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload