Microsoft MVP성태의 닷넷 이야기
VS.NET IDE: 103. Visual Studio의 Ctrl + F5 실행 동작 [링크 복사], [링크+제목 복사],
조회: 19776
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일

Visual Studio의 Ctrl + F5 실행 동작

아래의 질문이 있군요. ^^

visual studio의 ctrl+f5 기능을 command 입력으로 실행하기? 
; http://lab.gamecodi.com/board/zboard.php?id=GAMECODILAB_QnA_etc&no=3833&z=

이 질문을 읽으면서 생각난 건데요... 콘솔 유형의 프로그램을 Ctrl + F5 (Start Without Debugging) 키로 실행시키면 "명령행 창"이 없어지지 않고 "Press any key to continue..." 문자열과 함께 대기를 하게 됩니다.

vs_cmd_1.png

반면 그냥 "F5(Start Debugging)"키를 누르면 실행 후 대기하지 않고 곧바로 창이 종료하게 됩니다. 도대체 그 차이가 뭘까요? ^^

이를 확인하려면, 콘솔 프로그램에서 부모 프로세스의 ID를 구하는 코드를 작성해 보면 됩니다.

How to get parent process in .NET in managed way
; http://stackoverflow.com/questions/394816/how-to-get-parent-process-in-net-in-managed-way

using System;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        int processId = Process.GetCurrentProcess().Id;
        Console.WriteLine("ParentPid: " + Process.GetProcessById(processId).Parent().Id);

        if (Debugger.IsAttached == true)
        {
            Console.ReadLine();
        }
    }
}

public static class ProcessExtensions
{
    private static string FindIndexedProcessName(int pid)
    {
        var processName = Process.GetProcessById(pid).ProcessName;
        var processesByName = Process.GetProcessesByName(processName);
        string processIndexdName = null;

        for (var index = 0; index < processesByName.Length; index++)
        {
            processIndexdName = index == 0 ? processName : processName + "#" + index;
            var processId = new PerformanceCounter("Process", "ID Process", processIndexdName);
            if ((int)processId.NextValue() == pid)
            {
                return processIndexdName;
            }
        }

        return processIndexdName;
    }

    private static Process FindPidFromIndexedProcessName(string indexedProcessName)
    {
        var parentId = new PerformanceCounter("Process", "Creating Process ID", indexedProcessName);
        return Process.GetProcessById((int)parentId.NextValue());
    }

    public static Process Parent(this Process process)
    {
        return FindPidFromIndexedProcessName(FindIndexedProcessName(process.Id));
    }
}

위의 코드를 F5로 실행해 보면, 출력되는 부모 프로세스 ID값이 비주얼 스튜디오인 devenv.exe임을 알 수 있습니다. 비주얼 스튜디오 입장에서는 디버거로써 매끄럽게 동작하기 위해 바로 하위의 프로세스로 콘솔 프로그램을 실행시켰던 것입니다.

반면 Ctrl + F5키로 실행하면 부모 프로세스로 devenv.exe와의 사이에 cmd.exe가 끼어들어간 것을 볼 수 있고 그것의 프로세스 ID를 출력하게 됩니다. 그리고 그 순간의 cmd.exe 창을 비주얼 스튜디오가 어떻게 실행했는지를 알기 위해 Process Explorer를 이용해 보면 다음과 같은 명령행을 확인할 수 있습니다.

"C:\WINDOWS\system32\cmd.exe" /c ""C:\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe"  & pause""

그렇습니다. Ctrl + F5 키가 눌린 경우 비주얼 스튜디오는 cmd.exe의 인자로 콘솔 프로그램의 실행 파일 경로와 함께 "pause" 명령을 추가해 그런 효과를 낸 것입니다. ^^

