Пример #1
0
        public bool TryFindLatestExcel(out string excelExePath)
        {
            excelExePath = null;

            _log.Debug("Trying to find latest version of Excel");

            var versions = (ExcelVersions[])Enum.GetValues(typeof(ExcelVersions));
            var versionsNumbersDescending = versions.Select(v => (int)v).OrderByDescending(vn => vn);

            foreach (var versionNumber in versionsNumbersDescending)
            {
                _log.Debug($"Trying to find {versionNumber} installed");

                var keyPath = $@"Software\Microsoft\Office\{versionNumber}.0\Excel\InstallRoot";

                if (!TryGetExcelExePathFromRegistry(keyPath, out excelExePath))
                {
                    continue;
                }

                return(true);
            }

            return(false);
        }
Пример #2
0
        public bool TrySetDebuggerOptions(string projectName, string excelExePath, string excelAddInToDebug)
        {
            using (var dte = new DevToolsEnvironment(_log))
            {
                var project = dte.GetProjectByName(projectName);
                if (project != null)
                {
                    _log.Debug($"Found project: {project.Name}");
                    var configuration = project
                                        .ConfigurationManager
                                        .ActiveConfiguration;

                    var startAction    = configuration.Properties.Item("StartAction");
                    var startProgram   = configuration.Properties.Item("StartProgram");
                    var startArguments = configuration.Properties.Item("StartArguments");

                    startAction.Value    = 1; // Start external program
                    startProgram.Value   = excelExePath;
                    startArguments.Value = string.Format(@"""{0}""", Path.GetFileName(excelAddInToDebug));

                    project.Save(string.Empty);

                    return(true);
                }
            }

            return(false);
        }
Пример #3
0
        public bool TrySetDebuggerOptions(string projectName, string excelExePath, string excelAddInToDebug)
        {
            try
            {
                MessageFilter.Register();

                var project = _dte.GetProjectByName(projectName);
                if (project != null)
                {
                    _log.Debug($"Found project: {project.Name}");
                    var configuration = project
                                        .ConfigurationManager
                                        .ActiveConfiguration;

                    var startAction    = configuration.Properties.Item("StartAction");
                    var startProgram   = configuration.Properties.Item("StartProgram");
                    var startArguments = configuration.Properties.Item("StartArguments");

                    startAction.Value    = 1; // Start external program
                    startProgram.Value   = excelExePath;
                    startArguments.Value = $@"""{Path.GetFileName(excelAddInToDebug)}""";

                    project.Save(string.Empty);

                    return(true);
                }

                return(false);
            }
            finally
            {
                MessageFilter.Revoke();
            }
        }
        public EnvDTE.Project GetProjectByName(string projectName)
        {
            _log.Debug("Starting GetProjectByName");

            foreach (var dte in EnumerateDevToolsEnvironments())
            {
                if (!TryFindCurrentProject(dte, projectName, out var project))
                {
                    _log.Debug($"Project {projectName} was not inside instance of DTE {dte.Name}");
                    continue;
                }

                _log.Debug($"Found project {projectName} inside DTE {dte.Name}");
                return(project);
            }

            return(null);
        }
Пример #5
0
        public override bool Execute()
        {
            try
            {
                _log.Debug("Running CleanExcelAddIn MSBuild Task");

                LogDiagnostics();

                FilesInProject = FilesInProject ?? new ITaskItem[0];
                _log.Debug("Number of files in project: " + FilesInProject.Length);

                _common = new BuildTaskCommon(FilesInProject, OutDirectory, FileSuffix32Bit, FileSuffix64Bit, ProjectName, AddInFileName);

                var existingBuiltFiles = _common.GetBuildItemsForDnaFiles();
                _packedFilesToDelete = GetPackedFilesToDelete(existingBuiltFiles);

                // Get the packed name versions : Refactor this + build items
                DeleteAddInFiles(existingBuiltFiles);
                DeletePackedAddInFiles(_packedFilesToDelete);

                return(true);
            }
            catch (Exception ex)
            {
                _log.Error(ex, ex.Message);
                _log.Error(ex, ex.ToString());
                return(false);
            }
        }
Пример #6
0
        public override bool Execute()
        {
            try
            {
                _log.Debug("Running SetDebuggerOptions MSBuild Task");

                // Create instances of ExcelDetector and ExcelDnaProject
                _excelDetector = _excelDetectorLazy.Value;
                _project       = _projectLazy.Value;

                FilesInProject = FilesInProject ?? new ITaskItem[0];
                _log.Debug("Number of files in project: " + FilesInProject.Length);

                var excelExePath      = GetExcelPath();
                var addInForDebugging = GetAddInForDebugging(excelExePath);

                LogDiagnostics();

                if (!_project.TrySetDebuggerOptions(ProjectName, excelExePath, addInForDebugging))
                {
                    const string message = "Unable to set the debugger options within Visual Studio. " +
                                           "Please restart Visual Studio and try again.";
                    _log.Warning("DNA" + "PROJECT".GetHashCode(), message);
                }
            }
            catch (Exception ex)
            {
                _log.Warning(ex, ex.Message);
            }

            // Setting the debugger options is not essential to the build process, thus if anything
            // goes wrong, we'll report errors and warnings, but will not fail the build because of that
            return(true);
        }
Пример #7
0
        public override bool Execute()
        {
            try
            {
                _log.Debug("Running CreateExcelAddIn MSBuild Task");

                LogDiagnostics();

                RunSanityChecks();

                _dnaFilesToPack = new List <ITaskItem>();
                DnaFilesToPack  = new ITaskItem[0];

                FilesInProject = FilesInProject ?? new ITaskItem[0];
                _log.Debug("Number of files in project: " + FilesInProject.Length);

                _configFilesInProject = GetConfigFilesInProject();
                _common = new BuildTaskCommon(FilesInProject, OutDirectory, FileSuffix32Bit, FileSuffix64Bit);

                var buildItemsForDnaFiles = _common.GetBuildItemsForDnaFiles();

                TryBuildAddInFor32Bit(buildItemsForDnaFiles);

                _log.Information("---", MessageImportance.High);

                TryBuildAddInFor64Bit(buildItemsForDnaFiles);

                DnaFilesToPack = _dnaFilesToPack.ToArray();

                return(true);
            }
            catch (Exception ex)
            {
                _log.Error(ex, ex.Message);
                _log.Error(ex, ex.ToString());
                return(false);
            }
        }