예제 #1
0
        public ExtractMetadataWorker(ExtractMetadataInputModel input)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            if (string.IsNullOrEmpty(input.OutputFolder))
            {
                throw new ArgumentNullException(nameof(input.OutputFolder), "Output folder must be specified");
            }

            _files = input.Files?.Select(s => new FileInformation(s))
                     .GroupBy(f => f.Type)
                     .ToDictionary(s => s.Key, s => s.Distinct().ToList());
            _references = input.References?.Select(s => new FileInformation(s))
                          .Select(f => f.NormalizedPath)
                          .Distinct()
                          .ToList();
            _rebuild = input.ForceRebuild;

            var msbuildProperties = input.MSBuildProperties ?? new Dictionary <string, string>();

            if (!msbuildProperties.ContainsKey("Configuration"))
            {
                msbuildProperties["Configuration"] = "Release";
            }

            _options = new ExtractMetadataOptions
            {
                ShouldSkipMarkup          = input.ShouldSkipMarkup,
                PreserveRawInlineComments = input.PreserveRawInlineComments,
                FilterConfigFile          = input.FilterConfigFile != null ? new FileInformation(input.FilterConfigFile).NormalizedPath : null,
                MSBuildProperties         = msbuildProperties,
                CodeSourceBasePath        = input.CodeSourceBasePath,
                DisableDefaultFilter      = input.DisableDefaultFilter,
            };

            _useCompatibilityFileName = input.UseCompatibilityFileName;
            _outputFolder             = StringExtension.ToNormalizedFullPath(Path.Combine(EnvironmentContext.OutputDirectory, input.OutputFolder));

            _workspace = new Lazy <MSBuildWorkspace>(() =>
            {
                var workspace              = MSBuildWorkspace.Create(msbuildProperties);
                workspace.WorkspaceFailed += (s, e) =>
                {
                    Logger.LogWarning($"Workspace failed with: {e.Diagnostic}");
                };
                return(workspace);
            });

            var roslynLoader = new RoslynProjectLoader(_workspace);
            var fsharpLoader = new FSharpProjectLoader(msbuildProperties);

            _loader = new AbstractProjectLoader(new IProjectLoader[] { roslynLoader, fsharpLoader });
        }
예제 #2
0
        public AbstractProject TryLoad(string path, AbstractProjectLoader loader)
        {
            var ext = Path.GetExtension(path).ToLowerInvariant();

            if (ext == ".csproj" || ext == ".vbproj")
            {
                Logger.LogVerbose("Loading project...");
                var project = _workspace.Value.CurrentSolution.Projects.FirstOrDefault(
                    p => FilePathComparer.OSPlatformSensitiveRelativePathComparer.Equals(p.FilePath, path));
                var result = project ?? _workspace.Value.OpenProjectAsync(path).Result;
                Logger.LogVerbose($"Project {result.FilePath} loaded.");
                return(new RoslynProject(result));
            }
            else
            {
                return(null);
            }
        }