/// <summary>
        /// Builds the requested target framework(s).
        /// </summary>
        /// <param name="targetFrameworks">The set of target frameworks to build.</param>
        /// <param name="environmentOptions">The environment options to use for the build.</param>
        /// <returns>A dictionary of target frameworks to <see cref="AnalyzerResult"/>.</returns>
        public AnalyzerResults Build(string[] targetFrameworks, EnvironmentOptions environmentOptions)
        {
            if (environmentOptions == null)
            {
                throw new ArgumentNullException(nameof(environmentOptions));
            }

            // If the set of target frameworks is empty, just build the default
            if (targetFrameworks == null || targetFrameworks.Length == 0)
            {
                targetFrameworks = new string[] { null };
            }

            // Create a new build envionment for each target
            AnalyzerResults results = new AnalyzerResults();

            foreach (string targetFramework in targetFrameworks)
            {
                BuildEnvironment buildEnvironment = EnvironmentFactory.GetBuildEnvironment(targetFramework, environmentOptions);
                string[]         targetsToBuild   = buildEnvironment.TargetsToBuild;
                Restore(buildEnvironment, ref targetsToBuild);
                results.Add(BuildTargets(buildEnvironment, targetFramework, targetsToBuild, true));
            }

            return(results);
        }
Beispiel #2
0
        internal ProjectAnalyzer(AnalyzerManager manager, string projectFilePath, XDocument projectDocument)
        {
            Manager         = manager;
            ProjectFilePath = projectFilePath;
            var projectFolder = Path.GetDirectoryName(projectFilePath);

            _projectDocument = TweakProjectDocument(projectDocument, projectFolder);

            // Get the paths
            _buildEnvironment = EnvironmentFactory.GetBuildEnvironment(projectFilePath, _projectDocument);

            // Preload/enforce referencing some required assemblies
            // ReSharper disable once UnusedVariable
            var copy = new Copy();


            var solutionDir = manager.SolutionDirectory ?? projectFolder;

            _globalProperties = _buildEnvironment.GetGlobalProperties(solutionDir);

            // Create the logger
            if (manager.ProjectLogger != null)
            {
                _logger = new ConsoleLogger(manager.LoggerVerbosity, x => manager.ProjectLogger.LogInformation(x), null, null);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Builds the requested target framework(s).
        /// </summary>
        /// <param name="targetFrameworks">The set of target frameworks to build.</param>
        /// <param name="environmentOptions">The environment options to use for the build.</param>
        /// <returns>A dictionary of target frameworks to <see cref="AnalyzerResult"/>.</returns>
        public AnalyzerResults Build(string[] targetFrameworks, EnvironmentOptions environmentOptions)
        {
            if (environmentOptions == null)
            {
                throw new ArgumentNullException(nameof(environmentOptions));
            }

            // If the set of target frameworks is empty, just build the default
            if (targetFrameworks == null || targetFrameworks.Length == 0)
            {
                targetFrameworks = new string[] { null };
            }

            // Reset the cache before every build in case MSBuild cached something from a project reference build
            Manager.BuildManager.ResetCaches();

            // Create a new build envionment for each target
            AnalyzerResults results = new AnalyzerResults();

            foreach (string targetFramework in targetFrameworks)
            {
                BuildEnvironment buildEnvironment = EnvironmentFactory.GetBuildEnvironment(targetFramework, environmentOptions);
                string[]         targetsToBuild   = buildEnvironment.TargetsToBuild;
                Restore(buildEnvironment, ref targetsToBuild);
                results.Add(BuildTargets(buildEnvironment, targetFramework, targetsToBuild));
            }

            return(results);
        }
        /// <summary>
        /// Builds a specific target framework.
        /// </summary>
        /// <param name="targetFramework">The target framework to build.</param>
        /// <param name="environmentOptions">The environment options to use for the build.</param>
        /// <returns>The result of the build process.</returns>
        public AnalyzerResults Build(string targetFramework, EnvironmentOptions environmentOptions)
        {
            if (environmentOptions == null)
            {
                throw new ArgumentNullException(nameof(environmentOptions));
            }

            return(Build(targetFramework, EnvironmentFactory.GetBuildEnvironment(targetFramework, environmentOptions)));
        }
Beispiel #5
0
        public Project Load(EnvironmentOptions environmentOptions)
        {
            if (environmentOptions == null)
            {
                throw new ArgumentNullException(nameof(environmentOptions));
            }

            return(Load(null, EnvironmentFactory.GetBuildEnvironment(environmentOptions)));
        }
Beispiel #6
0
        public Project Load(string targetFramework, EnvironmentOptions environmentOptions)
        {
            if (environmentOptions == null)
            {
                throw new ArgumentNullException(nameof(environmentOptions));
            }

            return(Load(targetFramework, EnvironmentFactory.GetBuildEnvironment(targetFramework, environmentOptions)));
        }
Beispiel #7
0
        /// <summary>
        /// Builds all target framework(s) with the specified build environment options.
        /// </summary>
        /// <param name="environmentOptions">The environment options to use for the build.</param>
        /// <returns>A dictionary of target frameworks to <see cref="AnalyzerResult"/>.</returns>
        public AnalyzerResults BuildAllTargetFrameworks(EnvironmentOptions environmentOptions)
        {
            if (environmentOptions == null)
            {
                throw new ArgumentNullException(nameof(environmentOptions));
            }

            // Load the project with the default build environment to get the evaluated target frameworks
            Project project = Load(EnvironmentFactory.GetBuildEnvironment(environmentOptions));

            // Get all evaluated target frameworks from the Project and build them
            // but don't worry about getting a single target framework, it'll build the default
            string[] targetFrameworks = ProjectFile.GetTargetFrameworks(
                new[] { project.GetPropertyValue(ProjectFileNames.TargetFrameworks) }, null, null);

            return(Build(targetFrameworks, environmentOptions));
        }
Beispiel #8
0
        internal ProjectAnalyzer(AnalyzerManager manager, string projectFilePath, XDocument projectDocument)
        {
            Manager          = manager;
            ProjectFilePath  = projectFilePath;
            _projectDocument = TweakProjectDocument(projectDocument);

            // Get the paths
            _buildEnvironment = EnvironmentFactory.GetBuildEnvironment(projectFilePath, _projectDocument);

            // Preload/enforce referencing some required asemblies
            Copy copy = new Copy();

            // Set global properties
            string solutionDir = manager.SolutionDirectory ?? Path.GetDirectoryName(projectFilePath);

            _globalProperties = _buildEnvironment.GetGlobalProperties(solutionDir);

            // Create the logger
            if (manager.ProjectLogger != null)
            {
                _logger = new ConsoleLogger(manager.LoggerVerbosity, x => LoggerExtensions.LogInformation(manager.ProjectLogger, x), null, null);
            }
        }
        internal ProjectAnalyzer(AnalyzerManager manager, string projectFilePath, XDocument projectDocument, BuildEnvironment buildEnvironment)
        {
            Manager          = manager;
            ProjectFilePath  = projectFilePath;
            _projectDocument = TweakProjectDocument(manager, projectDocument ?? XDocument.Load(projectFilePath));

            // Get the paths
            _buildEnvironment = buildEnvironment ?? EnvironmentFactory.GetBuildEnvironment(projectFilePath, _projectDocument);

            // Preload/enforce referencing some required asemblies
            Copy copy = new Copy();

            // Set the solution directory global property
            string solutionDir = manager.SolutionDirectory ?? Path.GetDirectoryName(projectFilePath);

            SetGlobalProperty(MsBuildProperties.SolutionDir, solutionDir);

            // Create the logger
            if (manager.ProjectLogger != null)
            {
                _logger = new ConsoleLogger(manager.LoggerVerbosity, x => manager.ProjectLogger.LogInformation(x), null, null);
            }
        }
Beispiel #10
0
 /// <summary>
 /// Builds a specific target framework.
 /// </summary>
 /// <param name="targetFramework">The target framework to build.</param>
 /// <returns>The result of the build process.</returns>
 public AnalyzerResults Build(string targetFramework) =>
 Build(targetFramework, EnvironmentFactory.GetBuildEnvironment(targetFramework));
Beispiel #11
0
 /// <inheritdoc/>
 public IAnalyzerResults Build(string targetFramework, EnvironmentOptions environmentOptions) =>
 Build(
     targetFramework,
     EnvironmentFactory.GetBuildEnvironment(
         targetFramework,
         environmentOptions ?? throw new ArgumentNullException(nameof(environmentOptions))));
Beispiel #12
0
 public Project Load() =>
 Load(null, EnvironmentFactory.GetBuildEnvironment());
Beispiel #13
0
 public Project Load(string targetFramwork) =>
 Load(targetFramwork, EnvironmentFactory.GetBuildEnvironment(targetFramwork));