From d235d7062c597a599ff6843a246fe6f27428b708 Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Tue, 2 Jul 2019 15:58:02 +1000 Subject: [PATCH 1/5] Formatting --- .../Collections/DictionaryEqualityComparer.cs | 3 +- .../IO/IFileSystem.cs | 1 + .../IO/SimpleFileWatcher.cs | 33 ++++++++++--------- .../PooledObjects/PooledStringBuilder.cs | 1 - .../ActiveConfiguredProjectsProvider.cs | 8 +++++ ...itlyActiveConfiguredProjectReadyToBuild.cs | 2 ++ ...seProjectConfigurationDimensionProvider.cs | 1 - ...urationDimensionDescriptionMetadataView.cs | 1 - ...ProjectConfigurationDimensionsProvider4.cs | 4 ++- .../Debug/IActiveDebugFrameworkServices.cs | 8 ++--- .../Extensibility/IProjectExportProvider.cs | 2 +- .../IActiveConfiguredProjectsProvider.cs | 5 +-- .../Imaging/ProjectImageProviderAggregator.cs | 4 ++- 13 files changed, 44 insertions(+), 29 deletions(-) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Collections/DictionaryEqualityComparer.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Collections/DictionaryEqualityComparer.cs index 40472344b83..6ac004f2b00 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Collections/DictionaryEqualityComparer.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Collections/DictionaryEqualityComparer.cs @@ -52,6 +52,7 @@ public int GetHashCode(IImmutableDictionary obj) var concreteDictionary1 = obj as ImmutableDictionary; IEqualityComparer keyComparer = concreteDictionary1 != null ? concreteDictionary1.KeyComparer : EqualityComparer.Default; IEqualityComparer valueComparer = concreteDictionary1 != null ? concreteDictionary1.ValueComparer : EqualityComparer.Default; + if (obj != null) { foreach (KeyValuePair pair in obj) @@ -68,6 +69,7 @@ public int GetHashCode(IImmutableDictionary obj) private static bool AreEquivalent(IImmutableDictionary dictionary1, IImmutableDictionary dictionary2) { Requires.NotNull(dictionary1, "dictionary1"); + if (dictionary1 == dictionary2) { return true; @@ -116,6 +118,5 @@ private static bool AreEquivalent(IReadOnlyDictionary dictionary1, return true; } - } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/IO/IFileSystem.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/IO/IFileSystem.cs index c7964f0b52b..2f70e934a00 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/IO/IFileSystem.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/IO/IFileSystem.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.IO; using System.Text; + using Microsoft.VisualStudio.Composition; using Microsoft.VisualStudio.ProjectSystem; diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/IO/SimpleFileWatcher.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/IO/SimpleFileWatcher.cs index af25b03bd50..b20d0bfdfbd 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/IO/SimpleFileWatcher.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/IO/SimpleFileWatcher.cs @@ -12,7 +12,7 @@ namespace Microsoft.VisualStudio.IO /// internal sealed class SimpleFileWatcher : IDisposable { - private FileSystemWatcher FileWatcher { get; set; } + private FileSystemWatcher _fileWatcher; private FileSystemEventHandler _handler; private RenamedEventHandler _renameHandler; @@ -22,9 +22,9 @@ public SimpleFileWatcher() } public SimpleFileWatcher(string dirToWatch, bool includeSubDirs, NotifyFilters notifyFilters, string fileFilter, - FileSystemEventHandler handler, RenamedEventHandler renameHandler) + FileSystemEventHandler handler, RenamedEventHandler renameHandler) { - FileWatcher = new FileSystemWatcher(dirToWatch) + _fileWatcher = new FileSystemWatcher(dirToWatch) { IncludeSubdirectories = includeSubDirs, NotifyFilter = notifyFilters, @@ -33,16 +33,17 @@ public SimpleFileWatcher(string dirToWatch, bool includeSubDirs, NotifyFilters n if (handler != null) { - FileWatcher.Created += handler; - FileWatcher.Deleted += handler; - FileWatcher.Changed += handler; + _fileWatcher.Created += handler; + _fileWatcher.Deleted += handler; + _fileWatcher.Changed += handler; } if (renameHandler != null) { - FileWatcher.Renamed += renameHandler; + _fileWatcher.Renamed += renameHandler; } - FileWatcher.EnableRaisingEvents = true; + + _fileWatcher.EnableRaisingEvents = true; _handler = handler; _renameHandler = renameHandler; } @@ -52,23 +53,23 @@ public SimpleFileWatcher(string dirToWatch, bool includeSubDirs, NotifyFilters n /// public void Dispose() { - if (FileWatcher != null) + if (_fileWatcher != null) { - FileWatcher.EnableRaisingEvents = false; + _fileWatcher.EnableRaisingEvents = false; if (_handler != null) { - FileWatcher.Created += _handler; - FileWatcher.Deleted += _handler; - FileWatcher.Changed += _handler; + _fileWatcher.Created += _handler; + _fileWatcher.Deleted += _handler; + _fileWatcher.Changed += _handler; _handler = null; } if (_renameHandler != null) { - FileWatcher.Renamed += _renameHandler; + _fileWatcher.Renamed += _renameHandler; _renameHandler = null; } - FileWatcher.Dispose(); - FileWatcher = null; + _fileWatcher.Dispose(); + _fileWatcher = null; } } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledStringBuilder.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledStringBuilder.cs index 43f236ae52b..4de876164ec 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledStringBuilder.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledStringBuilder.cs @@ -57,7 +57,6 @@ public string ToStringAndFree(int startIndex, int length) // global pool private static readonly ObjectPool s_poolInstance = CreatePool(); - // if someone needs to create a private pool; /// /// If someone need to create a private pool /// diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ActiveConfiguredProjectsProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ActiveConfiguredProjectsProvider.cs index 75214f728e6..60bb2ea63bf 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ActiveConfiguredProjectsProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ActiveConfiguredProjectsProvider.cs @@ -82,6 +82,7 @@ public async Task> GetActiveConfi ActiveConfiguredObjects projects = await GetActiveConfiguredProjectsAsync(); bool isCrossTargeting = projects.Objects.All(project => project.ProjectConfiguration.IsCrossTargeting()); + if (isCrossTargeting) { foreach (ConfiguredProject project in projects.Objects) @@ -102,7 +103,9 @@ public async Task> GetActiveConfigure { ActiveConfiguredObjects configurations = await GetActiveProjectConfigurationsAsync(); if (configurations == null) + { return null; + } ImmutableArray.Builder builder = ImmutableArray.CreateBuilder(configurations.Objects.Count); @@ -119,8 +122,11 @@ public async Task> GetActiveConfigure public async Task> GetActiveProjectConfigurationsAsync() { ProjectConfiguration activeSolutionConfiguration = _services.ActiveConfiguredProjectProvider.ActiveProjectConfiguration; + if (activeSolutionConfiguration == null) + { return null; + } IImmutableSet configurations = await _services.ProjectConfigurationsService.GetKnownProjectConfigurationsAsync(); @@ -156,7 +162,9 @@ private static bool IsActiveConfigurationCandidate(ProjectConfiguration activeSo foreach ((string dimensionName, string dimensionValue) in activeSolutionConfiguration.Dimensions) { if (ignoredDimensionNames.Contains(dimensionName)) + { continue; + } if (!configuration.Dimensions.TryGetValue(dimensionName, out string otherDimensionValue) || !string.Equals(dimensionValue, otherDimensionValue, StringComparison.Ordinal)) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/ImplicitlyActiveConfiguredProjectReadyToBuild.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/ImplicitlyActiveConfiguredProjectReadyToBuild.cs index ba6099f94d8..f1dc16c9bfa 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/ImplicitlyActiveConfiguredProjectReadyToBuild.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/ImplicitlyActiveConfiguredProjectReadyToBuild.cs @@ -33,6 +33,7 @@ public ImplicitlyActiveConfiguredProjectReadyToBuild( private void ActiveConfiguredProject_Changed(object sender, ActiveConfigurationChangedEventArgs e) => GetLatestActivationTask(); public bool IsValidToBuild => GetLatestActivationTask().IsCompleted; + public Task WaitReadyToBuildAsync() => GetLatestActivationTask(); private Task GetLatestActivationTask() @@ -66,6 +67,7 @@ public void Dispose() private bool IsActive() { ProjectConfiguration activeConfig = _activeConfiguredProjectProvider.ActiveProjectConfiguration; + if (activeConfig == null) return false; diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/BaseProjectConfigurationDimensionProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/BaseProjectConfigurationDimensionProvider.cs index 623c29cc7b2..b16ef37b7e6 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/BaseProjectConfigurationDimensionProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/BaseProjectConfigurationDimensionProvider.cs @@ -220,6 +220,5 @@ private ProjectPropertyElement FindDimensionProperty(IEnumerable StringComparers.PropertyNames.Equals(PropertyName, p.Name) && BuildUtilities.HasWellKnownConditionsThatAlwaysEvaluateToTrue(p)); } - } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/IConfigurationDimensionDescriptionMetadataView.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/IConfigurationDimensionDescriptionMetadataView.cs index b58843c5098..0689b3caa47 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/IConfigurationDimensionDescriptionMetadataView.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/IConfigurationDimensionDescriptionMetadataView.cs @@ -1,6 +1,5 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - #nullable disable namespace Microsoft.VisualStudio.ProjectSystem.Configuration diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/IProjectConfigurationDimensionsProvider4.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/IProjectConfigurationDimensionsProvider4.cs index 6b152c032b9..aa1efa3c9d7 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/IProjectConfigurationDimensionsProvider4.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/IProjectConfigurationDimensionsProvider4.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Generic; using System.Collections.Immutable; using Microsoft.Build.Construction; diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/IActiveDebugFrameworkServices.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/IActiveDebugFrameworkServices.cs index 015c5507d73..7b3d352c09a 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/IActiveDebugFrameworkServices.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/IActiveDebugFrameworkServices.cs @@ -10,7 +10,7 @@ namespace Microsoft.VisualStudio.ProjectSystem.Debug { /// /// Wrapper around the active debug framework to provide a single implementation of what is considered the active framework. If there is - /// only one framework + /// only one framework. /// [ProjectSystemContract(ProjectSystemContractScope.UnconfiguredProject, ProjectSystemContractProvider.Private, Cardinality = ImportCardinality.ExactlyOne)] public interface IActiveDebugFrameworkServices @@ -21,17 +21,17 @@ public interface IActiveDebugFrameworkServices Task> GetProjectFrameworksAsync(); /// - /// Sets the value of the active debugging target framework property + /// Sets the value of the active debugging target framework property. /// Task SetActiveDebuggingFrameworkPropertyAsync(string activeFramework); /// - /// Returns the value of the property, or empty string/null if the property has never been set + /// Returns the value of the property, or empty string/null if the property has never been set. /// Task GetActiveDebuggingFrameworkPropertyAsync(); /// - /// Returns the configured project which represents the active framework. This is valid whether multi-targeting or not + /// Returns the configured project which represents the active framework. This is valid whether multi-targeting or not. /// Task GetConfiguredProjectForActiveFrameworkAsync(); } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Extensibility/IProjectExportProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Extensibility/IProjectExportProvider.cs index d869b375b3e..0ba9f3c9ebb 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Extensibility/IProjectExportProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Extensibility/IProjectExportProvider.cs @@ -16,7 +16,7 @@ public interface IProjectExportProvider /// /// Returns the export for the given project without having to go to the /// UI thread. This is the preferred method for getting access to project specific - /// exports + /// exports. /// T GetExport(string projectFilePath) where T : class; } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/IActiveConfiguredProjectsProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/IActiveConfiguredProjectsProvider.cs index 0bc78ea8bdb..6c1603f383b 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/IActiveConfiguredProjectsProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/IActiveConfiguredProjectsProvider.cs @@ -22,8 +22,9 @@ namespace Microsoft.VisualStudio.ProjectSystem internal interface IActiveConfiguredProjectsProvider { /// - /// Gets all the active configured projects by TargetFramework dimension for the current unconfigured project. - /// If the current project is not a cross-targeting project, then it returns a singleton key-value pair with an ignorable key and single active configured project as value. + /// Gets all the active configured projects by TargetFramework dimension for the current unconfigured project. + /// If the current project is not a cross-targeting project, then it returns a singleton key-value pair with an + /// ignorable key and single active configured project as value. /// /// Map from TargetFramework dimension to active configured project. [Obsolete("This method will be removed in a future build.")] diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Imaging/ProjectImageProviderAggregator.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Imaging/ProjectImageProviderAggregator.cs index 81236f00f52..3563ee50c19 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Imaging/ProjectImageProviderAggregator.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Imaging/ProjectImageProviderAggregator.cs @@ -36,9 +36,11 @@ public ProjectImageMoniker GetProjectImage(string key) foreach (Lazy provider in ImageProviders) { ProjectImageMoniker image = provider.Value.GetProjectImage(key); + if (image != null) + { return image; - + } } return null; From f098c3f7db5b6e1b7e561214195061f2b3fcc607 Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Tue, 2 Jul 2019 15:58:15 +1000 Subject: [PATCH 2/5] Argument validation --- .../ProjectSystem/ActiveConfiguredProjectsProvider.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ActiveConfiguredProjectsProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ActiveConfiguredProjectsProvider.cs index 60bb2ea63bf..a55a5a68a10 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ActiveConfiguredProjectsProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ActiveConfiguredProjectsProvider.cs @@ -63,6 +63,9 @@ internal class ActiveConfiguredProjectsProvider : IActiveConfiguredProjectsProvi [ImportingConstructor] public ActiveConfiguredProjectsProvider(IUnconfiguredProjectServices services, UnconfiguredProject project) { + Requires.NotNull(services, nameof(services)); + Requires.NotNull(project, nameof(project)); + _services = services; _project = project; From e9eedb7094e28e5555e8a5227f49ea5c032c4ae5 Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Tue, 2 Jul 2019 16:00:25 +1000 Subject: [PATCH 3/5] Add nullability annotations --- .../Actions/SearchGraphActionHandler.cs | 4 +-- .../Build/BuildExtensions.cs | 2 -- .../Build/BuildUtilities.cs | 8 ++--- .../Collections/DictionaryEqualityComparer.cs | 8 ++--- .../Collections/ImmutableStringDictionary.cs | 2 -- .../Collections/ImmutableStringHashSet.cs | 2 -- .../Composition/DeconstructionExtensions.cs | 2 -- .../IO/IFileSystem.cs | 2 -- .../IO/SimpleFileWatcher.cs | 10 +++---- .../IO/Win32FileSystem.cs | 2 -- .../PooledObjects/ObjectPool.cs | 10 +++---- .../PooledObjects/PooledDictionary.cs | 6 ++-- .../PooledObjects/PooledHashSet.cs | 6 ++-- .../PooledObjects/PooledStringBuilder.cs | 6 ++-- .../ActiveConfiguredProjectsProvider.cs | 20 ++++++++----- .../ProjectSystem/Build/BuildProperty.cs | 2 -- ...ndLineDesignTimeBuildPropertiesProvider.cs | 2 -- ...eOnBuildDesignTimeBuildPropertyProvider.cs | 2 -- .../GeneratePackageOnBuildPropertyProvider.cs | 2 -- ...itlyActiveConfiguredProjectReadyToBuild.cs | 10 +++---- .../Build/PublishableProjectConfigProvider.cs | 2 -- ...getFrameworkGlobalBuildPropertyProvider.cs | 2 -- ...pilerIfAvailableBuildPropertiesProvider.cs | 2 -- ...seProjectConfigurationDimensionProvider.cs | 24 +++++++-------- ...onProjectConfigurationDimensionProvider.cs | 15 ++++++---- .../Configuration/DimensionProviderOrder.cs | 2 -- ...tiveConfiguredProjectsDimensionProvider.cs | 2 -- ...urationDimensionDescriptionMetadataView.cs | 2 -- .../IImplicitlyActiveDimensionProvider.cs | 2 -- ...ProjectConfigurationDimensionsProvider4.cs | 2 -- .../ImplicitlyActiveDimensionProvider.cs | 2 -- ...rmProjectConfigurationDimensionProvider.cs | 11 ++++--- ...rkProjectConfigurationDimensionProvider.cs | 4 +-- .../Debug/ActiveDebugFrameworkServices.cs | 30 +++++++++++-------- .../Debug/IActiveDebugFrameworkServices.cs | 9 +++--- .../Extensibility/IProjectExportProvider.cs | 4 +-- .../Extensibility/ProjectExportProvider.cs | 6 ++-- .../IActiveConfiguredProjectsProvider.cs | 14 +++++---- .../ProjectSystem/IProjectAccessor.cs | 2 -- .../Imaging/IProjectImageProvider.cs | 4 +-- .../ProjectSystem/Imaging/ProjectImageKey.cs | 2 -- .../Imaging/ProjectImageProviderAggregator.cs | 7 ++--- .../Input/AbstractProjectCommand.cs | 6 ++-- .../Input/AbstractSingleNodeProjectCommand.cs | 6 ++-- .../Input/GetCommandStatusResult.cs | 2 -- .../Input/ProjectCommandAttribute.cs | 2 -- .../Resources/ManagedImageMonikers.cs | 2 -- ...regateCrossTargetProjectContextProvider.cs | 9 +++++- .../AggregateDependenciesSnapshotProvider.cs | 2 +- .../AppDesignerFolderProjectImageProvider.cs | 4 +-- .../CSharp/CSharpProjectImageProvider.cs | 4 +-- .../FSharp/FSharpProjectImageProvider.cs | 4 +-- .../VisualBasicProjectImageProvider.cs | 4 +-- 53 files changed, 121 insertions(+), 182 deletions(-) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/Actions/SearchGraphActionHandler.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/Actions/SearchGraphActionHandler.cs index 40f297bfa3b..8c0cc4ea1c4 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/Actions/SearchGraphActionHandler.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/Actions/SearchGraphActionHandler.cs @@ -108,10 +108,10 @@ private void Search(IGraphContext graphContext) cachedDependencyToMatchingResultsMap); } - cachedDependencyToMatchingResultsMap[topLevelDependency.Id] = topLevelDependencyMatches; + cachedDependencyToMatchingResultsMap[topLevelDependency.Id] = topLevelDependencyMatches!; } - if (topLevelDependencyMatches.Count == 0) + if (topLevelDependencyMatches!.Count == 0) { continue; } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Build/BuildExtensions.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Build/BuildExtensions.cs index 04177bfd830..401316d019a 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Build/BuildExtensions.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Build/BuildExtensions.cs @@ -5,8 +5,6 @@ using Microsoft.Build.Construction; using Microsoft.Build.Evaluation; -#nullable disable - namespace Microsoft.VisualStudio.Build { internal static class BuildExtensions diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Build/BuildUtilities.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Build/BuildUtilities.cs index 39072cfd818..772bbe37bb4 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Build/BuildUtilities.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Build/BuildUtilities.cs @@ -10,8 +10,6 @@ using Microsoft.VisualStudio.Buffers.PooledObjects; using Microsoft.VisualStudio.Text; -#nullable disable - namespace Microsoft.VisualStudio.Build { /// @@ -54,7 +52,7 @@ public static bool HasWellKnownConditionsThatAlwaysEvaluateToTrue(ProjectPropert /// Xml representation of the MsBuild project. /// Name of the property. /// Requested project property. Null if the property is not present. - public static ProjectPropertyElement GetProperty(ProjectRootElement project, string propertyName) + public static ProjectPropertyElement? GetProperty(ProjectRootElement project, string propertyName) { Requires.NotNull(project, "project"); @@ -70,7 +68,7 @@ public static ProjectPropertyElement GetProperty(ProjectRootElement project, str /// Collection of individual values in the property. public static IEnumerable GetPropertyValues(string propertyValue, char delimiter = ';') { - HashSet seen = null; + HashSet? seen = null; // We need to ensure that we return values in the specified order. foreach (string value in new LazyStringSplit(propertyValue, delimiter)) @@ -223,7 +221,7 @@ public static ProjectPropertyElement GetProperty(ProjectRootElement project, str public static ProjectPropertyElement GetOrAddProperty(ProjectRootElement project, string propertyName) { Requires.NotNull(project, "project"); - ProjectPropertyElement property = GetProperty(project, propertyName); + ProjectPropertyElement? property = GetProperty(project, propertyName); if (property != null) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Collections/DictionaryEqualityComparer.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Collections/DictionaryEqualityComparer.cs index 6ac004f2b00..8e7a86b1a73 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Collections/DictionaryEqualityComparer.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Collections/DictionaryEqualityComparer.cs @@ -3,8 +3,6 @@ using System.Collections.Generic; using System.Collections.Immutable; -#nullable disable - namespace Microsoft.VisualStudio.Collections { /// @@ -49,7 +47,7 @@ public int GetHashCode(IImmutableDictionary obj) { int hashCode = 0; - var concreteDictionary1 = obj as ImmutableDictionary; + ImmutableDictionary? concreteDictionary1 = obj as ImmutableDictionary; IEqualityComparer keyComparer = concreteDictionary1 != null ? concreteDictionary1.KeyComparer : EqualityComparer.Default; IEqualityComparer valueComparer = concreteDictionary1 != null ? concreteDictionary1.ValueComparer : EqualityComparer.Default; @@ -82,7 +80,7 @@ private static bool AreEquivalent(IImmutableDictionary dictionary1 /// /// Tests two dictionaries to see if their contents are identical. /// - private static bool AreEquivalent(IReadOnlyDictionary dictionary1, IReadOnlyDictionary dictionary2, IEqualityComparer valueComparer) + private static bool AreEquivalent(IReadOnlyDictionary? dictionary1, IReadOnlyDictionary? dictionary2, IEqualityComparer valueComparer) { Requires.NotNull(valueComparer, "valueComparer"); @@ -91,7 +89,7 @@ private static bool AreEquivalent(IReadOnlyDictionary dictionary1, return true; } - if ((dictionary1 == null) ^ (dictionary2 == null)) // XOR + if (dictionary1 == null || dictionary2 == null) { return false; } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Collections/ImmutableStringDictionary.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Collections/ImmutableStringDictionary.cs index fa18fb7db67..a41d8fdc569 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Collections/ImmutableStringDictionary.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Collections/ImmutableStringDictionary.cs @@ -1,7 +1,5 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#nullable disable - namespace System.Collections.Immutable { internal static class ImmutableStringDictionary diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Collections/ImmutableStringHashSet.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Collections/ImmutableStringHashSet.cs index b1321afc7f0..e95ac5c6c5a 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Collections/ImmutableStringHashSet.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Collections/ImmutableStringHashSet.cs @@ -1,7 +1,5 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#nullable disable - namespace System.Collections.Immutable { internal static class ImmutableStringHashSet diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Composition/DeconstructionExtensions.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Composition/DeconstructionExtensions.cs index aaf47edb61c..86e16ef3f49 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Composition/DeconstructionExtensions.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Composition/DeconstructionExtensions.cs @@ -1,7 +1,5 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#nullable disable - namespace System.Collections.Generic { internal static class DeconstructionExtensions diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/IO/IFileSystem.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/IO/IFileSystem.cs index 2f70e934a00..38578181401 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/IO/IFileSystem.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/IO/IFileSystem.cs @@ -8,8 +8,6 @@ using Microsoft.VisualStudio.Composition; using Microsoft.VisualStudio.ProjectSystem; -#nullable disable - namespace Microsoft.VisualStudio.IO { /// diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/IO/SimpleFileWatcher.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/IO/SimpleFileWatcher.cs index b20d0bfdfbd..01009686337 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/IO/SimpleFileWatcher.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/IO/SimpleFileWatcher.cs @@ -3,8 +3,6 @@ using System; using System.IO; -#nullable disable - namespace Microsoft.VisualStudio.IO { /// @@ -12,9 +10,9 @@ namespace Microsoft.VisualStudio.IO /// internal sealed class SimpleFileWatcher : IDisposable { - private FileSystemWatcher _fileWatcher; - private FileSystemEventHandler _handler; - private RenamedEventHandler _renameHandler; + private FileSystemWatcher? _fileWatcher; + private FileSystemEventHandler? _handler; + private RenamedEventHandler? _renameHandler; // For unit tests public SimpleFileWatcher() @@ -22,7 +20,7 @@ public SimpleFileWatcher() } public SimpleFileWatcher(string dirToWatch, bool includeSubDirs, NotifyFilters notifyFilters, string fileFilter, - FileSystemEventHandler handler, RenamedEventHandler renameHandler) + FileSystemEventHandler? handler, RenamedEventHandler? renameHandler) { _fileWatcher = new FileSystemWatcher(dirToWatch) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/IO/Win32FileSystem.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/IO/Win32FileSystem.cs index 3697d264d4f..4ac71613769 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/IO/Win32FileSystem.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/IO/Win32FileSystem.cs @@ -6,8 +6,6 @@ using System.IO; using System.Text; -#nullable disable - namespace Microsoft.VisualStudio.IO { /// diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/ObjectPool.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/ObjectPool.cs index 0bcd498ec36..42ea4d25915 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/ObjectPool.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/ObjectPool.cs @@ -4,8 +4,6 @@ using System.Diagnostics; using System.Threading; -#nullable disable - namespace Microsoft.VisualStudio.Buffers.PooledObjects { /// @@ -30,12 +28,12 @@ internal class ObjectPool where T : class [DebuggerDisplay("{Value,nq}")] private struct Element { - internal T Value; + internal T? Value; } // Storage for the pool objects. The first item is stored in a dedicated field because we // expect to be able to satisfy most requests from it. - private T _firstItem; + private T? _firstItem; private readonly Element[] _items; // factory is stored for the lifetime of the pool. We will call this only when pool needs to @@ -74,7 +72,7 @@ internal T Allocate() // Note that the initial read is optimistically not synchronized. That is intentional. // We will interlock only when we have a candidate. in a worst case we may miss some // recently returned objects. Not a big deal. - T inst = _firstItem; + T? inst = _firstItem; if (inst == null || inst != Interlocked.CompareExchange(ref _firstItem, null, inst)) { inst = AllocateSlow(); @@ -92,7 +90,7 @@ private T AllocateSlow() // Note that the initial read is optimistically not synchronized. That is intentional. // We will interlock only when we have a candidate. in a worst case we may miss some // recently returned objects. Not a big deal. - T inst = items[i].Value; + T? inst = items[i].Value; if (inst != null) { if (inst == Interlocked.CompareExchange(ref items[i].Value, null, inst)) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledDictionary.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledDictionary.cs index 992a9c7d538..708681adf0d 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledDictionary.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledDictionary.cs @@ -3,8 +3,6 @@ using System.Collections.Generic; using System.Collections.Immutable; -#nullable disable - namespace Microsoft.VisualStudio.Buffers.PooledObjects { // Dictionary that can be recycled via an object pool @@ -37,8 +35,8 @@ public void Free() // if someone needs to create a pool; public static ObjectPool> CreatePool() { - ObjectPool> pool = null; - pool = new ObjectPool>(() => new PooledDictionary(pool), 128); + ObjectPool>? pool = null; + pool = new ObjectPool>(() => new PooledDictionary(pool!), 128); return pool; } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledHashSet.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledHashSet.cs index 42a74de453a..f7e23949c13 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledHashSet.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledHashSet.cs @@ -2,8 +2,6 @@ using System.Collections.Generic; -#nullable disable - namespace Microsoft.VisualStudio.Buffers.PooledObjects { // HashSet that can be recycled via an object pool @@ -29,8 +27,8 @@ public void Free() // if someone needs to create a pool; public static ObjectPool> CreatePool() { - ObjectPool> pool = null; - pool = new ObjectPool>(() => new PooledHashSet(pool), 128); + ObjectPool>? pool = null; + pool = new ObjectPool>(() => new PooledHashSet(pool!), 128); return pool; } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledStringBuilder.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledStringBuilder.cs index 4de876164ec..936975250ac 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledStringBuilder.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledStringBuilder.cs @@ -3,8 +3,6 @@ using System; using System.Text; -#nullable disable - namespace Microsoft.VisualStudio.Buffers.PooledObjects { /// @@ -64,8 +62,8 @@ public string ToStringAndFree(int startIndex, int length) /// public static ObjectPool CreatePool(int size = 32) { - ObjectPool pool = null; - pool = new ObjectPool(() => new PooledStringBuilder(pool), size); + ObjectPool? pool = null; + pool = new ObjectPool(() => new PooledStringBuilder(pool!), size); return pool; } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ActiveConfiguredProjectsProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ActiveConfiguredProjectsProvider.cs index a55a5a68a10..76c1867baae 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ActiveConfiguredProjectsProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ActiveConfiguredProjectsProvider.cs @@ -10,8 +10,6 @@ using Microsoft.VisualStudio.Buffers.PooledObjects; using Microsoft.VisualStudio.ProjectSystem.Configuration; -#nullable disable - namespace Microsoft.VisualStudio.ProjectSystem { [Export(typeof(IActiveConfiguredProjectsProvider))] @@ -78,11 +76,16 @@ public OrderPrecedenceImportCollection> GetActiveConfiguredProjectsMapAsync() + public async Task?> GetActiveConfiguredProjectsMapAsync() { - var builder = PooledDictionary.GetInstance(); + ActiveConfiguredObjects? projects = await GetActiveConfiguredProjectsAsync(); + + if (projects == null || projects.Objects.Count == 0) + { + return null; + } - ActiveConfiguredObjects projects = await GetActiveConfiguredProjectsAsync(); + var builder = PooledDictionary.GetInstance(); bool isCrossTargeting = projects.Objects.All(project => project.ProjectConfiguration.IsCrossTargeting()); @@ -102,9 +105,10 @@ public async Task> GetActiveConfi return builder.ToImmutableDictionaryAndFree(); } - public async Task> GetActiveConfiguredProjectsAsync() + public async Task?> GetActiveConfiguredProjectsAsync() { - ActiveConfiguredObjects configurations = await GetActiveProjectConfigurationsAsync(); + ActiveConfiguredObjects? configurations = await GetActiveProjectConfigurationsAsync(); + if (configurations == null) { return null; @@ -122,7 +126,7 @@ public async Task> GetActiveConfigure return new ActiveConfiguredObjects(builder.MoveToImmutable(), configurations.DimensionNames); } - public async Task> GetActiveProjectConfigurationsAsync() + public async Task?> GetActiveProjectConfigurationsAsync() { ProjectConfiguration activeSolutionConfiguration = _services.ActiveConfiguredProjectProvider.ActiveProjectConfiguration; diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/BuildProperty.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/BuildProperty.cs index 254d733d7af..aab578c210b 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/BuildProperty.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/BuildProperty.cs @@ -1,7 +1,5 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#nullable disable - namespace Microsoft.VisualStudio.ProjectSystem.Build { /// diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/CommandLineDesignTimeBuildPropertiesProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/CommandLineDesignTimeBuildPropertiesProvider.cs index e26fb914fd2..2bcbf4be5de 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/CommandLineDesignTimeBuildPropertiesProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/CommandLineDesignTimeBuildPropertiesProvider.cs @@ -5,8 +5,6 @@ using System.Threading; using System.Threading.Tasks; -#nullable disable - namespace Microsoft.VisualStudio.ProjectSystem.Build { /// diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/GeneratePackageOnBuildDesignTimeBuildPropertyProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/GeneratePackageOnBuildDesignTimeBuildPropertyProvider.cs index 2e730395766..0fef8ea4f5b 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/GeneratePackageOnBuildDesignTimeBuildPropertyProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/GeneratePackageOnBuildDesignTimeBuildPropertyProvider.cs @@ -5,8 +5,6 @@ using System.Threading; using System.Threading.Tasks; -#nullable disable - namespace Microsoft.VisualStudio.ProjectSystem.Build { /// diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/GeneratePackageOnBuildPropertyProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/GeneratePackageOnBuildPropertyProvider.cs index 7a6950f6c7b..a8957c79dde 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/GeneratePackageOnBuildPropertyProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/GeneratePackageOnBuildPropertyProvider.cs @@ -5,8 +5,6 @@ using System.Threading; using System.Threading.Tasks; -#nullable disable - namespace Microsoft.VisualStudio.ProjectSystem.Build { /// diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/ImplicitlyActiveConfiguredProjectReadyToBuild.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/ImplicitlyActiveConfiguredProjectReadyToBuild.cs index f1dc16c9bfa..52b7db041e5 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/ImplicitlyActiveConfiguredProjectReadyToBuild.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/ImplicitlyActiveConfiguredProjectReadyToBuild.cs @@ -4,8 +4,6 @@ using System.ComponentModel.Composition; using System.Threading.Tasks; -#nullable disable - namespace Microsoft.VisualStudio.ProjectSystem.Build { [Export(typeof(IConfiguredProjectReadyToBuild))] @@ -16,7 +14,7 @@ internal sealed class ImplicitlyActiveConfiguredProjectReadyToBuild : IConfigure private readonly ConfiguredProject _configuredProject; private readonly IActiveConfiguredProjectProvider _activeConfiguredProjectProvider; - private TaskCompletionSource _activationTask; + private TaskCompletionSource _activationTask; [ImportingConstructor] public ImplicitlyActiveConfiguredProjectReadyToBuild( @@ -25,7 +23,7 @@ public ImplicitlyActiveConfiguredProjectReadyToBuild( { _configuredProject = configuredProject; _activeConfiguredProjectProvider = activeConfiguredProjectProvider; - _activationTask = new TaskCompletionSource(); + _activationTask = new TaskCompletionSource(); _activeConfiguredProjectProvider.Changed += ActiveConfiguredProject_Changed; } @@ -46,7 +44,7 @@ private Task GetLatestActivationTask() { if (!nowActive) { - _activationTask = new TaskCompletionSource(); + _activationTask = new TaskCompletionSource(); } } else if (nowActive) @@ -66,7 +64,7 @@ public void Dispose() private bool IsActive() { - ProjectConfiguration activeConfig = _activeConfiguredProjectProvider.ActiveProjectConfiguration; + ProjectConfiguration? activeConfig = _activeConfiguredProjectProvider.ActiveProjectConfiguration; if (activeConfig == null) return false; diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/PublishableProjectConfigProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/PublishableProjectConfigProvider.cs index bbc1c719830..f0ad48e8b7f 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/PublishableProjectConfigProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/PublishableProjectConfigProvider.cs @@ -8,8 +8,6 @@ using Microsoft.VisualStudio.Threading; -#nullable disable - namespace Microsoft.VisualStudio.ProjectSystem.Build { /// diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/TargetFrameworkGlobalBuildPropertyProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/TargetFrameworkGlobalBuildPropertyProvider.cs index ee78b79684b..f362817969c 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/TargetFrameworkGlobalBuildPropertyProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/TargetFrameworkGlobalBuildPropertyProvider.cs @@ -5,8 +5,6 @@ using System.Threading; using System.Threading.Tasks; -#nullable disable - namespace Microsoft.VisualStudio.ProjectSystem.Build { /// diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/TurnOffUseHostCompilerIfAvailableBuildPropertiesProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/TurnOffUseHostCompilerIfAvailableBuildPropertiesProvider.cs index 53cb2cea48b..ae4916a8782 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/TurnOffUseHostCompilerIfAvailableBuildPropertiesProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/TurnOffUseHostCompilerIfAvailableBuildPropertiesProvider.cs @@ -5,8 +5,6 @@ using System.Threading; using System.Threading.Tasks; -#nullable disable - namespace Microsoft.VisualStudio.ProjectSystem.Build { /// diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/BaseProjectConfigurationDimensionProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/BaseProjectConfigurationDimensionProvider.cs index b16ef37b7e6..02e1389cece 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/BaseProjectConfigurationDimensionProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/BaseProjectConfigurationDimensionProvider.cs @@ -10,8 +10,6 @@ using Microsoft.VisualStudio.Buffers.PooledObjects; using Microsoft.VisualStudio.Build; -#nullable disable - namespace Microsoft.VisualStudio.ProjectSystem.Configuration { /// @@ -26,7 +24,7 @@ internal abstract class BaseProjectConfigurationDimensionProvider : IProjectConf /// Name of the dimension. /// Name of the project property containing the dimension values. /// The default value of the dimension, for example "AnyCPU". - protected BaseProjectConfigurationDimensionProvider(IProjectAccessor projectAccessor, string dimensionName, string propertyName, string dimensionDefaultValue = null) + protected BaseProjectConfigurationDimensionProvider(IProjectAccessor projectAccessor, string dimensionName, string propertyName, string? dimensionDefaultValue = null) { Requires.NotNull(projectAccessor, nameof(projectAccessor)); @@ -46,7 +44,7 @@ public string PropertyName get; } - public string DimensionDefaultValue + public string? DimensionDefaultValue { get; } @@ -68,8 +66,8 @@ protected virtual async Task> GetOrderedPropertyValuesAsy { Requires.NotNull(project, nameof(project)); - string propertyValue = await GetPropertyValue(project); - if (propertyValue == null || string.IsNullOrEmpty(propertyValue)) + string? propertyValue = await GetPropertyValue(project); + if (string.IsNullOrEmpty(propertyValue)) { return ImmutableArray.Empty; } @@ -144,7 +142,7 @@ public IEnumerable GetBestGuessDimensionNames(ImmutableArray>> GetBestGuessDefaultValuesForDimensionsAsync(UnconfiguredProject project) { - string defaultValue = await FindDefaultValueFromDimensionPropertyAsync(project) ?? DimensionDefaultValue; + string? defaultValue = await FindDefaultValueFromDimensionPropertyAsync(project) ?? DimensionDefaultValue; if (defaultValue != null) return new[] { new KeyValuePair(DimensionName, defaultValue) }; @@ -168,7 +166,7 @@ public async Task>> GetBestGuessDefault /// /// This needs to get the evaluated property in order to get inherited properties defines in props or targets. /// - protected async Task GetPropertyValue(UnconfiguredProject project, string propertyName = null) + protected async Task GetPropertyValue(UnconfiguredProject project, string? propertyName = null) { ConfiguredProject configuredProject = await project.GetSuggestedConfiguredProjectAsync(); @@ -178,9 +176,9 @@ protected async Task GetPropertyValue(UnconfiguredProject project, strin }); } - private async Task FindDefaultValueFromDimensionPropertyAsync(UnconfiguredProject project) + private async Task FindDefaultValueFromDimensionPropertyAsync(UnconfiguredProject project) { - string values = await FindDimensionPropertyAsync(project); + string? values = await FindDimensionPropertyAsync(project); if (string.IsNullOrEmpty(values)) return null; @@ -196,14 +194,14 @@ private async Task FindDefaultValueFromDimensionPropertyAsync(Unconfigur return null; } - private Task FindDimensionPropertyAsync(UnconfiguredProject project) + private Task FindDimensionPropertyAsync(UnconfiguredProject project) { return ProjectAccessor.OpenProjectXmlForReadAsync( project, projectXml => FindDimensionProperty(projectXml)?.GetUnescapedValue()); } - private ProjectPropertyElement FindDimensionProperty(ProjectRootElement projectXml) + private ProjectPropertyElement? FindDimensionProperty(ProjectRootElement projectXml) { IEnumerable properties = projectXml.PropertyGroups .SelectMany(group => group.Properties); @@ -211,7 +209,7 @@ private ProjectPropertyElement FindDimensionProperty(ProjectRootElement projectX return FindDimensionProperty(properties); } - private ProjectPropertyElement FindDimensionProperty(IEnumerable properties) + private ProjectPropertyElement? FindDimensionProperty(IEnumerable properties) { // NOTE: We try to somewhat mimic evaluation, but it doesn't have to be exact; its just a guess // at what "might" be the default configuration, not what it actually is. diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/ConfigurationProjectConfigurationDimensionProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/ConfigurationProjectConfigurationDimensionProvider.cs index d89e881379d..83661c9032a 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/ConfigurationProjectConfigurationDimensionProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/ConfigurationProjectConfigurationDimensionProvider.cs @@ -1,12 +1,11 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.ComponentModel.Composition; using System.Threading.Tasks; using Microsoft.VisualStudio.Build; -#nullable disable - namespace Microsoft.VisualStudio.ProjectSystem.Configuration { /// @@ -76,7 +75,9 @@ public override Task OnDimensionValueChangedAsync(ProjectConfigurationDimensionV /// A task for the async operation. private async Task OnConfigurationAddedAsync(UnconfiguredProject project, string configurationName) { - string evaluatedPropertyValue = await GetPropertyValue(project); + string? evaluatedPropertyValue = await GetPropertyValue(project); + if (evaluatedPropertyValue == null) + throw new InvalidOperationException($"Property {PropertyName} not defined."); await ProjectAccessor.OpenProjectXmlForWriteAsync(project, msbuildProject => { BuildUtilities.AppendPropertyValue(msbuildProject, evaluatedPropertyValue, PropertyName, configurationName); @@ -91,7 +92,9 @@ await ProjectAccessor.OpenProjectXmlForWriteAsync(project, msbuildProject => /// A task for the async operation. private async Task OnConfigurationRemovedAsync(UnconfiguredProject project, string configurationName) { - string evaluatedPropertyValue = await GetPropertyValue(project); + string? evaluatedPropertyValue = await GetPropertyValue(project); + if (evaluatedPropertyValue == null) + throw new InvalidOperationException($"Property {PropertyName} not defined."); await ProjectAccessor.OpenProjectXmlForWriteAsync(project, msbuildProject => { BuildUtilities.RemovePropertyValue(msbuildProject, evaluatedPropertyValue, PropertyName, configurationName); @@ -107,7 +110,9 @@ await ProjectAccessor.OpenProjectXmlForWriteAsync(project, msbuildProject => /// A task for the async operation. private async Task OnConfigurationRenamedAsync(UnconfiguredProject project, string oldName, string newName) { - string evaluatedPropertyValue = await GetPropertyValue(project); + string? evaluatedPropertyValue = await GetPropertyValue(project); + if (evaluatedPropertyValue == null) + throw new InvalidOperationException($"Property {PropertyName} not defined."); await ProjectAccessor.OpenProjectXmlForWriteAsync(project, msbuildProject => { BuildUtilities.RenamePropertyValue(msbuildProject, evaluatedPropertyValue, PropertyName, oldName, newName); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/DimensionProviderOrder.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/DimensionProviderOrder.cs index 073e0ef150a..56fce0506d1 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/DimensionProviderOrder.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/DimensionProviderOrder.cs @@ -1,7 +1,5 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#nullable disable - namespace Microsoft.VisualStudio.ProjectSystem.Configuration { /// diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/IActiveConfiguredProjectsDimensionProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/IActiveConfiguredProjectsDimensionProvider.cs index 0a4b569efff..7be4cb1c7b4 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/IActiveConfiguredProjectsDimensionProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/IActiveConfiguredProjectsDimensionProvider.cs @@ -2,8 +2,6 @@ using Microsoft.VisualStudio.Composition; -#nullable disable - namespace Microsoft.VisualStudio.ProjectSystem.Configuration { /// diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/IConfigurationDimensionDescriptionMetadataView.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/IConfigurationDimensionDescriptionMetadataView.cs index 0689b3caa47..e705d4312e3 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/IConfigurationDimensionDescriptionMetadataView.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/IConfigurationDimensionDescriptionMetadataView.cs @@ -1,7 +1,5 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#nullable disable - namespace Microsoft.VisualStudio.ProjectSystem.Configuration { /// diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/IImplicitlyActiveDimensionProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/IImplicitlyActiveDimensionProvider.cs index 2b05c34b413..edb125c996a 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/IImplicitlyActiveDimensionProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/IImplicitlyActiveDimensionProvider.cs @@ -4,8 +4,6 @@ using System.Collections.Generic; using Microsoft.VisualStudio.Composition; -#nullable disable - namespace Microsoft.VisualStudio.ProjectSystem.Configuration { /// diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/IProjectConfigurationDimensionsProvider4.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/IProjectConfigurationDimensionsProvider4.cs index aa1efa3c9d7..706d1d27bb3 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/IProjectConfigurationDimensionsProvider4.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/IProjectConfigurationDimensionsProvider4.cs @@ -5,8 +5,6 @@ using Microsoft.Build.Construction; -#nullable disable - namespace Microsoft.VisualStudio.ProjectSystem { internal interface IProjectConfigurationDimensionsProvider4 : IProjectConfigurationDimensionsProvider3 diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/ImplicitlyActiveDimensionProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/ImplicitlyActiveDimensionProvider.cs index a47dce0aac3..8664e5bc6c2 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/ImplicitlyActiveDimensionProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/ImplicitlyActiveDimensionProvider.cs @@ -8,8 +8,6 @@ using Microsoft.VisualStudio.Buffers.PooledObjects; -#nullable disable - namespace Microsoft.VisualStudio.ProjectSystem.Configuration { /// diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/PlatformProjectConfigurationDimensionProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/PlatformProjectConfigurationDimensionProvider.cs index 9c006e3d9eb..e651de70f1f 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/PlatformProjectConfigurationDimensionProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/PlatformProjectConfigurationDimensionProvider.cs @@ -1,12 +1,11 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.ComponentModel.Composition; using System.Threading.Tasks; using Microsoft.VisualStudio.Build; -#nullable disable - namespace Microsoft.VisualStudio.ProjectSystem.Configuration { /// @@ -67,7 +66,9 @@ public override Task OnDimensionValueChangedAsync(ProjectConfigurationDimensionV /// A task for the async operation. private async Task OnPlatformAddedAsync(UnconfiguredProject project, string platformName) { - string evaluatedPropertyValue = await GetPropertyValue(project); + string? evaluatedPropertyValue = await GetPropertyValue(project); + if (evaluatedPropertyValue == null) + throw new InvalidOperationException($"Property {PropertyName} not defined."); await ProjectAccessor.OpenProjectXmlForWriteAsync(project, msbuildProject => { BuildUtilities.AppendPropertyValue(msbuildProject, evaluatedPropertyValue, PropertyName, platformName); @@ -82,7 +83,9 @@ await ProjectAccessor.OpenProjectXmlForWriteAsync(project, msbuildProject => /// A task for the async operation. private async Task OnPlatformDeletedAsync(UnconfiguredProject project, string platformName) { - string evaluatedPropertyValue = await GetPropertyValue(project); + string? evaluatedPropertyValue = await GetPropertyValue(project); + if (evaluatedPropertyValue == null) + throw new InvalidOperationException($"Property {PropertyName} not defined."); await ProjectAccessor.OpenProjectXmlForWriteAsync(project, msbuildProject => { BuildUtilities.RemovePropertyValue(msbuildProject, evaluatedPropertyValue, PropertyName, platformName); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/TargetFrameworkProjectConfigurationDimensionProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/TargetFrameworkProjectConfigurationDimensionProvider.cs index 8203ab26842..cd188f845dd 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/TargetFrameworkProjectConfigurationDimensionProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Configuration/TargetFrameworkProjectConfigurationDimensionProvider.cs @@ -6,8 +6,6 @@ using Microsoft.VisualStudio.Build; -#nullable disable - namespace Microsoft.VisualStudio.ProjectSystem.Configuration { /// @@ -36,7 +34,7 @@ protected override async Task> GetOrderedPropertyValuesAs { Requires.NotNull(project, nameof(project)); - string targetFrameworksProperty = await GetPropertyValue(project, ConfigurationGeneral.TargetFrameworksProperty); + string? targetFrameworksProperty = await GetPropertyValue(project, ConfigurationGeneral.TargetFrameworksProperty); if (targetFrameworksProperty != null) { return BuildUtilities.GetPropertyValues(targetFrameworksProperty).ToImmutableArray(); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/ActiveDebugFrameworkServices.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/ActiveDebugFrameworkServices.cs index e6fbcc4fd0f..83619c546f5 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/ActiveDebugFrameworkServices.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/ActiveDebugFrameworkServices.cs @@ -8,8 +8,6 @@ using Microsoft.VisualStudio.Build; -#nullable disable - namespace Microsoft.VisualStudio.ProjectSystem.Debug { /// @@ -32,7 +30,7 @@ public ActiveDebugFrameworkServices(IActiveConfiguredProjectsProvider activeConf /// /// /// - public async Task> GetProjectFrameworksAsync() + public async Task?> GetProjectFrameworksAsync() { // It is important that we return the frameworks in the order they are specified in the project to ensure the default is set // correctly. @@ -40,11 +38,12 @@ public async Task> GetProjectFrameworksAsync() string targetFrameworks = (string)await props.TargetFrameworks.GetValueAsync(); - if (!string.IsNullOrWhiteSpace(targetFrameworks)) + if (string.IsNullOrWhiteSpace(targetFrameworks)) { - return BuildUtilities.GetPropertyValues(targetFrameworks).ToList(); + return null; } - return null; + + return BuildUtilities.GetPropertyValues(targetFrameworks).ToList(); } /// @@ -59,29 +58,35 @@ public async Task SetActiveDebuggingFrameworkPropertyAsync(string activeFramewor /// /// /// - public async Task GetActiveDebuggingFrameworkPropertyAsync() + public async Task GetActiveDebuggingFrameworkPropertyAsync() { ProjectDebugger props = await _commonProjectServices.ActiveConfiguredProjectProperties.GetProjectDebuggerPropertiesAsync(); - string activeValue = await props.ActiveDebugFramework.GetValueAsync() as string; + string? activeValue = await props.ActiveDebugFramework.GetValueAsync() as string; return activeValue; } /// /// /// - public async Task GetConfiguredProjectForActiveFrameworkAsync() + public async Task GetConfiguredProjectForActiveFrameworkAsync() { #pragma warning disable CS0618 // Type or member is obsolete - ImmutableDictionary configProjects = await _activeConfiguredProjectsProvider.GetActiveConfiguredProjectsMapAsync(); + ImmutableDictionary? configProjects = await _activeConfiguredProjectsProvider.GetActiveConfiguredProjectsMapAsync(); #pragma warning restore CS0618 // Type or member is obsolete + if (configProjects == null) + { + return null; + } + // If there is only one we are done if (configProjects.Count == 1) { return configProjects.First().Value; } - string activeFramework = await GetActiveDebuggingFrameworkPropertyAsync(); + string? activeFramework = await GetActiveDebuggingFrameworkPropertyAsync(); + if (!string.IsNullOrWhiteSpace(activeFramework)) { if (configProjects.TryGetValue(activeFramework, out ConfiguredProject configuredProject)) @@ -92,7 +97,8 @@ public async Task GetConfiguredProjectForActiveFrameworkAsync // We can't just select the first one. If activeFramework is not set we must pick the first one as defined by the // targetFrameworks property. So we need the order as returned by GetProjectFrameworks() - List frameworks = await GetProjectFrameworksAsync(); + List? frameworks = await GetProjectFrameworksAsync(); + if (frameworks != null && frameworks.Count > 0) { if (configProjects.TryGetValue(frameworks[0], out ConfiguredProject configuredProject)) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/IActiveDebugFrameworkServices.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/IActiveDebugFrameworkServices.cs index 7b3d352c09a..01bf2b9e6ca 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/IActiveDebugFrameworkServices.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/IActiveDebugFrameworkServices.cs @@ -2,9 +2,8 @@ using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.VisualStudio.Composition; -#nullable disable +using Microsoft.VisualStudio.Composition; namespace Microsoft.VisualStudio.ProjectSystem.Debug { @@ -18,7 +17,7 @@ public interface IActiveDebugFrameworkServices /// /// Returns the set of frameworks in the order defined in msbuild. If not multi-targeting it returns null. /// - Task> GetProjectFrameworksAsync(); + Task?> GetProjectFrameworksAsync(); /// /// Sets the value of the active debugging target framework property. @@ -28,11 +27,11 @@ public interface IActiveDebugFrameworkServices /// /// Returns the value of the property, or empty string/null if the property has never been set. /// - Task GetActiveDebuggingFrameworkPropertyAsync(); + Task GetActiveDebuggingFrameworkPropertyAsync(); /// /// Returns the configured project which represents the active framework. This is valid whether multi-targeting or not. /// - Task GetConfiguredProjectForActiveFrameworkAsync(); + Task GetConfiguredProjectForActiveFrameworkAsync(); } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Extensibility/IProjectExportProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Extensibility/IProjectExportProvider.cs index 0ba9f3c9ebb..64001fdc58a 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Extensibility/IProjectExportProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Extensibility/IProjectExportProvider.cs @@ -2,8 +2,6 @@ using Microsoft.VisualStudio.Composition; -#nullable disable - namespace Microsoft.VisualStudio.ProjectSystem.VS.Extensibility { /// @@ -18,6 +16,6 @@ public interface IProjectExportProvider /// UI thread. This is the preferred method for getting access to project specific /// exports. /// - T GetExport(string projectFilePath) where T : class; + T? GetExport(string projectFilePath) where T : class; } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Extensibility/ProjectExportProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Extensibility/ProjectExportProvider.cs index 133e89f9f7f..169ab7a9ff7 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Extensibility/ProjectExportProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Extensibility/ProjectExportProvider.cs @@ -4,8 +4,6 @@ using System.ComponentModel.Composition; using System.Linq; -#nullable disable - namespace Microsoft.VisualStudio.ProjectSystem.VS.Extensibility { /// @@ -28,7 +26,7 @@ public ProjectExportProvider(IProjectServiceAccessor serviceAccessor) /// UI thread. This is the preferred method for getting access to project specific /// exports /// - public T GetExport(string projectFilePath) where T : class + public T? GetExport(string projectFilePath) where T : class { if (string.IsNullOrEmpty(projectFilePath)) { @@ -37,7 +35,7 @@ public T GetExport(string projectFilePath) where T : class IProjectService projectService = _projectServiceAccessor.GetProjectService(); - UnconfiguredProject project = projectService?.LoadedUnconfiguredProjects + UnconfiguredProject? project = projectService?.LoadedUnconfiguredProjects .FirstOrDefault(x => x.FullPath.Equals(projectFilePath, StringComparison.OrdinalIgnoreCase)); return project?.Services.ExportProvider.GetExportedValueOrDefault(); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/IActiveConfiguredProjectsProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/IActiveConfiguredProjectsProvider.cs index 6c1603f383b..bc5f1213583 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/IActiveConfiguredProjectsProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/IActiveConfiguredProjectsProvider.cs @@ -3,9 +3,8 @@ using System; using System.Collections.Immutable; using System.Threading.Tasks; -using Microsoft.VisualStudio.Composition; -#nullable disable +using Microsoft.VisualStudio.Composition; namespace Microsoft.VisualStudio.ProjectSystem { @@ -26,9 +25,12 @@ internal interface IActiveConfiguredProjectsProvider /// If the current project is not a cross-targeting project, then it returns a singleton key-value pair with an /// ignorable key and single active configured project as value. /// - /// Map from TargetFramework dimension to active configured project. + /// + /// Map from TargetFramework dimension to active configured project, or if there + /// are no active objects. + /// [Obsolete("This method will be removed in a future build.")] - Task> GetActiveConfiguredProjectsMapAsync(); + Task?> GetActiveConfiguredProjectsMapAsync(); /// /// Returns the ordered list of configured projects that are active for the current project, loading them if needed. @@ -43,7 +45,7 @@ internal interface IActiveConfiguredProjectsProvider /// The order in the returned matches the declared ordered within /// the project file. /// - Task> GetActiveConfiguredProjectsAsync(); + Task?> GetActiveConfiguredProjectsAsync(); /// /// Returns the ordered list of project configurations that are active for the current project. @@ -58,6 +60,6 @@ internal interface IActiveConfiguredProjectsProvider /// The order in the returned matches the declared ordered within /// the project file. /// - Task> GetActiveProjectConfigurationsAsync(); + Task?> GetActiveProjectConfigurationsAsync(); } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/IProjectAccessor.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/IProjectAccessor.cs index d7fabdb3b96..5502f743942 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/IProjectAccessor.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/IProjectAccessor.cs @@ -8,8 +8,6 @@ using Microsoft.Build.Evaluation; using Microsoft.VisualStudio.Composition; -#nullable disable - namespace Microsoft.VisualStudio.ProjectSystem { /// diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Imaging/IProjectImageProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Imaging/IProjectImageProvider.cs index b3de87f5376..84cc51ab3f1 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Imaging/IProjectImageProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Imaging/IProjectImageProvider.cs @@ -2,8 +2,6 @@ using Microsoft.VisualStudio.Composition; -#nullable disable - namespace Microsoft.VisualStudio.ProjectSystem.Imaging { /// @@ -16,6 +14,6 @@ internal interface IProjectImageProvider /// Returns the for the specified key, returning /// if the provider does handle the specified key. /// - ProjectImageMoniker GetProjectImage(string key); + ProjectImageMoniker? GetProjectImage(string key); } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Imaging/ProjectImageKey.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Imaging/ProjectImageKey.cs index b511c55fdc3..882c2da0b14 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Imaging/ProjectImageKey.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Imaging/ProjectImageKey.cs @@ -1,7 +1,5 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#nullable disable - namespace Microsoft.VisualStudio.ProjectSystem.Imaging { /// diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Imaging/ProjectImageProviderAggregator.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Imaging/ProjectImageProviderAggregator.cs index 3563ee50c19..d88d11e9301 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Imaging/ProjectImageProviderAggregator.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Imaging/ProjectImageProviderAggregator.cs @@ -2,9 +2,8 @@ using System; using System.ComponentModel.Composition; -using Microsoft.VisualStudio.Composition; -#nullable disable +using Microsoft.VisualStudio.Composition; namespace Microsoft.VisualStudio.ProjectSystem.Imaging { @@ -29,13 +28,13 @@ public OrderPrecedenceImportCollection ImageProviders get; } - public ProjectImageMoniker GetProjectImage(string key) + public ProjectImageMoniker? GetProjectImage(string key) { Requires.NotNullOrEmpty(key, nameof(key)); foreach (Lazy provider in ImageProviders) { - ProjectImageMoniker image = provider.Value.GetProjectImage(key); + ProjectImageMoniker? image = provider.Value.GetProjectImage(key); if (image != null) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Input/AbstractProjectCommand.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Input/AbstractProjectCommand.cs index a074c8c2ed8..fcbb6522824 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Input/AbstractProjectCommand.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Input/AbstractProjectCommand.cs @@ -6,8 +6,6 @@ using Microsoft.VisualStudio.Threading; -#nullable disable - namespace Microsoft.VisualStudio.ProjectSystem.Input { /// @@ -22,7 +20,7 @@ protected AbstractProjectCommand() _commandIds = new Lazy(() => GetCommandIds(this)); } - public Task GetCommandStatusAsync(IImmutableSet nodes, long commandId, bool focused, string commandText, CommandStatus progressiveStatus) + public Task GetCommandStatusAsync(IImmutableSet nodes, long commandId, bool focused, string? commandText, CommandStatus progressiveStatus) { Requires.NotNull(nodes, nameof(nodes)); @@ -48,7 +46,7 @@ public Task TryHandleCommandAsync(IImmutableSet nodes, long return TaskResult.False; } - protected abstract Task GetCommandStatusAsync(IImmutableSet nodes, bool focused, string commandText, CommandStatus progressiveStatus); + protected abstract Task GetCommandStatusAsync(IImmutableSet nodes, bool focused, string? commandText, CommandStatus progressiveStatus); protected abstract Task TryHandleCommandAsync(IImmutableSet nodes, bool focused, long commandExecuteOptions, IntPtr variantArgIn, IntPtr variantArgOut); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Input/AbstractSingleNodeProjectCommand.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Input/AbstractSingleNodeProjectCommand.cs index 66dc5629bf6..a9a1fce6756 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Input/AbstractSingleNodeProjectCommand.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Input/AbstractSingleNodeProjectCommand.cs @@ -7,8 +7,6 @@ using Microsoft.VisualStudio.Threading; -#nullable disable - namespace Microsoft.VisualStudio.ProjectSystem.Input { /// @@ -20,7 +18,7 @@ protected AbstractSingleNodeProjectCommand() { } - protected sealed override Task GetCommandStatusAsync(IImmutableSet nodes, bool focused, string commandText, CommandStatus progressiveStatus) + protected sealed override Task GetCommandStatusAsync(IImmutableSet nodes, bool focused, string? commandText, CommandStatus progressiveStatus) { if (nodes.Count == 1) { @@ -40,7 +38,7 @@ protected sealed override Task TryHandleCommandAsync(IImmutableSet GetCommandStatusAsync(IProjectTree node, bool focused, string commandText, CommandStatus progressiveStatus); + protected abstract Task GetCommandStatusAsync(IProjectTree node, bool focused, string? commandText, CommandStatus progressiveStatus); protected abstract Task TryHandleCommandAsync(IProjectTree node, bool focused, long commandExecuteOptions, IntPtr variantArgIn, IntPtr variantArgOut); } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Input/GetCommandStatusResult.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Input/GetCommandStatusResult.cs index 177d6d8b70e..805b9f50f63 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Input/GetCommandStatusResult.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Input/GetCommandStatusResult.cs @@ -2,8 +2,6 @@ using System.Threading.Tasks; -#nullable disable - namespace Microsoft.VisualStudio.ProjectSystem.Input { internal static class GetCommandStatusResult diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Input/ProjectCommandAttribute.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Input/ProjectCommandAttribute.cs index ddbf5ad55d6..4c78ec09c99 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Input/ProjectCommandAttribute.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Input/ProjectCommandAttribute.cs @@ -3,8 +3,6 @@ using System; using System.ComponentModel.Composition; -#nullable disable - namespace Microsoft.VisualStudio.ProjectSystem.Input { /// diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Resources/ManagedImageMonikers.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Resources/ManagedImageMonikers.cs index f7cb2e42076..cde81b7e336 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Resources/ManagedImageMonikers.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Resources/ManagedImageMonikers.cs @@ -10,8 +10,6 @@ [assembly: DebuggerDisplay("{Microsoft.VisualStudio.ProjectSystem.VS.ManagedImageMonikers.ImageMonikerDebugDisplay(this)}", Target = typeof(ImageMoniker))] [assembly: DebuggerDisplay("{Microsoft.VisualStudio.ProjectSystem.VS.ManagedImageMonikers.ProjectImageMonikerDebugDisplay(this)}", Target = typeof(ProjectImageMoniker))] -#nullable disable - namespace Microsoft.VisualStudio.ProjectSystem.VS { /// diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Tree/Dependencies/CrossTarget/AggregateCrossTargetProjectContextProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Tree/Dependencies/CrossTarget/AggregateCrossTargetProjectContextProvider.cs index 4032782a533..e934c523aca 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Tree/Dependencies/CrossTarget/AggregateCrossTargetProjectContextProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Tree/Dependencies/CrossTarget/AggregateCrossTargetProjectContextProvider.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; using System.Collections.Immutable; using System.ComponentModel.Composition; @@ -35,8 +36,14 @@ public async Task CreateProjectContextAsync( { // Get the set of active configured projects ignoring target framework. #pragma warning disable CS0618 // Type or member is obsolete - ImmutableDictionary configuredProjectsMap = await _activeConfiguredProjectsProvider.GetActiveConfiguredProjectsMapAsync(); + ImmutableDictionary? configuredProjectsMap = await _activeConfiguredProjectsProvider.GetActiveConfiguredProjectsMapAsync(); #pragma warning restore CS0618 // Type or member is obsolete + + if (configuredProjectsMap == null) + { + throw new InvalidOperationException("There are no active configured projects."); + } + ProjectConfiguration activeProjectConfiguration = _commonServices.ActiveConfiguredProject.ProjectConfiguration; ImmutableArray.Builder targetFrameworks = ImmutableArray.CreateBuilder(initialCapacity: configuredProjectsMap.Count); ITargetFramework activeTargetFramework = TargetFramework.Empty; diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Tree/Dependencies/Snapshot/AggregateDependenciesSnapshotProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Tree/Dependencies/Snapshot/AggregateDependenciesSnapshotProvider.cs index 8b20988d146..2092d2d370e 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Tree/Dependencies/Snapshot/AggregateDependenciesSnapshotProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Tree/Dependencies/Snapshot/AggregateDependenciesSnapshotProvider.cs @@ -93,7 +93,7 @@ void OnSnapshotChanged(object sender, SnapshotChangedEventArgs e) lock (_snapshotProviders) { - if (!_snapshotProviders.TryGetValue(projectFilePath, out IDependenciesSnapshotProvider snapshotProvider)) + if (!_snapshotProviders.TryGetValue(projectFilePath, out IDependenciesSnapshotProvider? snapshotProvider)) { snapshotProvider = _projectExportProvider.GetExport(projectFilePath); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Tree/Imaging/AppDesignerFolderProjectImageProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Tree/Imaging/AppDesignerFolderProjectImageProvider.cs index 1993119c61a..4f41d2709ec 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Tree/Imaging/AppDesignerFolderProjectImageProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Tree/Imaging/AppDesignerFolderProjectImageProvider.cs @@ -5,8 +5,6 @@ using Microsoft.VisualStudio.Imaging; using Microsoft.VisualStudio.ProjectSystem.Imaging; -#nullable disable - namespace Microsoft.VisualStudio.ProjectSystem.VS.Imaging { /// @@ -21,7 +19,7 @@ public AppDesignerFolderProjectImageProvider() { } - public ProjectImageMoniker GetProjectImage(string key) + public ProjectImageMoniker? GetProjectImage(string key) { Requires.NotNullOrEmpty(key, nameof(key)); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Tree/Imaging/CSharp/CSharpProjectImageProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Tree/Imaging/CSharp/CSharpProjectImageProvider.cs index 3bf707e833a..f7c9483c28b 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Tree/Imaging/CSharp/CSharpProjectImageProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Tree/Imaging/CSharp/CSharpProjectImageProvider.cs @@ -5,8 +5,6 @@ using Microsoft.VisualStudio.Imaging; using Microsoft.VisualStudio.ProjectSystem.Imaging; -#nullable disable - namespace Microsoft.VisualStudio.ProjectSystem.VS.Imaging.CSharp { /// @@ -21,7 +19,7 @@ public CSharpProjectImageProvider() { } - public ProjectImageMoniker GetProjectImage(string key) + public ProjectImageMoniker? GetProjectImage(string key) { Requires.NotNullOrEmpty(key, nameof(key)); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Tree/Imaging/FSharp/FSharpProjectImageProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Tree/Imaging/FSharp/FSharpProjectImageProvider.cs index 842d2093463..a9d5b3d6906 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Tree/Imaging/FSharp/FSharpProjectImageProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Tree/Imaging/FSharp/FSharpProjectImageProvider.cs @@ -5,8 +5,6 @@ using Microsoft.VisualStudio.Imaging; using Microsoft.VisualStudio.ProjectSystem.Imaging; -#nullable disable - namespace Microsoft.VisualStudio.ProjectSystem.VS.Imaging.FSharp { /// @@ -21,7 +19,7 @@ public FSharpProjectImageProvider() { } - public ProjectImageMoniker GetProjectImage(string key) + public ProjectImageMoniker? GetProjectImage(string key) { Requires.NotNullOrEmpty(key, nameof(key)); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Tree/Imaging/VisualBasic/VisualBasicProjectImageProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Tree/Imaging/VisualBasic/VisualBasicProjectImageProvider.cs index 2614f90b22b..62312ea6e48 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Tree/Imaging/VisualBasic/VisualBasicProjectImageProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Tree/Imaging/VisualBasic/VisualBasicProjectImageProvider.cs @@ -5,8 +5,6 @@ using Microsoft.VisualStudio.Imaging; using Microsoft.VisualStudio.ProjectSystem.Imaging; -#nullable disable - namespace Microsoft.VisualStudio.ProjectSystem.VS.Imaging.VisualBasic { /// @@ -21,7 +19,7 @@ public VisualBasicProjectImageProvider() { } - public ProjectImageMoniker GetProjectImage(string key) + public ProjectImageMoniker? GetProjectImage(string key) { Requires.NotNullOrEmpty(key, nameof(key)); From 17e10c9555dc05358f0c9f05cd3b04fe9f346166 Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Tue, 2 Jul 2019 23:21:53 +1000 Subject: [PATCH 4/5] Remove event handlers correctly --- .../IO/SimpleFileWatcher.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/IO/SimpleFileWatcher.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/IO/SimpleFileWatcher.cs index 01009686337..7d162e1054d 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/IO/SimpleFileWatcher.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/IO/SimpleFileWatcher.cs @@ -56,14 +56,14 @@ public void Dispose() _fileWatcher.EnableRaisingEvents = false; if (_handler != null) { - _fileWatcher.Created += _handler; - _fileWatcher.Deleted += _handler; - _fileWatcher.Changed += _handler; + _fileWatcher.Created -= _handler; + _fileWatcher.Deleted -= _handler; + _fileWatcher.Changed -= _handler; _handler = null; } if (_renameHandler != null) { - _fileWatcher.Renamed += _renameHandler; + _fileWatcher.Renamed -= _renameHandler; _renameHandler = null; } _fileWatcher.Dispose(); From 0ad84237f89bae2d734119b1838f7ac513480b15 Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Tue, 2 Jul 2019 23:24:06 +1000 Subject: [PATCH 5/5] Remove outdated documentation --- .../IO/SimpleFileWatcher.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/IO/SimpleFileWatcher.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/IO/SimpleFileWatcher.cs index 7d162e1054d..9b2f2369493 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/IO/SimpleFileWatcher.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/IO/SimpleFileWatcher.cs @@ -46,9 +46,6 @@ public SimpleFileWatcher(string dirToWatch, bool includeSubDirs, NotifyFilters n _renameHandler = renameHandler; } - /// - /// Cleans up our watcher on the Project.Json file - /// public void Dispose() { if (_fileWatcher != null)