-
-
Save natemcmaster/1622db9d42156a306d16da8b1dafc795 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.IO; | |
using Microsoft.Build.Framework; | |
using Microsoft.Build.Utilities; | |
namespace RepoTasks | |
{ | |
/// <summary> | |
/// Because MSBuild can't copy files that exceed MAX_PATH and | |
/// https://github.com/Microsoft/msbuild/issues/53 has been open since 2015. | |
/// </summary> | |
public class StupidCopy : Task | |
{ | |
public string[] SourceFiles { get; set; } | |
public string[] DestinationFiles { get; set; } | |
public string DestinationFolder { get; set; } | |
public override bool Execute() | |
{ | |
if (SourceFiles == null || SourceFiles.Length == 0) | |
{ | |
return true; | |
} | |
if (!string.IsNullOrEmpty(DestinationFolder)) | |
{ | |
Directory.CreateDirectory(DestinationFolder); | |
foreach (var file in SourceFiles) | |
{ | |
string destFileName = Path.Combine(DestinationFolder, Path.GetFileName(file)); | |
Log.LogMessage("Copying {0} to {1}", file, destFileName); | |
File.Copy(file, destFileName, overwrite: true); | |
} | |
} | |
else | |
{ | |
if (SourceFiles.Length != DestinationFiles.Length) | |
{ | |
Log.LogError("The number of sources and destinations does not match"); | |
return false; | |
} | |
for (int i = 0; i < SourceFiles.Length; i++) | |
{ | |
Directory.CreateDirectory(Path.GetDirectoryName(DestinationFiles[i])); | |
Log.LogMessage("Copying {0} to {1}", SourceFiles[i], DestinationFiles[i]); | |
File.Copy(SourceFiles[i], DestinationFiles[i], overwrite: true); | |
} | |
} | |
return !Log.HasLoggedErrors; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment