Fix relative path tool path (#9330)
Pass full path to Path.GetRelativePath
This commit is contained in:
parent
35a2c5d032
commit
983612b95b
3 changed files with 36 additions and 4 deletions
|
@ -119,6 +119,11 @@ namespace Microsoft.DotNet.Tools.Common
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string GetRelativePath(string path1, string path2)
|
public static string GetRelativePath(string path1, string path2)
|
||||||
{
|
{
|
||||||
|
if (!Path.IsPathRooted(path1) || !Path.IsPathRooted(path2))
|
||||||
|
{
|
||||||
|
throw new ArgumentException("both paths need to be rooted/full path");
|
||||||
|
}
|
||||||
|
|
||||||
return GetRelativePath(path1, path2, Path.DirectorySeparatorChar, true);
|
return GetRelativePath(path1, path2, Path.DirectorySeparatorChar, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,8 +39,8 @@ namespace Microsoft.DotNet.ShellShim
|
||||||
appHostSourcePath = Path.Combine(_appHostSourceDirectory, ApphostNameWithoutExtension);
|
appHostSourcePath = Path.Combine(_appHostSourceDirectory, ApphostNameWithoutExtension);
|
||||||
}
|
}
|
||||||
|
|
||||||
var appHostDestinationFilePath = shimPath.Value;
|
var appHostDestinationFilePath = Path.GetFullPath(shimPath.Value);
|
||||||
var appBinaryFilePath = PathUtility.GetRelativePath(appHostDestinationFilePath, entryPoint.Value);
|
var appBinaryFilePath = Path.GetRelativePath(Path.GetDirectoryName(appHostDestinationFilePath), Path.GetFullPath(entryPoint.Value));
|
||||||
|
|
||||||
EmbedAppNameInHost.EmbedAndReturnModifiedAppHostPath(
|
EmbedAppNameInHost.EmbedAndReturnModifiedAppHostPath(
|
||||||
appHostSourceFilePath: appHostSourcePath,
|
appHostSourceFilePath: appHostSourcePath,
|
||||||
|
|
|
@ -45,6 +45,27 @@ namespace Microsoft.DotNet.ShellShim.Tests
|
||||||
stdOut.Should().Contain("Hello World");
|
stdOut.Should().Contain("Hello World");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reproduce https://github.com/dotnet/cli/issues/9319
|
||||||
|
[Fact]
|
||||||
|
public void GivenAnExecutableAndRelativePathToShimPathItCanGenerateShimFile()
|
||||||
|
{
|
||||||
|
var outputDll = MakeHelloWorldExecutableDll("GivenAnExecutableAndRelativePath");
|
||||||
|
// To reproduce the bug, dll need to be nested under the shim
|
||||||
|
var parentPathAsShimPath = outputDll.GetDirectoryPath().GetParentPath().GetParentPath().Value;
|
||||||
|
var relativePathToShim = Path.GetRelativePath(
|
||||||
|
Directory.GetCurrentDirectory(),
|
||||||
|
parentPathAsShimPath);
|
||||||
|
|
||||||
|
ShellShimRepository shellShimRepository = ConfigBasicTestDependecyShellShimRepository(relativePathToShim);
|
||||||
|
var shellCommandName = nameof(ShellShimRepositoryTests) + Path.GetRandomFileName();
|
||||||
|
|
||||||
|
shellShimRepository.CreateShim(outputDll, shellCommandName);
|
||||||
|
|
||||||
|
var stdOut = ExecuteInShell(shellCommandName, relativePathToShim);
|
||||||
|
|
||||||
|
stdOut.Should().Contain("Hello World");
|
||||||
|
}
|
||||||
|
|
||||||
private static ShellShimRepository ConfigBasicTestDependecyShellShimRepository(string pathToShim)
|
private static ShellShimRepository ConfigBasicTestDependecyShellShimRepository(string pathToShim)
|
||||||
{
|
{
|
||||||
string stage2AppHostTemplateDirectory = GetAppHostTemplateFromStage2();
|
string stage2AppHostTemplateDirectory = GetAppHostTemplateFromStage2();
|
||||||
|
@ -473,13 +494,19 @@ namespace Microsoft.DotNet.ShellShim.Tests
|
||||||
return stage2AppHostTemplateDirectory;
|
return stage2AppHostTemplateDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static FilePath MakeHelloWorldExecutableDll()
|
private static FilePath MakeHelloWorldExecutableDll(string instanceName = null)
|
||||||
{
|
{
|
||||||
const string testAppName = "TestAppSimple";
|
const string testAppName = "TestAppSimple";
|
||||||
const string emptySpaceToTestSpaceInPath = " ";
|
const string emptySpaceToTestSpaceInPath = " ";
|
||||||
const string directoryNamePostFix = "Test";
|
const string directoryNamePostFix = "Test";
|
||||||
|
|
||||||
|
if (instanceName == null)
|
||||||
|
{
|
||||||
|
instanceName = testAppName + emptySpaceToTestSpaceInPath + directoryNamePostFix;
|
||||||
|
}
|
||||||
|
|
||||||
TestAssetInstance testInstance = TestAssets.Get(testAppName)
|
TestAssetInstance testInstance = TestAssets.Get(testAppName)
|
||||||
.CreateInstance(testAppName + emptySpaceToTestSpaceInPath + directoryNamePostFix)
|
.CreateInstance(instanceName)
|
||||||
.UseCurrentRuntimeFrameworkVersion()
|
.UseCurrentRuntimeFrameworkVersion()
|
||||||
.WithRestoreFiles()
|
.WithRestoreFiles()
|
||||||
.WithBuildFiles();
|
.WithBuildFiles();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue