Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions src/Artifacts.UnitTests/ArtifactsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.Build.UnitTests.Common;
using Microsoft.Build.Utilities.ProjectCreation;
using Shouldly;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -139,6 +140,60 @@ public void DefaultArtifactsUseOutputPath(bool appendTargetFrameworkToOutputPath
ignoreOrder: true);
}

[Fact]
public void ArtifactsShouldTrimDestinationFolder()
{
DirectoryInfo baseOutputPath = CreateFiles(
Path.Combine("bin", "Debug"),
"foo.exe",
"foo.pdb",
"foo.exe.config",
"bar.dll",
"bar.pdb",
"bar.cs");

CreateFiles(
Path.Combine(baseOutputPath.FullName, "ref"),
"bar.dll");

DirectoryInfo artifactsPath = new DirectoryInfo(Path.Combine(TestRootPath, "artifacts"));
DirectoryInfo artifactsPath2 = new DirectoryInfo(Path.Combine(TestRootPath, "artifacts2"));
string artifactPathes = string.Concat(artifactsPath.FullName, ";", Environment.NewLine, artifactsPath2.FullName);

string outputPath = $"{Path.Combine("bin", "Debug")}{Path.DirectorySeparatorChar}";

ProjectCreator.Templates.ProjectWithArtifacts(
outputPath: outputPath,
appendTargetFrameworkToOutputPath: false,
artifactsPath: artifactPathes)
.TryGetItems("Artifact", out IReadOnlyCollection<ProjectItem> artifactItems)
.TryGetPropertyValue("DefaultArtifactsSource", out string defaultArtifactsSource)
.TryBuild(out bool result, out BuildOutput buildOutput);

result.ShouldBeTrue(buildOutput.GetConsoleLog());

defaultArtifactsSource.ShouldBe(outputPath);

ProjectItem artifactItem = artifactItems.ShouldHaveSingleItem();

artifactItem.EvaluatedInclude.ShouldBe(defaultArtifactsSource);
artifactItem.GetMetadataValue("DestinationFolder").ShouldBe(artifactPathes);

foreach (DirectoryInfo d in new[] { artifactsPath, artifactsPath2 })
{
d.GetFiles("*", SearchOption.AllDirectories)
.Select(i => i.FullName)
.ShouldBe(
new[]
{
"bar.dll",
"foo.exe",
"foo.exe.config",
}.Select(i => Path.Combine(d.FullName, i)),
ignoreOrder: true);
}
}

[Theory]
[InlineData(null)]
[InlineData(true)]
Expand Down
3 changes: 2 additions & 1 deletion src/Artifacts/Tasks/RobocopyMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

Expand Down Expand Up @@ -98,7 +99,7 @@ public static bool TryParse(ITaskItem item, TaskLoggingHelper log, Func<string,
OnlyNewer = item.GetMetadataBoolean(nameof(OnlyNewer), defaultValue: false),
};

foreach (string destination in item.GetMetadata("DestinationFolder").Split(DestinationSplitter, StringSplitOptions.RemoveEmptyEntries))
foreach (string destination in item.GetMetadata("DestinationFolder").Split(DestinationSplitter, StringSplitOptions.RemoveEmptyEntries).Select(d => d.Trim()))
{
if (destination.StartsWith(@"\") && !destination.StartsWith(@"\\"))
{
Expand Down