|
6 | 6 | using Microsoft.Build.UnitTests.Common; |
7 | 7 | using Microsoft.Build.Utilities.ProjectCreation; |
8 | 8 | using Shouldly; |
| 9 | +using System; |
9 | 10 | using System.Collections.Generic; |
10 | 11 | using System.IO; |
11 | 12 | using System.Linq; |
@@ -139,6 +140,60 @@ public void DefaultArtifactsUseOutputPath(bool appendTargetFrameworkToOutputPath |
139 | 140 | ignoreOrder: true); |
140 | 141 | } |
141 | 142 |
|
| 143 | + [Fact] |
| 144 | + public void ArtifactsShouldTrimDestinationFolder() |
| 145 | + { |
| 146 | + DirectoryInfo baseOutputPath = CreateFiles( |
| 147 | + Path.Combine("bin", "Debug"), |
| 148 | + "foo.exe", |
| 149 | + "foo.pdb", |
| 150 | + "foo.exe.config", |
| 151 | + "bar.dll", |
| 152 | + "bar.pdb", |
| 153 | + "bar.cs"); |
| 154 | + |
| 155 | + CreateFiles( |
| 156 | + Path.Combine(baseOutputPath.FullName, "ref"), |
| 157 | + "bar.dll"); |
| 158 | + |
| 159 | + DirectoryInfo artifactsPath = new DirectoryInfo(Path.Combine(TestRootPath, "artifacts")); |
| 160 | + DirectoryInfo artifactsPath2 = new DirectoryInfo(Path.Combine(TestRootPath, "artifacts2")); |
| 161 | + string artifactPathes = string.Concat(artifactsPath.FullName, ";", Environment.NewLine, artifactsPath2.FullName); |
| 162 | + |
| 163 | + string outputPath = $"{Path.Combine("bin", "Debug")}{Path.DirectorySeparatorChar}"; |
| 164 | + |
| 165 | + ProjectCreator.Templates.ProjectWithArtifacts( |
| 166 | + outputPath: outputPath, |
| 167 | + appendTargetFrameworkToOutputPath: false, |
| 168 | + artifactsPath: artifactPathes) |
| 169 | + .TryGetItems("Artifact", out IReadOnlyCollection<ProjectItem> artifactItems) |
| 170 | + .TryGetPropertyValue("DefaultArtifactsSource", out string defaultArtifactsSource) |
| 171 | + .TryBuild(out bool result, out BuildOutput buildOutput); |
| 172 | + |
| 173 | + result.ShouldBeTrue(buildOutput.GetConsoleLog()); |
| 174 | + |
| 175 | + defaultArtifactsSource.ShouldBe(outputPath); |
| 176 | + |
| 177 | + ProjectItem artifactItem = artifactItems.ShouldHaveSingleItem(); |
| 178 | + |
| 179 | + artifactItem.EvaluatedInclude.ShouldBe(defaultArtifactsSource); |
| 180 | + artifactItem.GetMetadataValue("DestinationFolder").ShouldBe(artifactPathes); |
| 181 | + |
| 182 | + foreach (DirectoryInfo d in new[] { artifactsPath, artifactsPath2 }) |
| 183 | + { |
| 184 | + d.GetFiles("*", SearchOption.AllDirectories) |
| 185 | + .Select(i => i.FullName) |
| 186 | + .ShouldBe( |
| 187 | + new[] |
| 188 | + { |
| 189 | + "bar.dll", |
| 190 | + "foo.exe", |
| 191 | + "foo.exe.config", |
| 192 | + }.Select(i => Path.Combine(d.FullName, i)), |
| 193 | + ignoreOrder: true); |
| 194 | + } |
| 195 | + } |
| 196 | + |
142 | 197 | [Theory] |
143 | 198 | [InlineData(null)] |
144 | 199 | [InlineData(true)] |
|
0 commit comments