示例#1
0
        /// <summary>
        /// Determines whether the current project is Raspberry compatible, has Raspberry project
        /// settings and is enabled for debugging and returns the name of the target connection when
        /// these conditions are met.
        /// </summary>
        /// <returns>
        /// <c>null</c> if the project does not have Raspberry settings or is not an eligible
        /// .NET Core project, <see cref="ProjectSettings.DefaultConnectionName"/> when the project
        /// targets the default Raspberry connection, otherwise the name of the specific target
        /// connection will be returned.
        /// </returns>
        private string GetConnectionName()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (dte.Solution == null)
            {
                return(null);
            }

            var project = PackageHelper.GetStartupProject(dte.Solution);

            if (project == null)
            {
                return(null);
            }

            var projectProperties = ProjectProperties.CopyFrom(dte.Solution, project);

            if (!projectProperties.IsRaspberryCompatible)
            {
                return(null);
            }

            var projectSettings = PackageHelper.GetProjectSettings(dte.Solution, project);

            if (projectSettings == null || !projectSettings.EnableRemoteDebugging)
            {
                return(null);
            }

            return(projectSettings.RemoteDebugTarget ?? ProjectSettings.DefaultConnectionName);
        }
示例#2
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
#pragma warning disable VSTHRD100
        private async void Execute(object sender, EventArgs e)
#pragma warning restore VSTHRD100
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            if (dte.Solution == null)
            {
                return;
            }

            var project = PackageHelper.GetStartupProject(dte.Solution);

            if (project == null)
            {
                MessageBoxEx.Show(
                    "Please select a startup project using the Project/Set as Startup project menu or by right clicking a project in the Solution Explorer and enabling this.",
                    "Startup Project not found",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);

                return;
            }

            var targetFrameworkMonikers = (string)project.Properties.Item("TargetFrameworkMoniker").Value;
            var outputType = (int)project.Properties.Item("OutputType").Value;
            var monikers   = targetFrameworkMonikers.Split(',');
            var isNetCore  = monikers[0] == ".NETCoreApp";
            var sdkVersion = monikers[1].StartsWith("Version=v") ? monikers[1].Substring("Version=v".Length) : null;

            if (!isNetCore ||
                outputType != 1 /* EXE */ ||
                sdkVersion == null ||
                SemanticVersion.Parse(sdkVersion) < SemanticVersion.Parse("3.1"))
            {
                MessageBoxEx.Show(
                    "Raspberry debugging is not supported by this project type.  Only .NET Core applications targeting .NET Core 3.1 or greater are supported.",
                    "Unsupported Project Type",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning);

                return;
            }

            var raspberryProjects = PackageHelper.ReadRaspberryProjects(dte.Solution);
            var projectSettings   = raspberryProjects[project.UniqueName];
            var settingsDialog    = new SettingsDialog(projectSettings);

            if (settingsDialog.ShowDialog() == DialogResult.OK)
            {
                PackageHelper.WriteRaspberryProjects(dte.Solution, raspberryProjects);
            }
        }
示例#3
0
        /// <summary>
        /// Attempts to locate the startup project to be debugged, ensuring that it's
        /// eligable for Raspberry debugging.
        /// </summary>
        /// <param name="dte">The IDE.</param>
        /// <returns>The target project or <c>null</c> if there isn't a startup project or it wasn't eligible.</returns>
        public static Project GetTargetProject(DTE2 dte)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            // Identify the current startup project (if any).

            if (dte.Solution == null)
            {
                MessageBox.Show(
                    "Please open a Visual Studio solution.",
                    "Solution Required",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);

                return(null);
            }

            var project = PackageHelper.GetStartupProject(dte.Solution);

            if (project == null)
            {
                MessageBox.Show(
                    "Please select a startup project for your solution.",
                    "Startup Project Required",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);

                return(null);
            }

            // We need to capture the relevant project properties while we're still
            // on the UI thread so we'll have them on background threads.

            var projectProperties = ProjectProperties.CopyFrom(dte.Solution, project);

            if (!projectProperties.IsNetCore)
            {
                MessageBox.Show(
                    "Only .NET Core 3.1 or .NET 5 projects are supported for Raspberry debugging.",
                    "Invalid Project Type",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);

                return(null);
            }

            if (!projectProperties.IsExecutable)
            {
                MessageBox.Show(
                    "Only projects types that generate an executable program are supported for Raspberry debugging.",
                    "Invalid Project Type",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);

                return(null);
            }

            if (string.IsNullOrEmpty(projectProperties.SdkVersion))
            {
                MessageBox.Show(
                    "The .NET Core SDK version could not be identified.",
                    "Invalid Project Type",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);

                return(null);
            }

            var sdkVersion = Version.Parse(projectProperties.SdkVersion);

            if (!projectProperties.IsSupportedSdkVersion)
            {
                MessageBox.Show(
                    $"The .NET Core SDK [{sdkVersion}] is not currently supported.  Only .NET Core versions [v3.1] or later will ever be supported\r\n\r\nNote that we currently support only offical SDKs (not previews or release candidates) and we check for new .NET Core SDKs every week or two.  Submit an issue if you really need support for a new SDK ASAP:\r\n\t\nhttps://github.com/nforgeio/RaspberryDebugger/issues",
                    "SDK Not Supported",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);

                return(null);
            }

            if (projectProperties.AssemblyName.Contains(' '))
            {
                MessageBox.Show(
                    $"Your assembly name [{projectProperties.AssemblyName}] includes a space.  This isn't supported.",
                    "Unsupported Assembly Name",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);

                return(null);
            }

            return(project);
        }