我目前正在研究 TFS 实现的构建定义。我几乎所有东西都在工作,除了我无法让最后一部分工作。下面是我目前正在实现的 CodeActivity 类。
在工作流程图中,我使用默认associatedChangesets
变量作为 InArgument。
以下代码有效并创建文件夹Database
,但AssociatedChangesets
似乎不包含任何项目。
public sealed class CreateDatabaseDrop : CodeActivity
{
public InArgument<Workspace> Workspace { get; set; }
public InArgument<string> DropLocation { get; set; }
public InArgument<IList<Changeset>> AssociatedChangesets { get; set; }
// If your activity returns a value, derive from CodeActivity<TResult>
// and return the value from the Execute method.
Workspace workspace;
string dropLocation;
IList<Changeset> associatedChangesets;
protected override void Execute(CodeActivityContext context)
{
List<string> filesChanged = new List<string>();
workspace = context.GetValue(this.Workspace);
dropLocation = context.GetValue(this.DropLocation);
associatedChangesets = context.GetValue(this.AssociatedChangesets);
if (!Directory.Exists(dropLocation + @"\database\"))
Directory.CreateDirectory(dropLocation + @"\database\");
foreach (var c in associatedChangesets.OrderBy(x => x.CreationDate))
{
foreach (var change in c.Changes)
{
context.WriteBuildMessage(change.Item.ServerItem);
}
foreach (var change in c.Changes.Where(x => x.Item.ItemType == ItemType.File && x.Item.ServerItem.Split('/').Last().ToLower().Contains(".sql")))
{
string fileName = change.Item.ServerItem.Split('/').Last();
context.WriteBuildMessage(string.Format("SQL File Found: {0}", change.Item.ServerItem));
WorkingFolder wf = workspace.GetWorkingFolderForServerItem(change.Item.ServerItem);
string copyFrom = Path.Combine(wf.LocalItem, fileName),
copyTo = dropLocation + @"\database\" + fileName;
context.WriteBuildMessage(string.Format("Copying {0} to {1}", fileName, copyTo));
File.Copy(copyFrom, copyTo, true);
}
}
}
自上次构建完成以来,任何人都可以帮助我弄清楚如何获得所有 SQL 更改。