Ejemplo n.º 1
0
        private IDictionary <string, string> GetGlobalProperties()
        {
            IDictionary <string, string> globalProperties;

            if (InheritGlobalProperties && BuildEngine.TryGetProjectInstance(out ProjectInstance projectInstance))
            {
                // Clone the properties since they will be modified
                globalProperties = new Dictionary <string, string>(projectInstance.GlobalProperties, StringComparer.OrdinalIgnoreCase);

                foreach (string propertyToRemove in SlnGenUtility.ParseList(GlobalPropertiesToRemove).Where(i => globalProperties.ContainsKey(i)))
                {
                    globalProperties.Remove(propertyToRemove);
                }
            }
            else
            {
                globalProperties = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
            }

            foreach (KeyValuePair <string, string> globalProperty in SlnGenUtility.ParseProperties(GlobalProperties))
            {
                globalProperties[globalProperty.Key] = globalProperty.Value;
            }

            if (globalProperties.Count > 0)
            {
                Log.LogMessageFromText("Global Properties:", MessageImportance.Low);
                foreach (KeyValuePair <string, string> globalProperty in globalProperties)
                {
                    Log.LogMessage(MessageImportance.Low, "  {0} = {1}", globalProperty.Key, globalProperty.Value);
                }
            }

            return(globalProperties);
        }
Ejemplo n.º 2
0
        /// <inheritdoc cref="Task.Execute()" />
        public override bool Execute()
        {
            ISlnGenLogger logger = new TaskLogger(BuildEngine);

            if (BuildingSolutionFile)
            {
                if (!File.Exists(SolutionFileFullPath))
                {
                    Log.LogError($"Could not find part of the path '{SolutionFileFullPath}'.");
                }
            }
            else
            {
                IDictionary <string, string> globalProperties = GetGlobalProperties();

                // Load up the full project closure
                ProjectCollection projectCollection = SlnGenUtility.LoadProjectsAndReferences(
                    globalProperties,
                    ToolsVersion,
                    BuildEngine,
                    CollectStats,
                    ProjectFullPath,
                    ProjectReferences,
                    logger);

                // Return if loading projects logged any errors
                if (!Log.HasLoggedErrors)
                {
                    SlnGenUtility.GenerateSolutionFile(
                        projectCollection,
                        SolutionFileFullPath,
                        ProjectFullPath,
                        SlnProject.GetCustomProjectTypeGuids(CustomProjectTypeGuids),
                        Folders,
                        GetSolutionItems(),
                        logger);
                }
            }

            if (!Log.HasLoggedErrors && ShouldLaunchVisualStudio)
            {
                SlnGenUtility.LaunchVisualStudio(
                    DevEnvFullPath,
                    UseShellExecute,
                    SolutionFileFullPath,
                    logger);
            }

            return(!Log.HasLoggedErrors);
        }
Ejemplo n.º 3
0
        private int Generate()
        {
            using (SlnGenTelemetryData telemetryData = new SlnGenTelemetryData
            {
                DevEnvFullPathSpecified = !_programArguments.DevEnvFullPath.IsNullOrWhitespace(),
                EntryProjectCount = _programArguments.Projects.Length,
                Folders = _programArguments.Folders,
                LaunchVisualStudio = _programArguments.LaunchVisualStudio,
                SolutionFileFullPathSpecified = !_programArguments.SolutionFileFullPath.IsNullOrWhitespace(),
                UseBinaryLogger = _programArguments.BinaryLogger.HasValue,
                UseFileLogger = _programArguments.FileLoggerParameters.HasValue,
                UseShellExecute = _programArguments.UseShellExecute,
            })
            {
                _logger.LogMessageHigh("Loading project references...");

                Stopwatch sw = Stopwatch.StartNew();

                IDictionary <string, string> globalProperties = new Dictionary <string, string>
                {
                    ["BuildingProject"] = "false",
                    ["DesignTimeBuild"] = "true",
                    ["ExcludeRestorePackageImports"] = "true",
                };

                ICollection <ProjectGraphEntryPoint> entryProjects = _programArguments.GetProjects(_logger).Select(i => new ProjectGraphEntryPoint(i, globalProperties)).ToList();

                _ = new ProjectGraph(entryProjects, _projectCollection, CreateProjectInstance);

                sw.Stop();

                _logger.LogMessageNormal($"Loaded {_projectCollection.LoadedProjects.Count} project(s) in {sw.ElapsedMilliseconds:N2}ms");

                telemetryData.ProjectEvaluationMilliseconds = sw.ElapsedMilliseconds;
                telemetryData.ProjectEvaluationCount        = _projectCollection.LoadedProjects.Count;

                Project project = _projectCollection.LoadedProjects.First();

                Dictionary <string, Guid> customProjectTypeGuids = SlnProject.GetCustomProjectTypeGuids(project.GetItems("SlnGenCustomProjectTypeGuid").Select(i => new MSBuildProjectItem(i)));

                IReadOnlyCollection <string> solutionItems = SlnFile.GetSolutionItems(project.GetItems("SlnGenSolutionItem").Select(i => new MSBuildProjectItem(i)), _logger).ToList();

                telemetryData.CustomProjectTypeGuidCount = customProjectTypeGuids.Count;

                telemetryData.SolutionItemCount = solutionItems.Count;

                string solutionFileFullPath = SlnGenUtility.GenerateSolutionFile(
                    _projectCollection,
                    solutionFileFullPath: null,
                    projectFileFullPath: entryProjects.First().ProjectFile,
                    customProjectTypeGuids: customProjectTypeGuids,
                    folders: _programArguments.Folders,
                    solutionItems: solutionItems,
                    logger: _logger);

                if (_programArguments.LaunchVisualStudio)
                {
                    SlnGenUtility.LaunchVisualStudio(_programArguments.DevEnvFullPath, _programArguments.UseShellExecute, solutionFileFullPath, _logger);
                }

                return(_logger.HasLoggedErrors ? 1 : 0);
            }
        }