public MSBuildWorkspaceUpgradeContext( UpgradeOptions options, ITargetFrameworkMonikerFactory tfmFactory, IVisualStudioFinder vsFinder, IComponentIdentifier componentIdentifier, ILogger <MSBuildWorkspaceUpgradeContext> logger) { if (options is null) { throw new ArgumentNullException(nameof(options)); } if (vsFinder is null) { throw new ArgumentNullException(nameof(vsFinder)); } _projectCache = new Dictionary <string, IProject>(StringComparer.OrdinalIgnoreCase); InputPath = options.ProjectPath; TfmFactory = tfmFactory ?? throw new ArgumentNullException(nameof(tfmFactory)); _componentIdentifier = componentIdentifier ?? throw new ArgumentNullException(nameof(componentIdentifier)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); var vsPath = vsFinder.GetLatestVisualStudioPath(); if (vsPath is null) { throw new UpgradeException("Could not find a Visual Studio install to use for upgrade."); } _vsPath = vsPath; GlobalProperties = CreateProperties(); ProjectCollection = new ProjectCollection(globalProperties: GlobalProperties); }
public MSBuildWorkspaceUpgradeContext( UpgradeOptions options, IVisualStudioFinder vsFinder, IPackageRestorer restorer, ITargetFrameworkMonikerComparer comparer, IComponentIdentifier componentIdentifier, ILogger <MSBuildWorkspaceUpgradeContext> logger, IUpgradeContextProperties properties) { if (options is null) { throw new ArgumentNullException(nameof(options)); } if (vsFinder is null) { throw new ArgumentNullException(nameof(vsFinder)); } _projectCache = new Dictionary <string, IProject>(StringComparer.OrdinalIgnoreCase); InputPath = options.ProjectPath; _restorer = restorer; _comparer = comparer; _componentIdentifier = componentIdentifier ?? throw new ArgumentNullException(nameof(componentIdentifier)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _properties = properties ?? throw new ArgumentNullException(nameof(properties)); _vsPath = vsFinder.GetLatestVisualStudioPath(); GlobalProperties = CreateProperties(); ProjectCollection = new ProjectCollection(globalProperties: GlobalProperties); }
public bool IsComponent(IComponentIdentifier identifier) { bool result = false; MatchComponent(identifier, _ => result = true, true); return(result); }
public MSBuildProject(MSBuildWorkspaceUpgradeContext context, IComponentIdentifier componentIdentifier, string path, ILogger logger) { FilePath = path; Context = context; _componentIdentifier = componentIdentifier; _logger = logger; }
public MSBuildProject( MSBuildWorkspaceUpgradeContext context, IComponentIdentifier componentIdentifier, IPackageRestorer restorer, ITargetFrameworkMonikerComparer comparer, FileInfo file, ILogger logger) { FileInfo = file; Context = context; _componentIdentifier = componentIdentifier; _restorer = restorer; _comparer = comparer; _logger = logger; }
bool MatchComponent(IComponentIdentifier identifier, Action <IVariableComponent> onComponent, bool stopOnFirst) { bool anyMatch = false; foreach (var element in _components) { if (identifier.IsMatch(element)) { onComponent(element); anyMatch = true; if (stopOnFirst) { return(true); } } } return(anyMatch); }
/// <summary>Invalidates a component. This will add a diagnostic error and prevent the component from being applied to the variable.</summary> public void RejectComponent(IComponentIdentifier rejectComponent) => MatchComponent(rejectComponent, component => { component.WasRejected = true; Diagnostics.Error(component.RejectMessage(), component.Range); }, false);