Пример #1
0
        private static void GenerateSolution(string outputFile, string platform, string inputFile)
        {
            if (outputFile == null)
            {
                throw new OptionException("Expect one output file", "o");
            }

            if (platform == null)
            {
                throw new OptionException("Platform not specified", "p");
            }

            string projectSuffix = platform;

            // Read .sln
            var solution = Solution.FromFile(inputFile);

            var processors = new List <IProjectProcessor>();

            ProjectType projectType;

            if (Enum.TryParse(platform, out projectType))
            {
                processors.Add(new SynchronizeProjectProcessor(projectType));
            }

            var projectProcessorContexts = new List <ProjectProcessorContext>();

            var removedProjects = new List <Project>();

            // Select active projects
            SelectActiveProjects(solution, platform, projectProcessorContexts, removedProjects);

            // Remove unnecessary project dependencies
            CleanProjectDependencies(projectProcessorContexts, removedProjects);

            // Process projects
            foreach (var context in projectProcessorContexts)
            {
                foreach (var processor in processors)
                {
                    processor.Process(context);
                }
            }

            // Update project references
            UpdateProjectReferences(projectProcessorContexts, projectSuffix);

            // Update solution with project that were recreated differently
            UpdateSolutionWithModifiedProjects(projectProcessorContexts, projectSuffix);

            // Rebuild solution configurations
            UpdateSolutionBuildConfigurations(platform, solution, projectProcessorContexts);

            // Remove empty solution folders
            RemoveEmptySolutionFolders(solution);

            // Save .sln
            solution.SaveAs(outputFile);

            // If there is a DotSettings (Resharper team shared file), create one that also reuse this one
            // Note: For now, it assumes input and output solutions are in the same folder (when constructing relative path to DotSetting file)
            var dotSettingsFile = inputFile + ".DotSettings";

            if (File.Exists(dotSettingsFile))
            {
                // Generate a deterministic GUID based on output file
                var cryptoProvider    = new System.Security.Cryptography.MD5CryptoServiceProvider();
                var inputBytes        = Encoding.Default.GetBytes(Path.GetFileName(outputFile));
                var deterministicGuid = new Guid(cryptoProvider.ComputeHash(inputBytes));

                var resharperDotSettingsGenerator = new ResharperDotSettings
                {
                    SharedSolutionDotSettings = new FileInfo(dotSettingsFile),
                    FileInjectedGuid          = deterministicGuid,
                };

                var outputDotSettingsFile = resharperDotSettingsGenerator.TransformText();
                File.WriteAllText(outputFile + ".DotSettings", outputDotSettingsFile);
            }
        }
Пример #2
0
        private static void GenerateSolution(string outputFile, string platform, string inputFile)
        {
            if (outputFile == null)
                throw new OptionException("Expect one output file", "o");

            if (platform == null)
                throw new OptionException("Platform not specified", "p");

            string projectSuffix = platform;

            // Read .sln
            var solution = Solution.FromFile(inputFile);

            var processors = new List<IProjectProcessor>();

            ProjectType projectType;
            if (Enum.TryParse(platform, out projectType))
            {
                processors.Add(new SynchronizeProjectProcessor(projectType));
            }

            var projectProcessorContexts = new List<ProjectProcessorContext>();

            var removedProjects = new List<Project>();

            // Select active projects
            SelectActiveProjects(solution, platform, projectProcessorContexts, removedProjects);

            // Remove unnecessary project dependencies
            CleanProjectDependencies(projectProcessorContexts, removedProjects);

            // Process projects
            foreach (var context in projectProcessorContexts)
            {
                foreach (var processor in processors)
                    processor.Process(context);
            }

            // Update project references
            UpdateProjectReferences(projectProcessorContexts, projectSuffix);

            // Update solution with project that were recreated differently
            UpdateSolutionWithModifiedProjects(projectProcessorContexts, projectSuffix);

            // Rebuild solution configurations
            UpdateSolutionBuildConfigurations(platform, solution, projectProcessorContexts);

            // Remove empty solution folders
            RemoveEmptySolutionFolders(solution);

            // Save .sln
            solution.SaveAs(outputFile);

            // If there is a DotSettings (Resharper team shared file), create one that also reuse this one
            // Note: For now, it assumes input and output solutions are in the same folder (when constructing relative path to DotSetting file)
            var dotSettingsFile = inputFile + ".DotSettings";
            if (File.Exists(dotSettingsFile))
            {
                // Generate a deterministic GUID based on output file
                var cryptoProvider = new System.Security.Cryptography.MD5CryptoServiceProvider();
                var inputBytes = Encoding.Default.GetBytes(Path.GetFileName(outputFile));
                var deterministicGuid = new Guid(cryptoProvider.ComputeHash(inputBytes));

                var resharperDotSettingsGenerator = new ResharperDotSettings
                {
                    SharedSolutionDotSettings = new FileInfo(dotSettingsFile),
                    FileInjectedGuid = deterministicGuid,
                };

                var outputDotSettingsFile = resharperDotSettingsGenerator.TransformText();
                File.WriteAllText(outputFile + ".DotSettings", outputDotSettingsFile);
            }
        }