public bool CleanProject(IVsOutputWindowPane outputPanel) {
            var dteProject = GetDteProject();
            var projectPath = dteProject.FullName;

            // Compute solution path by removing the unique name of the project from the project path.
            var solutionPath = string.Empty;

            if (dteProject.FullName.EndsWith(dteProject.UniqueName))
                solutionPath = dteProject.FullName.Substring(0,
                    dteProject.FullName.Length - dteProject.UniqueName.Length);

            // Expecting no build running... But somehow a build is running, just end it and then start our own.
            try {
                BuildManager.DefaultBuildManager.EndBuild();
            }
            catch {

            }

            var logger = new AccumulatingLogger(solutionPath);

            // Build the project.
            var project = ProjectCollection.GlobalProjectCollection
                .LoadProject(projectPath);

            var result = project.Build("Clean", new[] { logger });
            
            // Output accumulated log messages.
            logger.Flush(outputPanel);

            return result;
        }
        public bool BuildProject(IVsOutputWindowPane outputPanel)
        {
            var dteProject = GetDteProject();
            var activeConfiguration = dteProject.ConfigurationManager.ActiveConfiguration;

            var projectPath = dteProject.FullName;
            var projectDirectory = Path.GetDirectoryName(projectPath);

            var outputPath = activeConfiguration.Properties.Item("OutputPath").Value.ToString();
            var outputDirectory = Path.GetDirectoryName(MakeAbsolutePath(outputPath, projectDirectory));

            // Compute solution path by removing the unique name of the project from the project path.
            var solutionPath = string.Empty;

            if (dteProject.FullName.EndsWith(dteProject.UniqueName))
                solutionPath = dteProject.FullName.Substring(0,
                    dteProject.FullName.Length - dteProject.UniqueName.Length);

            // Expecting no build running... But somehow a build is running, just end it and then start our own.
            try
            {
                BuildManager.DefaultBuildManager.EndBuild();
            }
            catch
            {
                
            }

            var logger = new AccumulatingLogger(solutionPath);

            // Build the project.
            var project = ProjectCollection.GlobalProjectCollection
                .LoadProject(projectPath);

            var result = project.Build(logger);

            foreach (var item in project.GetItems("Reference"))
            {
                var hintPath = item.GetMetadataValue("HintPath");

                if (string.IsNullOrWhiteSpace(hintPath))
                {
                    continue;
                }

                var fromPath = MakeAbsolutePath(hintPath, projectDirectory);

                if (!File.Exists(fromPath))
                {
                    continue;
                }

                var toPath = Path.Combine(outputDirectory, Path.GetFileName(fromPath));

                try
                {
                    File.Copy(fromPath, toPath, true);
                }
                catch(Exception e)
                {
                    throw new Exception("Could not copy reference. File is likely in use. (Server already running?)", e);
                }
            }

            // Output accumulated log messages.
            logger.Flush(outputPanel);

            return result;
        }