public override bool Execute() { Log.LogMessage(MessageImportance.Low, $"Task {nameof (CreateThirdPartyNotices)}"); Log.LogMessage(MessageImportance.Low, $" {nameof (FileName)}: {FileName}"); var notices = Notices .Distinct(NoticesComparer) .OrderBy(e => e.ItemSpec, StringComparer.OrdinalIgnoreCase) .ToList(); var contents = new StringWriter(); WriteHeader(contents); int countWidth = notices.Count.ToString().Length + 1; var countFormat = "{0,-" + countWidth + "}"; for (int i = 0; i < notices.Count; ++i) { var count = string.Format(countFormat, (i + 1) + "."); var notice = notices [i]; var version = notice.GetMetadata("Version"); if (!string.IsNullOrEmpty(version)) { version = $" version {version}"; } contents.WriteLine($"{count} {notice.ItemSpec}{version} ({notice.GetMetadata ("SourceUrl")})"); } contents.WriteLine(); foreach (var notice in notices) { contents.WriteLine(); contents.WriteLine($"%% {notice.ItemSpec} NOTICES AND INFORMATION BEGIN HERE"); contents.WriteLine("========================================="); var licenseText = notice.GetMetadata("LicenseText"); WriteLicense(contents, licenseText); var licenseFile = notice.GetMetadata("LicenseFile"); WriteLicenseFromFile(contents, licenseFile); contents.WriteLine("========================================="); contents.WriteLine($"END OF {notice.ItemSpec} NOTICES AND INFORMATION"); } Directory.CreateDirectory(Path.GetDirectoryName(FileName.ItemSpec)); var current = File.Exists(FileName.ItemSpec) ? File.ReadAllText(FileName.ItemSpec) : null; if (current != contents.ToString()) { File.WriteAllText(FileName.ItemSpec, contents.ToString()); } return(!Log.HasLoggedErrors); }