Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix pack issue with readmes and snupkgs #4268

Merged
merged 6 commits into from
Sep 21, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -859,14 +859,14 @@ private static void ValidateFileFrameworks(IEnumerable<IPackageFile> files)
}

/// <summary>
/// Validate that the readme file is of the correct size/type and can be opened properly.
/// Validate that the readme file is of the correct size/type and can be opened properly except for Symbol packages.
/// </summary>
/// <param name="files">Files resolved from the file entries in the nuspec</param>
/// <param name="readmePath">readmepath found in the .nuspec</param>
/// <exception cref="PackagingException">When a validation rule is not met</exception>
private void ValidateReadmeFile(IEnumerable<IPackageFile> files, string readmePath)
{
if (!string.IsNullOrEmpty(readmePath))
if (!PackageTypes.Contains(PackageType.SymbolsPackage) && !string.IsNullOrEmpty(readmePath))
{
// Validate readme extension
var extension = Path.GetExtension(readmePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public static XElement ToXElement(this ManifestMetadata metadata, XNamespace ns,
}
}
AddElementIfNotNull(elem, ns, "licenseUrl", licenseUrlToWrite);

AddElementIfNotNull(elem, ns, "icon", metadata.Icon);
AddElementIfNotNull(elem, ns, "readme", metadata.Readme);
}
AddElementIfNotNull(elem, ns, "projectUrl", metadata.ProjectUrl);
AddElementIfNotNull(elem, ns, "iconUrl", metadata.IconUrl);
Expand All @@ -80,7 +80,6 @@ public static XElement ToXElement(this ManifestMetadata metadata, XNamespace ns,
AddElementIfNotNull(elem, ns, "copyright", metadata.Copyright);
AddElementIfNotNull(elem, ns, "language", metadata.Language);
AddElementIfNotNull(elem, ns, "tags", metadata.Tags);
AddElementIfNotNull(elem, ns, "readme", metadata.Readme);
if (metadata.Serviceable)
{
elem.Add(new XElement(ns + "serviceable", metadata.Serviceable));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5440,6 +5440,56 @@ public void PackCommand_PackageReadmeFile_ReadmeFileIsEmpty_Fails()
}
}

[PlatformFact(Platform.Windows)]
public void PackCommand_PackageReadmeFile_BasicFunc_WithSymbol_Succeeds()
{
// Arrange
TestDirectoryBuilder testDirBuilder = TestDirectoryBuilder.Create();
ProjectFileBuilder projectBuilder = ProjectFileBuilder.Create();

testDirBuilder
.WithFile("test\\readme.md", 10)
.WithFile("test\\folder\\notes.txt", 10)
.WithFile("test\\folder\\nested\\content.txt", 10)
.WithFile("test\\folder\\nested\\sample.txt", 10)
.WithFile("test\\icon.jpg", 10)
.WithFile("test\\other\\files.txt", 10)
.WithFile("test\\utils\\sources.txt", 10);

projectBuilder
.WithProjectName("test")
.WithProperty("IncludeSymbols", "true")
.WithProperty("SymbolPackageFormat", "snupkg")
.WithPackageReadmeFile("readme.md")
.WithItem(itemType: "None", itemPath: "readme.md", packagePath: string.Empty, pack: "true")
.WithItem(itemType: "None", itemPath: "other\\files.txt", packagePath: null, pack: "true")
.WithItem(itemType: "None", itemPath: "folder\\**", packagePath: "media", pack: "true")
.WithItem(itemType: "None", itemPath: "utils\\*", packagePath: "utils", pack: "true");

// Act
using (TestDirectory srcDir = msbuildFixture.Build(testDirBuilder))
{
projectBuilder.Build(msbuildFixture, srcDir.Path);
msbuildFixture.PackProject(projectBuilder.ProjectFolder, projectBuilder.ProjectName, string.Empty);

// Assert
// Validate embedded readme in package
ValidatePackReadme(projectBuilder);

// Validate that other content is also included
string nupkgPath = Path.Combine(projectBuilder.ProjectFolder, "bin", "Debug", $"{projectBuilder.ProjectName}.1.0.0.nupkg");
using (var nupkgReader = new PackageArchiveReader(nupkgPath))
{
Assert.NotNull(nupkgReader.GetEntry("content/other/files.txt"));
Assert.NotNull(nupkgReader.GetEntry("utils/sources.txt"));
Assert.NotNull(nupkgReader.GetEntry("media/nested/sample.txt"));
}

string snupkgPath = Path.Combine(projectBuilder.ProjectFolder, "bin", "Debug", $"{projectBuilder.ProjectName}.1.0.0.snupkg");
Assert.True(File.Exists(snupkgPath), "No snupkg was produced");
}
}

private void ValidatePackReadme(ProjectFileBuilder projectBuilder)
{
Assert.True(File.Exists(projectBuilder.ProjectFilePath), "No project was produced");
Expand Down