Skip to content
Open
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 @@ -186,7 +186,6 @@ NOTE: This file is imported from the following contexts, so be aware when writin
Condition=" '$(PackAsTool)' == 'true' "
Returns="@(TfmSpecificPackageFile)">
<ItemGroup>
<_GeneratedFiles Include="$(_ToolsSettingsFilePath)"/>
<!-- Note here that we're _not_ computing relative directories inside the package anymore. In our packages, we essentially want to
recreate the publish layout, but under a TFM- or RID-specific root path. Because we're globbing from the PublishDir,
the MSBuild Items will have the RecursiveDir metadata - this is used by the PackLogic to combine with the PackagePath
Expand All @@ -205,8 +204,15 @@ NOTE: This file is imported from the following contexts, so be aware when writin
<PropertyGroup>
<_ToolRidPath Condition="'$(RuntimeIdentifier)' == ''">any</_ToolRidPath>
<_ToolRidPath Condition="'$(RuntimeIdentifier)' != ''">$(RuntimeIdentifier)</_ToolRidPath>
<_ToolSettingsTargetFrameworkPath>$(_ToolPackShortTargetFrameworkName)</_ToolSettingsTargetFrameworkPath>
<!-- RID-specific top-level packages are pointers only, so their settings file should be TFM-agnostic too. -->
<_ToolSettingsTargetFrameworkPath Condition="'$(_ToolPackageShouldIncludeImplementation)' != 'true' and '$(_UserSpecifiedToolPackageRids)' != ''">any</_ToolSettingsTargetFrameworkPath>
</PropertyGroup>
<ItemGroup>
<TfmSpecificPackageFile Include="$(_ToolsSettingsFilePath)">
<PackagePath>tools/$(_ToolSettingsTargetFrameworkPath)/$(_ToolRidPath)/</PackagePath>
</TfmSpecificPackageFile>

<TfmSpecificPackageFile Include="@(_GeneratedFiles)">
<PackagePath>tools/$(_ToolPackShortTargetFrameworkName)/$(_ToolRidPath)/%(_GeneratedFiles.RecursiveDir)</PackagePath>
</TfmSpecificPackageFile>
Expand Down
19 changes: 17 additions & 2 deletions test/Microsoft.DotNet.PackageInstall.Tests/EndToEndToolTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public void PackagesMultipleToolsWithASingleInvocation()

// top-level package should declare all of the rids
var topLevelPackage = packages.First(p => p.EndsWith($"{packageIdentifier}.{toolSettings.ToolPackageVersion}.nupkg"));
EnsureToolSettingsFileUsesAnyTfmAndRid(topLevelPackage);
var foundRids = GetRidsInSettingsFile(topLevelPackage);
foundRids.Should().BeEquivalentTo(expectedRids, "The top-level package should declare all of the RIDs for the tools it contains");
}
Expand Down Expand Up @@ -264,6 +265,7 @@ public void PackageToolWithAnyRid()
// top-level package should declare all of the rids
var topLevelPackage = packages.FirstOrDefault(p => p.EndsWith($"{packageIdentifier}.{toolSettings.ToolPackageVersion}.nupkg"));
topLevelPackage.Should().NotBeNull($"Package {packageIdentifier}.{toolSettings.ToolPackageVersion}.nupkg should be present in the tool packages directory")
.And.Satisfy<string>(EnsureToolSettingsFileUsesAnyTfmAndRid)
.And.Satisfy<string>(SupportAllOfTheseRuntimes([.. expectedRids, "any"]));
}

Expand Down Expand Up @@ -554,16 +556,29 @@ static string[] GetRidsInSettingsFile(XElement settingsXml)
return nodes;
}

static void EnsureToolSettingsFileUsesAnyTfmAndRid(string packagePath)
{
using var zipArchive = ZipFile.OpenRead(packagePath);
GetToolSettingsFileEntry(zipArchive).FullName.Should().Be("tools/any/any/DotnetToolSettings.xml");
}

static XElement GetToolSettingsFile(string packagePath)
{
using var zipArchive = ZipFile.OpenRead(packagePath);
var nuspecEntry = zipArchive.Entries.First(e => e.Name == "DotnetToolSettings.xml")!;
var stream = nuspecEntry.Open();
var toolSettingsEntry = GetToolSettingsFileEntry(zipArchive);
var stream = toolSettingsEntry.Open();
var xml = XDocument.Load(stream, LoadOptions.None);
Comment thread
baronfel marked this conversation as resolved.
return xml.Root!;

}

static ZipArchiveEntry GetToolSettingsFileEntry(ZipArchive zipArchive)
{
var settingsEntries = zipArchive.Entries.Where(e => e.Name == "DotnetToolSettings.xml").ToArray();
settingsEntries.Should().ContainSingle("tool packages should contain exactly one DotnetToolSettings.xml file");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think multi-targeted tool packages can contain more than one tool settings file. But this is probably fine for the scenarios we're testing.

return settingsEntries[0];
}

[TestMethod]
public void InstallToolWithHigherFrameworkAsGlobalToolShowsAppropriateError()
{
Expand Down
Loading