コード例 #1
0
        public DotNet()
        {
            KnownDotnetLocations = Util.Platform switch
            {
                Platform.Windows => new string[]
                {
                    Path.Combine(
                        Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86),
                        "dotnet",
                        "dotnet.exe"),
                    Path.Combine(
                        Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles),
                        "dotnet",
                        "dotnet.exe"),
                },
                Platform.OSX => new string[]
                {
                    "/usr/local/share/dotnet/dotnet",
                },
                Platform.Linux => new string[]
                {
                    // /home/user/share/dotnet/dotnet
                    Path.Combine(
                        Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
                        "share",
                        "dotnet",
                        "dotnet")
                },
                _ => new string[] { }
            };

            // First try and use the actual resolver logic
            var r = new Microsoft.DotNet.DotNetSdkResolver.NETCoreSdkResolver();

            DotNetSdkLocation = new DirectoryInfo(r.GetDotnetExeDirectory());

            if (DotNetSdkLocation.Exists)
            {
                DotNetExeLocation = new FileInfo(Path.Combine(DotNetSdkLocation.FullName, Util.IsWindows ? "dotnet.exe" : "dotnet"));
            }
            else
            {
                var l = FindDotNetLocations();

                if (l != default)
                {
                    DotNetExeLocation = l.dotnet;
                    DotNetSdkLocation = l.sdkDir;
                }
            }
        }
コード例 #2
0
        public DotNetSdk(SharedState sharedState)
        {
            KnownDotnetLocations = Util.Platform switch
            {
                Platform.Windows => new string[]
                {
                    Path.Combine(
                        Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86),
                        "dotnet",
                        DotNetExeName),
                    Path.Combine(
                        Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles),
                        "dotnet",
                        DotNetExeName),
                },
                Platform.OSX => new string[]
                {
                    "/usr/local/share/dotnet/dotnet",
                },
                Platform.Linux => new string[]
                {
                    // /home/user/share/dotnet/dotnet
                    Path.Combine(
                        Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
                        "share",
                        "dotnet",
                        DotNetExeName)
                },
                _ => new string[] { }
            };

            string sdkRoot = null;

            if (sharedState != null && sharedState.TryGetEnvironmentVariable("DOTNET_ROOT", out var envSdkRoot))
            {
                if (Directory.Exists(envSdkRoot))
                {
                    sdkRoot = envSdkRoot;
                }
            }

            if (string.IsNullOrEmpty(sdkRoot) || !Directory.Exists(sdkRoot))
            {
                var r = new Microsoft.DotNet.DotNetSdkResolver.NETCoreSdkResolver();
                sdkRoot = r.GetDotnetExeDirectory();
            }

            if (string.IsNullOrEmpty(sdkRoot) || !Directory.Exists(sdkRoot))
            {
                var l = FindDotNetLocations();
                if (l != default)
                {
                    sdkRoot = l.sdkDir.FullName;
                }
            }

            sharedState.SetEnvironmentVariable("DOTNET_ROOT", sdkRoot);

            // First try and use the actual resolver logic
            DotNetSdkLocation = new DirectoryInfo(sdkRoot);
            DotNetExeLocation = new FileInfo(Path.Combine(DotNetSdkLocation.FullName, DotNetExeName));
        }