(첨부한 파일은 위의 예제를 테스트한 코드입니다.)




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 9/8/2015]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 61  62  [63]  64  65  66  67  68  69  70  71  72  73  74  75  ...
NoWriterDateCnt.TitleFile(s)
12051정성태11/14/201913755개발 환경 구성: 462. 시작하자마자 비정상 종료하는 프로세스의 메모리 덤프 - procdump [1]
12050정성태11/14/201911443Windows: 165. AcLayers의 API 후킹과 FaultTolerantHeap
12049정성태11/13/201911510.NET Framework: 868. (닷넷 프로세스를 대상으로) 디버거 방식이 아닌 CLR Profiler를 이용해 procdump.exe 기능 구현
12048정성태11/12/201912341Windows: 164. GUID 이름의 볼륨에 해당하는 파티션을 찾는 방법
12047정성태11/12/201914132Windows: 163. 안전하게 eject시킨 USB 장치를 물리적인 재연결 없이 다시 인식시키는 방법
12046정성태10/29/201910102오류 유형: 577. windbg - The call to LoadLibrary(...\sos.dll) failed, Win32 error 0n193
12045정성태10/27/20199466오류 유형: 576. mstest.exe 실행 시 "Visual Studio Enterprise is required to execute the test." 오류 - 두 번째 이야기
12044정성태10/27/20199722오류 유형: 575. mstest.exe - System.Resources.MissingSatelliteAssemblyException: The satellite assembly named "Microsoft.VisualStudio.ProductKeyDialog.resources.dll, ..."
12043정성태10/27/201910433오류 유형: 574. Windows 10 설치 시 오류 - 0xC1900101 - 0x4001E
12042정성태10/26/201910807오류 유형: 573. OneDrive 하위에 위치한 Documents, Desktop 폴더에 대한 권한 변경 시 "Unable to display current owner"
12041정성태10/23/201910831오류 유형: 572. mstest.exe - The load test results database could not be opened.
12040정성태10/23/201911125오류 유형: 571. Unhandled Exception: System.Net.Mail.SmtpException: Transaction failed. The server response was: 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied
12039정성태10/22/20199561스크립트: 16. cmd.exe의 for 문에서는 ERRORLEVEL이 설정되지 않는 문제
12038정성태10/17/20199145오류 유형: 570. SQL Server 2019 RC1 - SQL Client Connectivity SDK 설치 오류
12037정성태10/15/201914752.NET Framework: 867. C# - Encoding.Default 값을 바꿀 수 있을까요?파일 다운로드1
12036정성태10/14/201916082.NET Framework: 866. C# - 고성능이 필요한 환경에서 GC가 발생하지 않는 네이티브 힙 사용파일 다운로드1
12035정성태10/13/201912225개발 환경 구성: 461. C# 8.0의 #nulable 관련 특성을 .NET Framework 프로젝트에서 사용하는 방법 [2]파일 다운로드1
12034정성태10/12/201911607개발 환경 구성: 460. .NET Core 환경에서 (프로젝트가 아닌) C# 코드 파일을 입력으로 컴파일하는 방법 [1]
12033정성태10/11/201915242개발 환경 구성: 459. .NET Framework 프로젝트에서 C# 8.0/9.0 컴파일러를 사용하는 방법
12032정성태10/8/201911736.NET Framework: 865. .NET Core 2.2/3.0 웹 프로젝트를 IIS에서 호스팅(Inproc, out-of-proc)하는 방법 - AspNetCoreModuleV2 소개
12031정성태10/7/20199213오류 유형: 569. Azure Site Extension 업그레이드 시 "System.IO.IOException: There is not enough space on the disk" 예외 발생
12030정성태10/5/201915413.NET Framework: 864. .NET Conf 2019 Korea - "닷넷 17년의 변화 정리 및 닷넷 코어 3.0" 발표 자료 [1]파일 다운로드1
12029정성태9/27/201915469제니퍼 .NET: 29. Jennifersoft provides a trial promotion on its APM solution such as JENNIFER, PHP, and .NET in 2019 and shares the examples of their application.
12028정성태9/26/201911366.NET Framework: 863. C# - Thread.Suspend 호출 시 응용 프로그램 hang 현상을 해결하기 위한 시도파일 다운로드1
12027정성태9/26/20198652오류 유형: 568. Consider app.config remapping of assembly "..." from Version "..." [...] to Version "..." [...] to solve conflict and get rid of warning.
12026정성태9/26/201912227.NET Framework: 862. C# - Active Directory의 LDAP 경로 및 정보 조회
... 61  62  [63]  64  65  66  67  68  69  70  71  72  73  74  75  ...