Пример #1
0
        private string CreateCommandLineArgsForProject(IVsHierarchy project)
        {
            if (project == null)
            {
                return(null);
            }

            IEnumerable <CmdArgument> checkedArgs = ToolWindowViewModel.TreeViewModel.Projects.GetValueOrDefault(project.GetGuid())?.CheckedArguments;

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

            string projConfig = project.GetProject()?.ConfigurationManager?.ActiveConfiguration?.ConfigurationName;

            if (projConfig != null)
            {
                checkedArgs = checkedArgs.Where(x => { var conf = x.UsedProjectConfig; return(conf == null || conf == projConfig); });
            }

            if (project.IsCpsProject())
            {
                var activeLaunchProfile = SmartCmdArgs15.CpsProjectSupport.GetActiveLaunchProfileName(project.GetProject());
                if (activeLaunchProfile != null)
                {
                    checkedArgs = checkedArgs.Where(x => { var prof = x.UsedLaunchProfile; return(prof == null || prof == activeLaunchProfile); });
                }
            }

            IEnumerable <string> enabledEntries;

            if (IsMacroEvaluationEnabled)
            {
                enabledEntries = checkedArgs.Select(
                    e => msBuildPropertyRegex.Replace(e.Value,
                                                      match => vsHelper.GetMSBuildPropertyValueForActiveConfig(project, match.Groups["propertyName"].Value) ?? match.Value));
            }
            else
            {
                enabledEntries = checkedArgs.Select(e => e.Value);
            }
            return(string.Join(" ", enabledEntries));
        }
Пример #2
0
        private string CreateCommandLineArgsForProject(IVsHierarchy project)
        {
            if (project == null)
            {
                return(null);
            }

            var projectCmd = ToolWindowViewModel.TreeViewModel.Projects.GetValueOrDefault(project.GetGuid());

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

            string projConfig = project.GetProject()?.ConfigurationManager?.ActiveConfiguration?.ConfigurationName;

            string activeLaunchProfile = null;

            if (project.IsCpsProject())
            {
                activeLaunchProfile = SmartCmdArgs15.CpsProjectSupport.GetActiveLaunchProfileName(project.GetProject());
            }

            string MacroEvaluation(string arg)
            {
                if (!IsMacroEvaluationEnabled)
                {
                    return(arg);
                }

                return(msBuildPropertyRegex.Replace(arg,
                                                    match => vsHelper.GetMSBuildPropertyValueForActiveConfig(project, match.Groups["propertyName"].Value) ?? match.Value));
            }

            string JoinContainer(CmdContainer con)
            {
                IEnumerable <CmdBase> items = con.Items.Where(x => x.IsChecked != false);

                if (projConfig != null)
                {
                    items = items.Where(x => { var conf = x.UsedProjectConfig; return(conf == null || conf == projConfig); });
                }

                if (activeLaunchProfile != null)
                {
                    items = items.Where(x => { var prof = x.UsedLaunchProfile; return(prof == null || prof == activeLaunchProfile); });
                }

                return(string.Join(con.Delimiter, items.Select(x => x is CmdContainer c ? JoinContainer(c) : MacroEvaluation(x.Value))));
            }

            return(JoinContainer(projectCmd));
        }