Esempio n. 1
0
        public static void ActivateBridgeVsOnSolution(CommandAction action, List <Project> projects, string solutionName,
                                                      string vsVersion,
                                                      string vsEdition,
                                                      string solutionFolder)
        {
            Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();

            List <BridgeProjectInfo> executeParams = new List <BridgeProjectInfo>();

            //enable each individual project by mapping the assembly name and location to a registry entry
            foreach (Project project in projects)
            {
                string path       = project.Properties.Item("FullPath").Value.ToString();
                string outputPath = project.ConfigurationManager.ActiveConfiguration.Properties.Item("OutputPath").Value
                                    .ToString();
                string fileName          = project.Properties.Item("OutputFileName").Value.ToString();
                string projectOutputPath = Path.Combine(path, outputPath, fileName);

                string assemblyName             = project.Properties.Item("AssemblyName").Value.ToString();
                IEnumerable <string> references = Enumerable.Empty <string>();

                if (project.Object is VSProject vsProject && vsProject.References != null)
                {
                    references = from Reference reference in vsProject.References
                                 where reference.Path != null
                                 where reference.SourceProject == null                                                    //it means it's an assembly reference
                                 where !reference.Path.Contains(".NETFramework") && !reference.Path.Contains("Microsoft") //no .net framework assembly
                                 select reference.Path;
                }

                executeParams.Add(new BridgeProjectInfo(project.FullName, solutionName, assemblyName,
                                                        projectOutputPath, vsVersion, vsEdition, references.ToList()));
            }
            switch (action)
            {
            case CommandAction.Enable:
                CommonRegistryConfigurations.BridgeSolution(solutionName, vsVersion, executeParams);
                //copy directory build target to the solution folder
                string target = PackageConfigurator.GetInstallationFolder(vsVersion);
                File.Copy(Path.Combine(target, "Targets", DirectoryBuildTargets), Path.Combine(solutionFolder, DirectoryBuildTargets), true);
                break;

            case CommandAction.Disable:
                CommonRegistryConfigurations.UnBridgeSolution(solutionName, vsVersion);
                //delete directory build target
                File.Delete(Path.Combine(solutionFolder, DirectoryBuildTargets));
                break;
            }

            string result     = action == CommandAction.Enable ? "Bridged" : "Un-Bridged";
            string userAction = action == CommandAction.Enable ? "Please rebuild your solution." : string.Empty;
            string message    = $@"Solution {solutionName} has been {result}. {userAction}";

            MessageBox.Show(message);
        }