Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Commit

Permalink
Merge pull request #10120 from wli3/fix-enusposix-toolinstall
Browse files Browse the repository at this point in the history
Change package id compare from CurrentCultureIgnoreCase to OrdinalIgnoreCase
  • Loading branch information
William Li authored Oct 10, 2018
2 parents c918fd6 + 5ec02ad commit 2548ac2
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/dotnet/ToolPackage/ToolPackageInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ private LockFileTargetLibrary FindLibraryInLockFile(LockFile lockFile)
return lockFile
?.Targets?.SingleOrDefault(t => t.RuntimeIdentifier != null)
?.Libraries?.SingleOrDefault(l =>
string.Compare(l.Name, Id.ToString(), StringComparison.CurrentCultureIgnoreCase) == 0);
string.Compare(l.Name, Id.ToString(), StringComparison.OrdinalIgnoreCase) == 0);
}

private static LockFileItem FindItemInTargetLibrary(LockFileTargetLibrary library, string targetRelativeFilePath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
<Content Remove="SampleGlobalToolWithShim/**" />
<EmbeddedResource Remove="SampleGlobalToolWithShim/**" />
<None Remove="SampleGlobalToolWithShim/**" />

<Compile Remove="SampleGlobalToolWithDifferentCasing/**" />
<Content Remove="SampleGlobalToolWithDifferentCasing/**" />
<EmbeddedResource Remove="SampleGlobalToolWithDifferentCasing/**" />
<None Remove="SampleGlobalToolWithDifferentCasing/**" />
</ItemGroup>

<UsingTask TaskName="DownloadFile" AssemblyFile="$(CLIBuildDll)" />
Expand All @@ -67,6 +72,19 @@
</MSBuild>
</Target>

<Target Name="CreateNupkgWithDifferentCasingFromSource" BeforeTargets="Build">
<PropertyGroup>
<testAssetSourceRoot>$(BaseOutputPath)/TestAsset/SampleGlobalToolWithDifferentCasing</testAssetSourceRoot>
</PropertyGroup>
<Copy SourceFiles="SampleGlobalToolWithDifferentCasing/DotnetToolSettings.xml" DestinationFolder="$(testAssetSourceRoot)" />
<MSBuild BuildInParallel="False" Projects="SampleGlobalToolWithDifferentCasing/ConsoleDemoWithCasing.csproj" Targets="Restore" Properties="Configuration=Release;BaseOutputPath=$(testAssetSourceRoot)/bin/;ForceRestoreToEvaluateSeparately=1">
</MSBuild>
<MSBuild BuildInParallel="False" Projects="SampleGlobalToolWithDifferentCasing/ConsoleDemoWithCasing.csproj" Targets="Build;Publish" Properties="Configuration=Release;BaseOutputPath=$(testAssetSourceRoot)/bin/">
</MSBuild>
<MSBuild BuildInParallel="False" Projects="SampleGlobalToolWithDifferentCasing/ConsoleDemoWithCasing.csproj" Targets="pack" Properties="Configuration=Release;NuspecFile=includepublish.nuspec;NuspecBasePath=$(testAssetSourceRoot);PackageOutputPath=$(OutputPath)/TestAssetLocalNugetFeed">
</MSBuild>
</Target>

<Target Name="CreateNupkgWithShimFromSource" BeforeTargets="Build">
<PropertyGroup>
<testAssetSourceRoot>$(BaseOutputPath)/TestAsset/SampleGlobalToolWithShim</testAssetSourceRoot>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AssemblyName>ConsoleDemoWithCasing</AssemblyName>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<DotNetCliTool Version="1" >
<Commands>
<Command Name="DemoWithCasing" EntryPoint="ConsoleDemoWithCasing.dll" Runner="dotnet" />
</Commands>
</DotNetCliTool>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;

namespace ConsoleDemoWithCasing
{
class Program
{
static void Main(string[] args)
{
var greeting = "Hello World from Global Tool";
Console.WriteLine(greeting);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Global.Tool.Console.Demo.With.Casing</id>
<version>2.0.4</version>
<description>test app</description>
<authors>testauthor</authors>
<packageTypes>
<packageType name="DotnetTool" />
</packageTypes>
</metadata>
<files>
<file src="bin\Release\netcoreapp2.1\publish\*.*" target="tools\netcoreapp2.1\any\" />
<file src="DotnetToolSettings.xml" target="tools\netcoreapp2.1\any\DotnetToolSettings.xml" />
</files>
</package>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Linq;
using System.Reflection;
using System.Transactions;
using System.Threading;
using FluentAssertions;
using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.DotNet.Cli;
Expand Down Expand Up @@ -669,6 +670,59 @@ public void GivenAComplexVersionRangeInstallSucceeds(bool testMockBehaviorIsInSy
package.Uninstall();
}

[NonWindowsOnlyTheory]
[InlineData(false)]
[InlineData(true)]
// repro https://github.com/dotnet/cli/issues/10101
public void GivenAPackageWithCasingAndenUSPOSIXInstallSucceeds(bool testMockBehaviorIsInSync)
{
var nugetConfigPath = WriteNugetConfigFileToPointToTheFeed();
var emptySource = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
Directory.CreateDirectory(emptySource);

var packageId = new PackageId("Global.Tool.Console.Demo.With.Casing");
var packageVersion = "2.0.4";
var feed = new MockFeed
{
Type = MockFeedType.ImplicitAdditionalFeed,
Uri = nugetConfigPath.Value,
Packages = new List<MockFeedPackage>
{
new MockFeedPackage
{
PackageId = packageId.ToString(),
Version = packageVersion,
}
}
};

var (store, installer, reporter, fileSystem) = Setup(
useMock: testMockBehaviorIsInSync,
feeds: new[] { feed });

CultureInfo currentCultureBefore = CultureInfo.CurrentCulture;
try
{
CultureInfo.CurrentCulture = new CultureInfo("en-US-POSIX");
IToolPackage package = null;
Action action = () => package = installer.InstallPackage(
packageId: packageId,
versionRange: VersionRange.Parse(packageVersion),
targetFramework: _testTargetframework,
nugetConfig: nugetConfigPath, additionalFeeds: new[] { emptySource });

action.ShouldNotThrow<ToolConfigurationException>();

fileSystem.File.Exists(package.Commands[0].Executable.Value).Should().BeTrue($"{package.Commands[0].Executable.Value} should exist");

package.Uninstall();
}
finally
{
CultureInfo.CurrentCulture = currentCultureBefore;
}
}

private static void AssertPackageInstall(
BufferedReporter reporter,
IFileSystem fileSystem,
Expand Down

0 comments on commit 2548ac2

Please sign in to comment.