-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCopyAssemblyFiles.cs
More file actions
62 lines (53 loc) · 1.86 KB
/
Copy pathCopyAssemblyFiles.cs
File metadata and controls
62 lines (53 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// ReSharper disable UnusedAutoPropertyAccessor.Global
using System;
using System.IO;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
namespace NETMetaCoder.MSBuild
{
/// <summary>
/// An MSBuild task that copies assembly files to a given destination, to help with bundling this library's
/// resources.
/// </summary>
public sealed class CopyAssemblyFiles : Task
{
/// <summary>
/// The assembly files to copy.
/// </summary>
[Required]
public ITaskItem[] AssemblyFilePaths { get; set; }
/// <summary>
/// The destination directory where the assembly files are to be copied.
/// </summary>
[Required]
public string DestinationDirectory { get; set; }
/// <inheritdoc cref="Task.Execute"/>
public override bool Execute()
{
try
{
foreach (var assemblyFilePath in AssemblyFilePaths)
{
if (!File.Exists(assemblyFilePath.ItemSpec))
{
throw new ArgumentException($"\"{assemblyFilePath.ItemSpec}\" is not a file.");
}
var destinationFilePath =
Path.Combine(DestinationDirectory, Path.GetFileName(assemblyFilePath.ItemSpec));
if (File.Exists(destinationFilePath))
{
File.Delete(destinationFilePath);
}
// ReSharper disable once AssignNullToNotNullAttribute
File.Copy(assemblyFilePath.ItemSpec, destinationFilePath);
}
return true;
}
catch (Exception exception)
{
Log.LogErrorFromException(exception, true);
return false;
}
}
}
}