Skip to content

Commit

Permalink
Revert "Implement consuming pdb in package reference (#4654)"
Browse files Browse the repository at this point in the history
This reverts commit 60b3c34.
  • Loading branch information
kartheekp-ms committed Jun 29, 2022
1 parent 00ee74b commit 344f8a8
Show file tree
Hide file tree
Showing 8 changed files with 1,209 additions and 4,345 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -691,11 +691,6 @@ private static IEnumerable<LockFileItem> GetLockFileItems(
{
newItem.Properties["locale"] = (string)locale;
}
object related;
if (item.Properties.TryGetValue("related", out related))
{
newItem.Properties["related"] = (string)related;
}
additionalAction?.Invoke(newItem);
yield return newItem;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using NuGet.Packaging;

Expand All @@ -13,7 +11,6 @@ namespace NuGet.ContentModel
public class ContentItemCollection
{
private List<Asset> _assets;
private ConcurrentDictionary<string, string> _assemblyRelatedExtensions;

/// <summary>
/// True if lib/contract exists
Expand All @@ -22,9 +19,6 @@ public class ContentItemCollection

public void Load(IEnumerable<string> paths)
{
// Cache for assembly and it's related file extensions.
_assemblyRelatedExtensions = new ConcurrentDictionary<string, string>();

// Read already loaded assets
_assets = new List<Asset>();

Expand Down Expand Up @@ -274,15 +268,6 @@ private IList<ContentItem> FindItemsImplementation(PatternSet definition, IEnume
var contentItem = pathPattern.Match(path, definition.PropertyDefinitions);
if (contentItem != null)
{
//If the item is assembly, populate the "related files extentions property".
if (contentItem.Properties.ContainsKey("assembly"))
{
string relatedFileExtensionsProperty = GetRelatedFileExtensionProperty(contentItem.Path, assets);
if (relatedFileExtensionsProperty is not null)
{
contentItem.Properties.Add("related", relatedFileExtensionsProperty);
}
}
itemsList.Add(contentItem);
break;
}
Expand All @@ -292,56 +277,6 @@ private IList<ContentItem> FindItemsImplementation(PatternSet definition, IEnume
return itemsList;
}

internal string GetRelatedFileExtensionProperty(string assemblyPath, IEnumerable<Asset> assets)
{
//E.g. if path is "lib/net472/A.B.C.dll", the prefix will be "lib/net472/A.B.C."
string assemblyPrefix = assemblyPath.Substring(0, assemblyPath.LastIndexOf('.') + 1);

if (_assemblyRelatedExtensions.TryGetValue(assemblyPrefix, out string relatedProperty))
{
return relatedProperty;
}

List<string> relatedFileExtensionList = null;
foreach (Asset asset in assets)
{
if (asset.Path is not null)
{
string extension = Path.GetExtension(asset.Path);
if (extension != string.Empty &&
//Assembly properties are files with extensions ".dll", ".winmd", ".exe", see ManagedCodeConventions.
!extension.Equals(".dll", StringComparison.OrdinalIgnoreCase) &&
!extension.Equals(".exe", StringComparison.OrdinalIgnoreCase) &&
!extension.Equals(".winmd", StringComparison.OrdinalIgnoreCase) &&
!asset.Path.Equals(assemblyPath, StringComparison.OrdinalIgnoreCase) &&
//The prefix should match exactly (case sensitive), as file names are case sensitive on certain OSes.
//E.g. for lib/net472/A.B.C.dll and lib/net472/a.b.c.xml, if we generate related property '.xml', the related file path is not predicatble on case sensitive OSes.
asset.Path.StartsWith(assemblyPrefix, StringComparison.Ordinal))
{
if (relatedFileExtensionList is null)
{
relatedFileExtensionList = new List<string>();
}
relatedFileExtensionList.Add(asset.Path.Substring(assemblyPrefix.Length - 1));
}
}
}

// If no related files found.
if (relatedFileExtensionList is null || !relatedFileExtensionList.Any())
{
_assemblyRelatedExtensions.TryAdd(assemblyPrefix, null);
return null;
}
else
{
relatedFileExtensionList.Sort();
string relatedFileExtensionsProperty = string.Join(";", relatedFileExtensionList);
_assemblyRelatedExtensions.TryAdd(assemblyPrefix, relatedFileExtensionsProperty);
return relatedFileExtensionsProperty;
}
}

/// <summary>
/// False if the path would not match any patterns.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1752,7 +1752,7 @@ public async Task DotnetRestore_WithDuplicatePackageVersion_WarnsWithNU1506()
await SimpleTestPackageUtility.CreateFolderFeedV3Async(pathContext.PackageSource, packageContext);

var directoryPackagesPropsContent =
@"<Project>
@"<Project>
<ItemGroup>
<PackageVersion Include=""X"" Version=""[1.0.0]"" />
<PackageVersion Include=""X"" Version=""[2.0.0]"" />
Expand Down Expand Up @@ -2307,7 +2307,7 @@ public async Task DotnetRestore_WithDuplicatePackageVersion_WithTreatWarningsAsE
await SimpleTestPackageUtility.CreateFolderFeedV3Async(pathContext.PackageSource, packageContext);

var directoryPackagesPropsContent =
@"<Project>
@"<Project>
<ItemGroup>
<PackageVersion Include=""X"" Version=""[1.0.0]"" />
<PackageVersion Include=""X"" Version=""[2.0.0]"" />
Expand Down Expand Up @@ -2393,96 +2393,6 @@ public async Task DotnetRestore_WithDuplicatePackageReference_RespectsContinueOn
}
}

[Fact]
public async Task WhenPackageReferrenceHasRelatedFiles_RelatedPropertyIsApplied_Success()
{
using var pathContext = _msbuildFixture.CreateSimpleTestPathContext();

// Set up solution, and project
// projectA -> projectB -> packageX -> packageY
var solution = new SimpleTestSolutionContext(pathContext.SolutionRoot);
var framework = "net5.0";
var projectA = SimpleTestProjectContext.CreateNETCore(
"projectA",
pathContext.SolutionRoot,
framework);

var projectB = SimpleTestProjectContext.CreateNETCore(
"projectB",
pathContext.SolutionRoot,
framework);

projectB.Properties.Add("Configuration", "Debug");

projectA.AddProjectToAllFrameworks(projectB);

var packageX = new SimpleTestPackageContext("packageX", "1.0.0");
packageX.Files.Clear();
packageX.AddFile($"lib/net5.0/X.dll");
packageX.AddFile($"lib/net5.0/X.xml");

var packageY = new SimpleTestPackageContext("packageY", "1.0.0");
packageY.Files.Clear();
// Compile
packageY.AddFile("ref/net5.0/Y.dll");
packageY.AddFile("ref/net5.0/Y.xml");
// Runtime
packageY.AddFile("lib/net5.0/Y.dll");
packageY.AddFile("lib/net5.0/Y.pdb");
packageY.AddFile("lib/net5.0/Y.xml");
// Embed
packageY.AddFile("embed/net5.0/Y.dll");
packageY.AddFile("embed/net5.0/Y.pdb");

packageX.Dependencies.Add(packageY);
await SimpleTestPackageUtility.CreatePackagesAsync(pathContext.PackageSource, packageX, packageY);
projectB.AddPackageToAllFrameworks(packageX);

solution.Projects.Add(projectA);
solution.Projects.Add(projectB);
solution.Create(pathContext.SolutionRoot);

await SimpleTestPackageUtility.CreateFolderFeedV3Async(
pathContext.PackageSource,
PackageSaveMode.Defaultv3,
packageX,
packageY);

//Act
var result = _msbuildFixture.RunDotnet(pathContext.WorkingDirectory, $"restore {projectA.ProjectPath} -v n", ignoreExitCode: true);

// Assert
result.Success.Should().BeTrue(because: result.AllOutput);

var assetsFile = projectA.AssetsFile;
Assert.NotNull(assetsFile);
var targets = assetsFile.GetTarget(framework, null);

// packageX (top-level package reference): "related" property is applied correctly for Compile & Runtime
var packageXLib = targets.Libraries.Single(x => x.Name.Equals("packageX"));
var packageXCompile = packageXLib.CompileTimeAssemblies;
AssertRelatedProperty(packageXCompile, $"lib/net5.0/X.dll", ".xml");
var packageXRuntime = packageXLib.RuntimeAssemblies;
AssertRelatedProperty(packageXRuntime, $"lib/net5.0/X.dll", ".xml");

// packageY (transitive package reference): "related" property is applied for Compile, Runtime and Embeded.
var packageYLib = targets.Libraries.Single(x => x.Name.Equals("packageY"));
var packageYCompile = packageYLib.CompileTimeAssemblies;
AssertRelatedProperty(packageYCompile, $"ref/net5.0/Y.dll", ".xml");
var packageYRuntime = packageYLib.RuntimeAssemblies;
AssertRelatedProperty(packageYRuntime, $"lib/net5.0/Y.dll", ".pdb;.xml");
var packageYEmbed = packageYLib.EmbedAssemblies;
AssertRelatedProperty(packageYEmbed, $"embed/net5.0/Y.dll", ".pdb");

// projectB (project reference): "related" property is NOT applied for Compile or Runtime.
var projectBLib = targets.Libraries.Single(x => x.Name.Equals("projectB"));
var projectBCompile = projectBLib.CompileTimeAssemblies;
AssertRelatedProperty(projectBCompile, $"bin/placeholder/projectB.dll", null);
var projectBRuntime = projectBLib.RuntimeAssemblies;
AssertRelatedProperty(projectBRuntime, $"bin/placeholder/projectB.dll", null);

}

private static SimpleTestPackageContext CreateNetstandardCompatiblePackage(string id, string version)
{
var pkgX = new SimpleTestPackageContext(id, version);
Expand Down Expand Up @@ -2693,18 +2603,5 @@ public async Task DotnetRestore_WithMultiTargettingProject_WhenTargetFrameworkIs
var allTargets = File.ReadAllText(targetsFilePath);
allTargets.Should().Contain(condition);
}

private void AssertRelatedProperty(IList<LockFileItem> items, string path, string related)
{
var item = items.Single(i => i.Path.Equals(path));
if (related == null)
{
Assert.False(item.Properties.ContainsKey("related"));
}
else
{
Assert.Equal(related, item.Properties["related"]);
}
}
}
}
Loading

0 comments on commit 344f8a8

Please sign in to comment.