private static bool LaunchedFromVisualStudio()
        {
            if (PATH != null)
            {
                return(true);
            }

            var processAndParent = ParentProcessUtils.CurrentProcessWithAncestors().ToArray();

            Process process = null;

            try
            {
                process = processAndParent.FirstOrDefault(x => x.MainModule.FileName.EndsWith("devenv.exe"));
            }
            catch (Exception)
            {
                // Any exception means we are not working in this environment.
                return(false);
            }

            if (process != null)
            {
                var processModule = process.MainModule;
                var version       = processModule.FileVersionInfo.FileMajorPart;
                if (11 <= version)
                {
                    PATH = processModule.FileName;
                }
            }

            return(PATH != null);
        }
        /*
         *  Copyright (c) Llewellyn Falco.  All rights reserved.
         *
         *  Licensed under the Apache License, Version 2.0 (the "License"); you
         *  may not use this file except in compliance with the License. You may
         *  obtain a copy of the License at
         *
         *  http://www.apache.org/licenses/LICENSE-2.0
         *
         *  Unless required by applicable law or agreed to in writing, software
         *  distributed under the License is distributed on an "AS IS" BASIS,
         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
         *  implied. See the License for the specific language governing permissions
         *  and limitations under the License.
         */
        // https://github.com/approvals/ApprovalTests.Net/blob/master/ApprovalTests/Reporters/VisualStudioReporter.cs
        private static string GetPath()
        {
            Process process;

            try
            {
                var processAndParent = ParentProcessUtils.CurrentProcessWithAncestors();
                process = processAndParent.FirstOrDefault(x => x.MainModule.FileName.EndsWith("devenv.exe"));
            }
            catch (Exception)
            {
                // Any exception means we are not working in this environment.
                return(null);
            }

            if (process != null)
            {
                var processModule = process.MainModule;
                var version       = processModule.FileVersionInfo.FileMajorPart;
                if (11 <= version)
                {
                    return(processModule.FileName);
                }
            }

            return(null);
        }
        private static Process FindVsOrVsTestConsoleExe()
        {
            var    process    = Process.GetCurrentProcess();
            string executable = Path.GetFileName(process.MainModule.FileName).Trim().ToLower();

            while (executable != null && !ParentProcessRegex.IsMatch(executable))
            {
                process    = ParentProcessUtils.GetParentProcess(process.Id);
                executable = process != null
                    ? Path.GetFileName(process.MainModule.FileName).Trim().ToLower()
                    : null;
            }
            return(process);
        }
        private static Process FindVsOrVsTestConsoleExe()
        {
            var    process    = Process.GetCurrentProcess();
            string executable = Path.GetFileName(process.MainModule.FileName).Trim().ToUpperInvariant();

            while (executable != null && executable != "DEVENV.EXE" && executable != "VSTEST.CONSOLE.EXE")
            {
                process    = ParentProcessUtils.GetParentProcess(process.Id);
                executable = process != null
                    ? Path.GetFileName(process.MainModule.FileName).Trim().ToUpperInvariant()
                    : null;
            }
            return(process);
        }
        private static string FindPath()
        {
            var processAndParent = ParentProcessUtils.CurrentProcessWithAncestors().ToArray();

            using (var process = processAndParent.FirstOrDefault(x => x.MainModule.FileName.EndsWith("rider64.exe")))
            {
                if (process != null)
                {
                    var processModule = process.MainModule;
                    return(processModule?.FileName);
                }
            }

            return(null);
        }
Beispiel #6
0
        private static string GetParentProcessName()
        {
            var parentProcess = ParentProcessUtils.GetParentProcess(Process.GetCurrentProcess());

            return(parentProcess == null ? string.Empty : parentProcess.ProcessName);
        }