MSProjFile ReloadProjectFile(FileSystem fs, IActivityMonitor m, Dictionary <NormalizedPath, MSProjFile> cache) { _file = MSProjFile.FindOrLoadProjectFile(fs, m, Path, cache); if (_file != null) { XElement f = _file.Document.Root .Elements("PropertyGroup") .Elements() .Where(x => x.Name.LocalName == "TargetFramework" || x.Name.LocalName == "TargetFrameworks") .SingleOrDefault(); if (f == null) { m.Error($"There must be one and only one TargetFramework or TargetFrameworks element in {Path}."); _file = null; } else { TargetFrameworks = Savors.FindOrCreate(f.Value); LangVersion = _file.Document.Root.Elements("PropertyGroup").Elements("LangVersion").LastOrDefault()?.Value; OutputType = _file.Document.Root.Elements("PropertyGroup").Elements("OutputType").LastOrDefault()?.Value; IsPackable = (bool?)_file.Document.Root.Elements("PropertyGroup").Elements("IsPackable").LastOrDefault(); DoInitializeDependencies(m); if (!_dependencies.IsInitialized) { _file = null; } } } if (_file == null) { TargetFrameworks = Savors.EmptyTrait; } return(_file); }
MSProjFile ReloadProjectFile(FileSystem fs, IActivityMonitor m, Dictionary <NormalizedPath, MSProjFile> cache) { _primaryFile = MSProjFile.FindOrLoadProjectFile(fs, m, Path, cache); if (_primaryFile != null) { XElement f = _primaryFile.Document.Root .Elements("PropertyGroup") .Elements() .Where(x => x.Name.LocalName == "TargetFramework" || x.Name.LocalName == "TargetFrameworks") .SingleOrDefault(); if (f == null) { m.Error($"There must be one and only one TargetFramework or TargetFrameworks element in {Path}."); _primaryFile = null; } else { TargetFrameworks = Savors.FindOrCreate(f.Value); LangVersion = _primaryFile.Document.Root.Elements("PropertyGroup").Elements("LangVersion").LastOrDefault()?.Value; OutputType = _primaryFile.Document.Root.Elements("PropertyGroup").Elements("OutputType").LastOrDefault()?.Value; IsPackable = (bool?)_primaryFile.Document.Root.Elements("PropertyGroup").Elements("IsPackable").LastOrDefault(); bool useMicrosoftBuildCentralPackageVersions = _primaryFile.Document.Root.Elements("Sdk") .Attributes("Name") .Any(a => a.Value == "Microsoft.Build.CentralPackageVersions"); if (useMicrosoftBuildCentralPackageVersions) { NormalizedPath packageFile; var definer = _primaryFile.AllFiles.Select(file => file.Document.Root) .SelectMany(root => root.Elements("PropertyGroup")) .Elements() .FirstOrDefault(e => e.Name.LocalName == "CentralPackagesFile"); if (definer != null) { m.Info($"Found Property '{definer}' that defines CentralPackagesFile."); var fileDefiner = _primaryFile.AllFiles.Single(file => file.Document == definer.Document); packageFile = definer.Value.Replace("$(MSBuildThisFileDirectory)", fileDefiner.Path.RemoveLastPart() + '/'); } else { packageFile = Solution.SolutionFolderPath.AppendPart("Packages.props"); } _centralPackagesFile = MSProjFile.FindOrLoadProjectFile(fs, m, packageFile, cache); if (_centralPackagesFile == null) { // Emits an error: reading the missing Version attribute will fail. m.Error($"Failed to read '{packageFile}' central package file."); } } DoInitializeDependencies(m); if (!_dependencies.IsInitialized) { _primaryFile = null; } } } if (_primaryFile == null) { TargetFrameworks = Savors.EmptyTrait; } return(_primaryFile); }