Skip to content

Commit

Permalink
check contentFiles and different alias inference (#3686)
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat authored Sep 29, 2020
1 parent 44f1096 commit ba87e7e
Showing 1 changed file with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ public void PackTaskLogic_InfersFrameworkPlatformVersionFromAlias()
// Arrange
using (var testDir = TestDirectory.Create())
{
var tc = new TestContext(testDir, "net5.0-windows");
var tc = new TestContext(testDir, "net50-windows");

var assetsJson = @"{
""version"": 3,
Expand All @@ -530,7 +530,7 @@ public void PackTaskLogic_InfersFrameworkPlatformVersionFromAlias()
],
""originalTargetFrameworks"": [
""net5.0"",
""net5.0-windows""
""net50-windows""
],
""sources"": {
""https://api.nuget.org/v3/index.json"": {},
Expand All @@ -541,7 +541,7 @@ public void PackTaskLogic_InfersFrameworkPlatformVersionFromAlias()
""projectReferences"": {}
},
""net5.0-windows7.0"": {
""targetAlias"": ""net5.0-windows"",
""targetAlias"": ""net50-windows"",
""projectReferences"": {}
}
},
Expand Down Expand Up @@ -571,7 +571,7 @@ public void PackTaskLogic_InfersFrameworkPlatformVersionFromAlias()
},
},
""net5.0-windows7.0"": {
""targetAlias"": ""net5.0-windows"",
""targetAlias"": ""net50-windows"",
""imports"": [
""net461"",
""net462"",
Expand All @@ -593,9 +593,19 @@ public void PackTaskLogic_InfersFrameworkPlatformVersionFromAlias()
}";
File.WriteAllText(Path.Combine(testDir, "obj", "project.assets.json"), assetsJson);

// var msbuildItem = tc.AddContentToProject("", "abc.txt", "hello world");
// tc.Request.PackageFiles = new MSBuildItem[] { msbuildItem };
// tc.Request.ContentTargetFolders = new string[] { "content" };
tc.Request.PackageFiles = new MSBuildItem[] {
tc.AddContentToProject("", "abc.txt", "hello world", new Dictionary<string, string>()
{
{"BuildAction", "Content"}
}),
tc.AddContentToProject("", "def.txt", "hello world", new Dictionary<string, string>()
{
{"BuildAction", "None"},
{"Pack", "true" },
{"PackagePath", "contentFiles\\net5.0-windows" }
})
};
tc.Request.ContentTargetFolders = new string[] { "content", "contentFiles" };

// Act
tc.BuildPackage();
Expand All @@ -610,6 +620,23 @@ public void PackTaskLogic_InfersFrameworkPlatformVersionFromAlias()
Assert.Equal(1, libItems.Count);
Assert.Equal(NuGetFramework.Parse("net5.0-windows7.0"), libItems[0].TargetFramework);
Assert.Equal(new[] { "lib/net5.0-windows7.0/a.dll" }, libItems[0].Items);

var contentFiles = nuspecReader.GetContentFiles().ToList();

Assert.Equal(contentFiles.Count, 2);
Assert.Equal(contentFiles[0].BuildAction, "Content", StringComparer.Ordinal);
Assert.Equal(contentFiles[0].Include, "any/net5.0-windows7.0/abc.txt", StringComparer.Ordinal);
Assert.Equal(contentFiles[1].BuildAction, "None", StringComparer.Ordinal);
Assert.Equal(contentFiles[1].Include, "net5.0-windows/def.txt", StringComparer.Ordinal);

// Validate the content items
var contentItems = nupkgReader.GetFiles("content").ToList();
var contentFileItems = nupkgReader.GetFiles("contentFiles").ToList();
Assert.Equal(contentItems.Count, 1);
Assert.Equal(contentFileItems.Count, 2);
Assert.Contains("content/abc.txt", contentItems, StringComparer.Ordinal);
Assert.Contains("contentFiles/any/net5.0-windows7.0/abc.txt", contentFileItems, StringComparer.Ordinal);
Assert.Contains("contentFiles/net5.0-windows/def.txt", contentFileItems, StringComparer.Ordinal);
}
}
}
Expand Down

0 comments on commit ba87e7e

Please sign in to comment.