dotnet-installer/test/Microsoft.DotNet.Tools.Tests.Utilities/RepoDirectoriesProvider.cs

65 lines
2.1 KiB
C#
Raw Normal View History

// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.IO;
using System.Linq;
2018-10-29 18:26:53 +00:00
using System.Runtime.InteropServices;
using System.Xml.Linq;
using Microsoft.DotNet.PlatformAbstractions;
namespace Microsoft.DotNet.Tools.Test.Utilities
{
public class RepoDirectoriesProvider
{
2018-10-29 18:26:53 +00:00
public readonly static string RepoRoot;
public readonly static string TestWorkingFolder;
public readonly static string DotnetUnderTest;
2018-10-29 18:26:53 +00:00
static RepoDirectoriesProvider()
{
#if NET451
2018-10-29 18:26:53 +00:00
string directory = AppDomain.CurrentDomain.BaseDirectory;
#else
2018-10-29 18:26:53 +00:00
string directory = AppContext.BaseDirectory;
#endif
2018-10-29 18:26:53 +00:00
while (directory != null)
{
var gitDirOrFile = Path.Combine(directory, ".git");
if (Directory.Exists(gitDirOrFile) || File.Exists(gitDirOrFile))
{
2018-10-29 18:26:53 +00:00
break;
}
2018-10-29 18:26:53 +00:00
directory = Directory.GetParent(directory)?.FullName;
}
2018-10-29 18:26:53 +00:00
RepoRoot = directory;
2018-10-29 18:26:53 +00:00
TestWorkingFolder = Environment.GetEnvironmentVariable("CORESDK_TEST_FOLDER");
if (string.IsNullOrEmpty(TestWorkingFolder))
{
TestWorkingFolder = Path.Combine(AppContext.BaseDirectory, "Tests");
}
2018-10-29 18:26:53 +00:00
DotnetUnderTest = Environment.GetEnvironmentVariable("DOTNET_UNDER_TEST");
string dotnetExtension = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : "";
if (string.IsNullOrEmpty(DotnetUnderTest))
{
2018-10-29 18:26:53 +00:00
if (RepoRoot == null)
{
2018-10-29 18:26:53 +00:00
DotnetUnderTest = "dotnet" + dotnetExtension;
}
else
{
string configuration = new DirectoryInfo(AppContext.BaseDirectory).Parent.Name;
2018-10-29 19:26:31 +00:00
DotnetUnderTest = Path.Combine(RepoRoot, "artifacts", "bin", "redist", configuration, "dotnet", "dotnet" + dotnetExtension);
}
}
}
}
}