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

Fixes the package testing for runtime packages using the dotnet pack task #7360

Merged
merged 1 commit into from
May 8, 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 @@ -26,7 +26,6 @@ public override bool Execute()
{
bool result = true;
List<ITaskItem> testProjects = new List<ITaskItem>();

try
{
Initialize();
Expand All @@ -36,7 +35,7 @@ public override bool Execute()
List<NuGetFramework> packageTargetFrameworks = package.PackageAssets.Where(t => t.AssetType != AssetType.RuntimeAsset).Select(t => t.TargetFramework).Distinct().ToList();

List<NuGetFramework> frameworksToTest = GetTestFrameworks(packageTargetFrameworks);
testProjects.AddRange(CreateItemFromTestFramework(package.Title, package.Version, frameworksToTest, GetRidsFromPackage(package)));
testProjects.AddRange(CreateItemFromTestFramework(package.PackageId, package.Version, frameworksToTest, GetRidsFromPackage(package)));
}

// Removing empty items.
Expand Down Expand Up @@ -113,12 +112,12 @@ public static void Initialize()
}
}

public List<ITaskItem> CreateItemFromTestFramework(string title, string version, List<NuGetFramework> testFrameworks, string rids)
public List<ITaskItem> CreateItemFromTestFramework(string packageId, string version, List<NuGetFramework> testFrameworks, string rids)
{
List<ITaskItem> testprojects = new List<ITaskItem>();
foreach (var framework in testFrameworks)
{
var supportedPackage = new TaskItem(title);
var supportedPackage = new TaskItem(packageId);
supportedPackage.SetMetadata("Version", version);
supportedPackage.SetMetadata("TargetFramework", framework.ToString());
supportedPackage.SetMetadata("TargetFrameworkShort", framework.GetShortFolderName());
Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.DotNet.PackageValidation/NupkgParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static Package CreatePackageObject(string packagePath)
PackageArchiveReader nupkgReader = new PackageArchiveReader(packagePath);
NuspecReader nuspecReader = nupkgReader.NuspecReader;

string title = nuspecReader.GetTitle();
string packageId = nuspecReader.GetId();
string version = nuspecReader.GetVersion().ToString();
IEnumerable<PackageDependencyGroup> dependencyGroups = nuspecReader.GetDependencyGroups();

Expand All @@ -28,13 +28,13 @@ public static Package CreatePackageObject(string packagePath)
packageDependencies.Add(item.TargetFramework, item.Packages.ToList());
}

var files = nupkgReader.GetFiles().ToList().Where(t => t.EndsWith(".dll")).Where(t => t.Contains(title + ".dll"));
var files = nupkgReader.GetFiles().ToList().Where(t => t.EndsWith(".dll")).Where(t => t.Contains(packageId + ".dll"));
foreach (var file in files)
{
packageAssets.Add(ExtractAssetFromFile(file));
}

return new Package(title, version, packageAssets, packageDependencies);
return new Package(packageId, version, packageAssets, packageDependencies);
}

public static PackageAsset ExtractAssetFromFile(string filePath)
Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.DotNet.PackageValidation/Package.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ namespace Microsoft.DotNet.PackageValidation
public class Package
{
public List<PackageAsset> PackageAssets { get; set; }
public string Title { get; set; }
public string PackageId { get; set; }
public string Version { get; set; }
public Dictionary<NuGetFramework, List<PackageDependency>> PackageDependencies { get; set; }
public Package(string title, string version, List<PackageAsset> packageAssets, Dictionary<NuGetFramework, List<PackageDependency>> packageDependencies)
public Package(string packageId, string version, List<PackageAsset> packageAssets, Dictionary<NuGetFramework, List<PackageDependency>> packageDependencies)
{
Title = title;
PackageId = packageId;
Version = version;
PackageAssets = packageAssets;
PackageDependencies = packageDependencies;
Expand Down