internal async Task AttachDebugger(DebugOptions debugOptions)
        {
            string appHash = ComputeHash(debugOptions.StartupAssemblyPath);

            Project startup = GetStartupProject();

            bool            isWeb   = ((object[])startup.ExtenderNames).Any(x => x.ToString() == "WebApplication");
            ApplicationType appType = isWeb ? ApplicationType.Webapplication : ApplicationType.Desktopapplication;

            if (appType == ApplicationType.Webapplication)
            {
                debugOptions.OutputDirectory += @"\..\..\";
            }

            var          client  = new DebugClient(appType, debugOptions.TargetExeFileName, debugOptions.StartArguments, debugOptions.OutputDirectory, appHash);
            DebugSession session = await client.ConnectToServerAsync(debugOptions.UserSettings.LastIp);

            var debugSessionStarted = await session.RestartDebuggingAsync(debugOptions.UserSettings.LastTimeout);

            if (!debugSessionStarted)
            {
                await session.TransferFilesAsync();

                await session.WaitForAnswerAsync(debugOptions.UserSettings.LastTimeout);
            }

            IntPtr pInfo = GetDebugInfo(debugOptions);
            var    sp    = new ServiceProvider((IServiceProvider)_dte);

            try
            {
                var dbg = (IVsDebugger)sp.GetService(typeof(SVsShellDebugger));
                int hr  = dbg.LaunchDebugTargets(1, pInfo);
                Marshal.ThrowExceptionForHR(hr);

                DebuggedProcess.Instance.AssociateDebugSession(session);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                string msg;
                var    sh = (IVsUIShell)sp.GetService(typeof(SVsUIShell));
                sh.GetErrorInfo(out msg);

                if (!string.IsNullOrWhiteSpace(msg))
                {
                    logger.Error(msg);
                }
                throw;
            }
            finally
            {
                if (pInfo != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(pInfo);
                }
            }
        }
        internal async Task AttachDebugger(string ipAddress)
        {
            string path            = GetStartupAssemblyPath();
            string targetExe       = Path.GetFileName(path);
            string outputDirectory = Path.GetDirectoryName(path);

            Project startup = GetStartupProject();

            bool            isWeb   = ((object[])startup.ExtenderNames).Any(x => x.ToString() == "WebApplication");
            ApplicationType appType = isWeb ? ApplicationType.Webapplication : ApplicationType.Desktopapplication;

            if (appType == ApplicationType.Webapplication)
            {
                outputDirectory += @"\..\..\";
            }

            var          client  = new DebugClient(appType, targetExe, outputDirectory);
            DebugSession session = await client.ConnectToServerAsync(ipAddress);

            await session.TransferFilesAsync();

            await session.WaitForAnswerAsync();

            IntPtr pInfo = GetDebugInfo(ipAddress, targetExe, outputDirectory);
            var    sp    = new ServiceProvider((IServiceProvider)_dte);

            try
            {
                var dbg = (IVsDebugger)sp.GetService(typeof(SVsShellDebugger));
                int hr  = dbg.LaunchDebugTargets(1, pInfo);
                Marshal.ThrowExceptionForHR(hr);

                DebuggedProcess.Instance.AssociateDebugSession(session);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                string msg;
                var    sh = (IVsUIShell)sp.GetService(typeof(SVsUIShell));
                sh.GetErrorInfo(out msg);

                if (!string.IsNullOrWhiteSpace(msg))
                {
                    logger.Error(msg);
                }
                throw;
            }
            finally
            {
                if (pInfo != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(pInfo);
                }
            }
        }
示例#3
0
        internal async Task AttachDebugger(string ipAddress)
        {
            string path            = GetStartupAssemblyPath();
            string targetExe       = Path.GetFileName(path);
            string outputDirectory = Path.GetDirectoryName(path);

            Project startup = GetStartupProject();

            bool isWeb = ((object[])startup.ExtenderNames).Any(x => x.ToString() == "WebApplication") ||
                         startup.Properties.OfType <Property>().Any(p => p.Name.StartsWith("WebApplication.") || p.Name.StartsWith("WebSite."));
            ApplicationType   appType = isWeb ? ApplicationType.Webapplication : ApplicationType.Desktopapplication;
            WebsiteParameters webPar  = null;

            if (appType != ApplicationType.Desktopapplication)
            {
                outputDirectory += @"\..\";
                var extUrlProp       = startup.Properties.OfType <Property>().FirstOrDefault(p => p.Name == "WebApplication.StartExternalUrl");
                var frameworkVerProp = startup.Properties.OfType <Property>().FirstOrDefault(prop => prop.Name == "TargetFrameworkVersion");

                var extUrl       = extUrlProp?.Value as string;
                var frameworkVer = ((frameworkVerProp?.Value as string) ?? "v4.0").Substring(1);

                webPar = new WebsiteParameters()
                {
                    Runtime = new Version(frameworkVer) >= new Version(4, 0) ? Runtimes.Net4 : Runtimes.Net2,
                    Url     = extUrl
                };
            }

            var          client  = new DebugClient(appType, targetExe, webPar, outputDirectory);
            DebugSession session = await client.ConnectToServerAsync(ipAddress);

            await session.TransferFilesAsync();

            await session.WaitForAnswerAsync();

            IntPtr pInfo = GetDebugInfo(ipAddress, targetExe, outputDirectory);
            var    sp    = new ServiceProvider((IServiceProvider)_dte);

            try {
                var dbg = (IVsDebugger)sp.GetService(typeof(SVsShellDebugger));
                int hr  = dbg.LaunchDebugTargets(1, pInfo);
                Marshal.ThrowExceptionForHR(hr);

                DebuggedMonoProcess.Instance.AssociateDebugSession(session);
            } catch (Exception ex) {
                logger.Error(ex);
                string msg;
                var    sh = (IVsUIShell)sp.GetService(typeof(SVsUIShell));
                sh.GetErrorInfo(out msg);

                if (!string.IsNullOrWhiteSpace(msg))
                {
                    logger.Error(msg);
                }
                throw;
            } finally {
                if (pInfo != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(pInfo);
                }
            }
        }