From 679a350096addbc0053c499c0021c380d3df176b Mon Sep 17 00:00:00 2001 From: Kevin Pilch Date: Wed, 12 Dec 2018 10:11:35 -0800 Subject: [PATCH 01/20] Start using nullable --- build/Test.ruleset | 5 +++++ build/Versions.props | 2 +- src/Directory.Build.props | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/build/Test.ruleset b/build/Test.ruleset index 7bafdb1a663..1f9ff0f681b 100644 --- a/build/Test.ruleset +++ b/build/Test.ruleset @@ -37,5 +37,10 @@ + + + + + diff --git a/build/Versions.props b/build/Versions.props index 607d19ffd3e..2695204c0aa 100644 --- a/build/Versions.props +++ b/build/Versions.props @@ -19,7 +19,7 @@ 2.3.2 1.0.0-beta1 4.7.1-alpha-00001 - 2.11.0-beta2-63529-05 + 3.0.0-beta2-18616-01 1.1.0-beta1-62624-01 2.6.3-beta1.18614.2 4.6.519 diff --git a/src/Directory.Build.props b/src/Directory.Build.props index a71005f6e5b..29dc277c54a 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -23,8 +23,9 @@ false - 7.3 + 8.0 strict + true From 2fb8515e9333ca56c7ad8219b689c27201bff294 Mon Sep 17 00:00:00 2001 From: Kevin Pilch Date: Fri, 14 Dec 2018 16:57:08 -0800 Subject: [PATCH 02/20] DO NOT MERGE: Treat nullable warnings as warnings instead of errors --- build/build.ps1 | 6 +++--- src/Directory.Build.props | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/build/build.ps1 b/build/build.ps1 index dceb7a52089..b28c73b6e6f 100644 --- a/build/build.ps1 +++ b/build/build.ps1 @@ -165,7 +165,7 @@ function InstallToolset { } if (!(Test-Path $ToolsetBuildProj)) { - & $MsbuildExe $ToolsetRestoreProj /t:restore /m /nologo /clp:None /warnaserror /v:quiet /p:NuGetPackageRoot=$NuGetPackageRoot /p:BaseIntermediateOutputPath=$ToolsetDir /p:ExcludeRestorePackageImports=true $logCmd + & $MsbuildExe $ToolsetRestoreProj /t:restore /m /nologo /clp:None /p:TreatWarningsAsErrors=true /v:quiet /p:NuGetPackageRoot=$NuGetPackageRoot /p:BaseIntermediateOutputPath=$ToolsetDir /p:ExcludeRestorePackageImports=true $logCmd } } @@ -180,14 +180,14 @@ function Build { $useCodecov = $ci -and $env:CODECOV_TOKEN -and ($configuration -eq 'Debug') -and ($env:ghprbPullAuthorLogin -ne 'dotnet-bot') $useOpenCover = $useCodecov - & $MsbuildExe $ToolsetBuildProj /m /nologo /clp:Summary /nodeReuse:$nodeReuse /warnaserror /v:$verbosity $logCmd /p:Configuration=$configuration /p:SolutionPath=$solution /p:Restore=$restore /p:QuietRestore=true /p:Build=$build /p:Rebuild=$rebuild /p:Deploy=$deploy /p:Test=$test /p:IntegrationTest="false" /p:Sign=$sign /p:Pack=$pack /p:UseCodecov=$useCodecov /p:UseOpenCover=$useOpenCover /p:CIBuild=$ci /p:Optimize=$optimize /p:NuGetPackageRoot=$NuGetPackageRoot $properties + & $MsbuildExe $ToolsetBuildProj /m /nologo /clp:Summary /nodeReuse:$nodeReuse /p:TreatWarningsAsErrors=true /v:$verbosity $logCmd /p:Configuration=$configuration /p:SolutionPath=$solution /p:Restore=$restore /p:QuietRestore=true /p:Build=$build /p:Rebuild=$rebuild /p:Deploy=$deploy /p:Test=$test /p:IntegrationTest="false" /p:Sign=$sign /p:Pack=$pack /p:UseCodecov=$useCodecov /p:UseOpenCover=$useOpenCover /p:CIBuild=$ci /p:Optimize=$optimize /p:NuGetPackageRoot=$NuGetPackageRoot $properties if ((-not $?) -or ($lastExitCode -ne 0)) { throw "Aborting after build failure." } if ($useCodecov) { $CodecovProj = Join-Path $PSScriptRoot 'Codecov.proj' - & $MsbuildExe $CodecovProj /m /nologo /clp:Summary /nodeReuse:$nodeReuse /warnaserror /v:diag /t:Codecov /p:Configuration=$configuration /p:UseCodecov=$useCodecov /p:NuGetPackageRoot=$NuGetPackageRoot $properties + & $MsbuildExe $CodecovProj /m /nologo /clp:Summary /nodeReuse:$nodeReuse /p:TreatWarningsAsErrors=true /v:diag /t:Codecov /p:Configuration=$configuration /p:UseCodecov=$useCodecov /p:NuGetPackageRoot=$NuGetPackageRoot $properties } # create suite.json file diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 29dc277c54a..0089242bb7f 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -26,6 +26,7 @@ 8.0 strict true + $(WarningsNotAsErrors);8600;8601;8602;8603;8604;8618;8619;8620;8622;8625;8626;8629 From f367d8b6140de4176381b45b4d370e120d1ac22c Mon Sep 17 00:00:00 2001 From: Kevin Pilch Date: Sun, 16 Dec 2018 13:27:54 -0800 Subject: [PATCH 03/20] Observe async result --- .../ProjectSystem/VS/PropertyPages/PropertyPage.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/PropertyPage.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/PropertyPage.cs index 1c29bbca5c9..e0ff15f12d2 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/PropertyPage.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/PropertyPage.cs @@ -362,7 +362,7 @@ public void SetObjects(uint cObjects, object[] ppunk) } } - OnSetObjects(false); + WaitForAsync(() => OnSetObjects(false)); } } } From 87b078ff504317d3c508a18a1f409fbb565ebf1e Mon Sep 17 00:00:00 2001 From: Kevin Pilch Date: Mon, 17 Dec 2018 09:44:12 -0800 Subject: [PATCH 04/20] Annotate Microsoft.VisualStudio.ProjectSystem.Managed.dll for nullability --- src/Directory.Build.props | 2 +- .../Build/BuildUtilities.cs | 2 +- ...derPrecedenceImportCollectionExtensions.cs | 6 +- .../IO/SimpleFileWatcher.cs | 6 +- .../ImmutableCollectionLinqExtensions.cs | 3 +- .../LinqExtensions.cs | 5 +- ....VisualStudio.ProjectSystem.Managed.csproj | 1 + .../PooledObjects/ObjectPool.cs | 6 +- .../PooledObjects/PooledArray.Enumerator.cs | 2 + .../PooledObjects/PooledArray.cs | 15 ++- .../PooledObjects/PooledDictionary.cs | 2 +- .../PooledObjects/PooledHashSet.cs | 2 +- .../PooledObjects/PooledStringBuilder.cs | 2 +- .../AbstractMultiLifetimeComponent.cs | 10 +- ...cialFolderProjectTreePropertiesProvider.cs | 2 +- .../ActiveConfiguredProjectsLoader.cs | 2 +- .../ActiveConfiguredProjectsProvider.cs | 29 ++--- ...gnerFolderProjectTreePropertiesProvider.cs | 8 +- ...itlyActiveConfiguredProjectReadyToBuild.cs | 2 +- ...seProjectConfigurationDimensionProvider.cs | 10 +- ...iguredProjectImplicitActivationTracking.cs | 4 +- .../ProjectSystem/DataFlowUtilities.cs | 8 +- .../Debug/ActiveDebugFrameworkServices.cs | 10 +- .../Debug/IActiveDebugFrameworkServices.cs | 4 +- .../ProjectSystem/Debug/ILaunchProfile.cs | 16 +-- .../ProjectSystem/Debug/ILaunchSettings.cs | 2 +- .../Debug/ILaunchSettingsProvider.cs | 6 +- .../Debug/IWritableLaunchProfile.cs | 12 +- .../Debug/IWritableLaunchSettings.cs | 2 +- .../ProjectSystem/Debug/LaunchProfile.cs | 18 +-- .../ProjectSystem/Debug/LaunchProfileData.cs | 16 +-- .../ProjectSystem/Debug/LaunchSettings.cs | 21 ++-- .../ProjectSystem/Debug/LaunchSettingsData.cs | 6 +- .../Debug/LaunchSettingsProvider.cs | 105 +++++++++++++----- .../Debug/WritableLaunchProfile.cs | 12 +- .../Debug/WritableLaunchSettings.cs | 7 +- .../ProjectSystem/FileItemServices.cs | 4 +- .../IActiveConfiguredProjectsProvider.cs | 4 +- .../ICreateFileFromTemplateService.cs | 2 +- .../Imaging/IProjectImageProvider.cs | 2 +- .../Imaging/ProjectImageProviderAggregator.cs | 4 +- .../AggregateWorkspaceProjectContext.cs | 2 +- .../ApplyChangesToWorkspaceContext.cs | 24 ++-- .../ContextHandlerProvider.cs | 4 +- .../AbstractWorkspaceContextHandler.cs | 4 +- .../Handlers/DynamicItemHandler.cs | 2 +- .../Handlers/SourceItemHandler.cs | 2 +- .../LanguageServices/ILanguageServiceHost.cs | 6 +- .../IProjectContextProvider.cs | 2 +- .../IUnconfiguredProjectHostObject.cs | 2 +- .../IWorkspaceProjectContextProvider.cs | 2 +- .../LanguageServices/LanguageServiceHost.cs | 47 ++++---- .../UnconfiguredProjectContextProvider.cs | 12 +- ...ontextHost.WorkspaceContextHostInstance.cs | 14 ++- ...vider.ForegroundWorkspaceProjectContext.cs | 4 +- .../WorkspaceProjectContextProvider.cs | 6 +- ...jectLoggerExtensions.ProjectLoggerBatch.cs | 30 ++--- .../ProjectSystem/ProjectChangeDiff.cs | 2 +- ...tRootImageProjectTreePropertiesProvider.cs | 2 +- .../ProjectTreeProviderExtensions.cs | 2 +- .../AssemblyInfoProperties.cs | 13 ++- ...eAssemblyAttributePropertyValueProvider.cs | 14 +-- .../DelegatedProjectPropertiesBase.cs | 8 +- .../ApplicationManifestValueProvider.cs | 6 +- .../IInterceptingPropertyValueProvider.cs | 8 +- .../InterceptedProjectProperties.cs | 10 +- .../InterceptingPropertyValueProviderBase.cs | 8 +- .../BaseVersionValueProvider.cs | 4 +- .../AssemblyOriginatorKeyFileValueProvider.cs | 2 +- .../TargetFrameworkValueProvider.cs | 2 +- .../ProjectRuleSnapshotExtensions.cs | 4 +- .../Properties/RuleExtensions.cs | 2 +- .../AbstractSpecialFileProvider.cs | 16 +-- .../AppDesignerFolderSpecialFileProvider.cs | 15 +-- .../AppManifestSpecialFileProvider.cs | 2 +- .../UnconfiguredProjectTasksService.cs | 4 +- .../UpToDate/BuildUpToDateCheck.cs | 51 +++++---- .../UpToDate/BuildUpToDateCheckLogger.cs | 8 +- .../UpToDate/UpToDateCheckItemComparer.cs | 8 +- .../StringComparers.cs | 2 +- .../StringFormat.cs | 12 +- .../Text/LazyStringSplit.cs | 8 +- .../Threading/Tasks/CancellationSeries.cs | 2 + 83 files changed, 428 insertions(+), 332 deletions(-) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 0089242bb7f..9efc21cf592 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -25,7 +25,7 @@ false 8.0 strict - true + $(WarningsNotAsErrors);8600;8601;8602;8603;8604;8618;8619;8620;8622;8625;8626;8629 diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Build/BuildUtilities.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Build/BuildUtilities.cs index abd7fd0a3e9..b610b447765 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Build/BuildUtilities.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Build/BuildUtilities.cs @@ -68,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)) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Composition/OrderPrecedenceImportCollectionExtensions.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Composition/OrderPrecedenceImportCollectionExtensions.cs index b88a2f4c096..4a099f9fadb 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Composition/OrderPrecedenceImportCollectionExtensions.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Composition/OrderPrecedenceImportCollectionExtensions.cs @@ -56,7 +56,8 @@ internal static IEnumerable ExtensionValues(this OrderPrecedenceImportColl } } - public static T FirstOrDefaultValue(this OrderPrecedenceImportCollection imports, Func predicate) + public static T? FirstOrDefaultValue(this OrderPrecedenceImportCollection imports, Func predicate) + where T : class { Requires.NotNull(imports, nameof(imports)); @@ -72,7 +73,8 @@ public static T FirstOrDefaultValue(this OrderPrecedenceImportCollection i return default; } - public static TImport FirstOrDefaultValue(this OrderPrecedenceImportCollection imports, Func predicate, TArg arg) + public static TImport? FirstOrDefaultValue(this OrderPrecedenceImportCollection imports, Func predicate, TArg arg) + where TImport : class { Requires.NotNull(imports, nameof(imports)); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/IO/SimpleFileWatcher.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/IO/SimpleFileWatcher.cs index ff1f9fe754f..e54d5969ee5 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/IO/SimpleFileWatcher.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/IO/SimpleFileWatcher.cs @@ -10,9 +10,9 @@ namespace Microsoft.VisualStudio.IO /// internal sealed class SimpleFileWatcher : IDisposable { - private FileSystemWatcher FileWatcher { get; set; } - private FileSystemEventHandler _handler; - private RenamedEventHandler _renameHandler; + private FileSystemWatcher? FileWatcher { get; set; } + private FileSystemEventHandler? _handler; + private RenamedEventHandler? _renameHandler; // For unit tests public SimpleFileWatcher() diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ImmutableCollectionLinqExtensions.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ImmutableCollectionLinqExtensions.cs index 95218e96bff..78b476087c1 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ImmutableCollectionLinqExtensions.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ImmutableCollectionLinqExtensions.cs @@ -39,7 +39,8 @@ public static bool Any(this ImmutableDictionary immu return false; } - public static T FirstOrDefault(this ImmutableArray immutableArray, Func predicate, TArg arg) + public static T? FirstOrDefault(this ImmutableArray immutableArray, Func predicate, TArg arg) + where T : class { foreach (T obj in immutableArray) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/LinqExtensions.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/LinqExtensions.cs index d0a055bbc73..4a05e84ca38 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/LinqExtensions.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/LinqExtensions.cs @@ -17,11 +17,12 @@ public static T FirstOrDefault(this IEnumerable source, Func(this IEnumerable source, Func predicate, TArg arg) + public static T? SingleOrDefault(this IEnumerable source, Func predicate, TArg arg) + where T : class { using (IEnumerator enumerator = source.GetEnumerator()) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Microsoft.VisualStudio.ProjectSystem.Managed.csproj b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Microsoft.VisualStudio.ProjectSystem.Managed.csproj index 1f9e4562ce1..3b95c1ee18f 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Microsoft.VisualStudio.ProjectSystem.Managed.csproj +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Microsoft.VisualStudio.ProjectSystem.Managed.csproj @@ -12,6 +12,7 @@ Microsoft VisualStudio Managed Project System Roslyn Managed Project System VisualStudio $(NoWarn);NU5125 + true diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/ObjectPool.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/ObjectPool.cs index 205a71e2fec..3211bc4678f 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/ObjectPool.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/ObjectPool.cs @@ -33,7 +33,7 @@ private struct Element // 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 @@ -72,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(); @@ -93,7 +93,9 @@ private T AllocateSlow() T inst = items[i].Value; if (inst != null) { +#pragma warning disable CS8625 // Workaround https://github.com/dotnet/roslyn/issues/31865 if (inst == Interlocked.CompareExchange(ref items[i].Value, null, inst)) +#pragma warning restore CS8625 { return inst; } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledArray.Enumerator.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledArray.Enumerator.cs index daea612a68b..ed4f7643df6 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledArray.Enumerator.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledArray.Enumerator.cs @@ -32,7 +32,9 @@ public void Dispose() { } +#pragma warning disable CS8603 // Workaround https://github.com/dotnet/roslyn/issues/31867 object System.Collections.IEnumerator.Current => Current; +#pragma warning restore CS8603 public void Reset() => _index = -1; } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledArray.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledArray.cs index 3e27ca8a48e..ab00f4088c1 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledArray.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledArray.cs @@ -13,7 +13,7 @@ internal sealed partial class PooledArray : IReadOnlyCollection, IReadOnly { private readonly ImmutableArray.Builder _builder; - private readonly ObjectPool> _pool; + private readonly ObjectPool>? _pool; public PooledArray(int size) { @@ -71,7 +71,9 @@ public void SetItem(int index, T value) { while (index > _builder.Count) { +#pragma warning disable CS8625 // Workaround https://github.com/dotnet/roslyn/issues/31865 _builder.Add(default); +#pragma warning restore CS8625 } if (index == _builder.Count) @@ -177,7 +179,10 @@ public ImmutableArray ToDowncastedImmutable() var tmp = PooledArray.GetInstance(Count); foreach (T i in this) { +#pragma warning disable CS8600,CS8604 // Workaround for https://github.com/dotnet/roslyn/issues/31866 tmp.Add((U)i); +#pragma warning restore CS8600,CS8604 + } return tmp.ToImmutableAndFree(); @@ -213,7 +218,7 @@ public T[] ToArrayAndFree() // 1) Expose Freeing primitive. public void Free() { - ObjectPool> pool = _pool; + ObjectPool>? pool = _pool; if (pool != null) { // We do not want to retain (potentially indefinitely) very large builders @@ -274,7 +279,7 @@ public static ObjectPool> CreatePool() public static ObjectPool> CreatePool(int size) { - ObjectPool> pool = null; + ObjectPool>? pool = null; pool = new ObjectPool>(() => new PooledArray(pool), size); return pool; } @@ -284,7 +289,9 @@ public Enumerator GetEnumerator() return new Enumerator(this); } +#pragma warning disable CS8616 // Workaround https://github.com/dotnet/roslyn/issues/31862 IEnumerator IEnumerable.GetEnumerator() +#pragma warning restore CS8616 { return GetEnumerator(); } @@ -294,7 +301,7 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() return GetEnumerator(); } - internal Dictionary> ToDictionary(Func keySelector, IEqualityComparer comparer = null) + internal Dictionary> ToDictionary(Func keySelector, IEqualityComparer? comparer = null) { if (Count == 1) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledDictionary.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledDictionary.cs index e97fe2f1e3e..484a68dfe68 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledDictionary.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledDictionary.cs @@ -35,7 +35,7 @@ public void Free() // if someone needs to create a pool; public static ObjectPool> CreatePool() { - ObjectPool> pool = null; + 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 71449816f5e..c80d1c028be 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledHashSet.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledHashSet.cs @@ -27,7 +27,7 @@ public void Free() // if someone needs to create a pool; public static ObjectPool> CreatePool() { - ObjectPool> pool = null; + 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 c932732472d..1886b1716b4 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledStringBuilder.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledStringBuilder.cs @@ -63,7 +63,7 @@ public string ToStringAndFree(int startIndex, int length) /// public static ObjectPool CreatePool(int size = 32) { - ObjectPool pool = null; + ObjectPool? pool = null; pool = new ObjectPool(() => new PooledStringBuilder(pool), size); return pool; } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/AbstractMultiLifetimeComponent.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/AbstractMultiLifetimeComponent.cs index a659808b00a..50088c11a08 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/AbstractMultiLifetimeComponent.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/AbstractMultiLifetimeComponent.cs @@ -15,14 +15,14 @@ internal abstract class AbstractMultiLifetimeComponent : OnceInitializedOnceDisp { private readonly object _lock = new object(); private TaskCompletionSource _loadedSource = new TaskCompletionSource(); - private IMultiLifetimeInstance _instance; + private IMultiLifetimeInstance? _instance; protected AbstractMultiLifetimeComponent(JoinableTaskContextNode joinableTaskContextNode) : base(joinableTaskContextNode) { } - public IMultiLifetimeInstance Instance + public IMultiLifetimeInstance? Instance { get { return _instance; } } @@ -49,7 +49,7 @@ public async Task LoadAsync() private async Task LoadCoreAsync() { - TaskCompletionSource loadedSource = null; + TaskCompletionSource? loadedSource = null; IMultiLifetimeInstance instance; lock (_lock) { @@ -65,12 +65,12 @@ private async Task LoadCoreAsync() // While all callers should wait on InitializeAsync, // only one should complete the completion source await instance.InitializeAsync(); - loadedSource?.SetResult(null); + loadedSource?.SetResult(null!); } public Task UnloadAsync() { - IMultiLifetimeInstance instance = null; + IMultiLifetimeInstance? instance = null; lock (_lock) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/AbstractSpecialFolderProjectTreePropertiesProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/AbstractSpecialFolderProjectTreePropertiesProvider.cs index 990056fdb1d..08976993000 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/AbstractSpecialFolderProjectTreePropertiesProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/AbstractSpecialFolderProjectTreePropertiesProvider.cs @@ -93,7 +93,7 @@ private void ApplySpecialFolderProperties(IProjectTreeCustomizablePropertyValues propertyValues.Flags = propertyValues.Flags.Union(FolderFlags); // Avoid overwriting icon if the image provider didn't provide one - ProjectImageMoniker icon = _imageProvider.GetProjectImage(FolderImageKey); + ProjectImageMoniker? icon = _imageProvider.GetProjectImage(FolderImageKey); if (icon != null) { propertyValues.Icon = icon; diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ActiveConfiguredProjectsLoader.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ActiveConfiguredProjectsLoader.cs index 2d1e345d719..c061cf95e25 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ActiveConfiguredProjectsLoader.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ActiveConfiguredProjectsLoader.cs @@ -17,7 +17,7 @@ internal class ActiveConfiguredProjectsLoader : OnceInitializedOnceDisposed private readonly IActiveConfigurationGroupService _activeConfigurationGroupService; private readonly IUnconfiguredProjectTasksService _tasksService; private readonly ITargetBlock>> _targetBlock; - private IDisposable _subscription; + private IDisposable? _subscription; [ImportingConstructor] public ActiveConfiguredProjectsLoader(UnconfiguredProject project, IActiveConfigurationGroupService activeConfigurationGroupService, IUnconfiguredProjectTasksService tasksService) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ActiveConfiguredProjectsProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ActiveConfiguredProjectsProvider.cs index d210851011b..7f43f11d99d 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ActiveConfiguredProjectsProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ActiveConfiguredProjectsProvider.cs @@ -76,28 +76,31 @@ public async Task> GetActiveConfi { var builder = PooledDictionary.GetInstance(); - ActiveConfiguredObjects projects = await GetActiveConfiguredProjectsAsync(); + ActiveConfiguredObjects? projects = await GetActiveConfiguredProjectsAsync(); - bool isCrossTargeting = projects.Objects.All(project => project.ProjectConfiguration.IsCrossTargeting()); - if (isCrossTargeting) + if (projects != null) { - foreach (ConfiguredProject project in projects.Objects) + bool isCrossTargeting = projects.Objects.All(project => project.ProjectConfiguration.IsCrossTargeting()); + if (isCrossTargeting) { - string targetFramework = project.ProjectConfiguration.Dimensions[ConfigurationGeneral.TargetFrameworkProperty]; - builder.Add(targetFramework, project); + foreach (ConfiguredProject project in projects.Objects) + { + string targetFramework = project.ProjectConfiguration.Dimensions[ConfigurationGeneral.TargetFrameworkProperty]; + builder.Add(targetFramework, project); + } + } + else + { + builder.Add(string.Empty, projects.Objects[0]); } - } - else - { - builder.Add(string.Empty, projects.Objects[0]); } return builder.ToImmutableDictionaryAndFree(); } - public async Task> GetActiveConfiguredProjectsAsync() + public async Task?> GetActiveConfiguredProjectsAsync() { - ActiveConfiguredObjects configurations = await GetActiveProjectConfigurationsAsync(); + ActiveConfiguredObjects? configurations = await GetActiveProjectConfigurationsAsync(); if (configurations == null) return null; @@ -113,7 +116,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; if (activeSolutionConfiguration == null) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/AppDesignerFolderProjectTreePropertiesProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/AppDesignerFolderProjectTreePropertiesProvider.cs index 7f3ede6f5a9..0e834aa657a 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/AppDesignerFolderProjectTreePropertiesProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/AppDesignerFolderProjectTreePropertiesProvider.cs @@ -58,11 +58,11 @@ public void UpdateProjectTreeSettings(IImmutableDictionaryName 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)); @@ -44,7 +44,7 @@ public string PropertyName get; } - public string DimensionDefaultValue + public string? DimensionDefaultValue { get; } @@ -134,7 +134,7 @@ public virtual async Task>> public async Task>> GetBestGuessDefaultValuesForDimensionsAsync(UnconfiguredProject project) { - string defaultValue = await FindDefaultValueFromDimensionPropertyAsync(project) ?? DimensionDefaultValue; + string? defaultValue = await FindDefaultValueFromDimensionPropertyAsync(project) ?? DimensionDefaultValue; if (defaultValue != null) return new[] { new KeyValuePair(DimensionName, defaultValue) }; @@ -158,7 +158,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(); @@ -168,7 +168,7 @@ protected async Task GetPropertyValue(UnconfiguredProject project, strin }); } - private async Task FindDefaultValueFromDimensionPropertyAsync(UnconfiguredProject project) + private async Task FindDefaultValueFromDimensionPropertyAsync(UnconfiguredProject project) { string values = await FindDimensionPropertyAsync(project); if (string.IsNullOrEmpty(values)) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ConfiguredProjectImplicitActivationTracking.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ConfiguredProjectImplicitActivationTracking.cs index 82303f2b334..353abccea03 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ConfiguredProjectImplicitActivationTracking.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ConfiguredProjectImplicitActivationTracking.cs @@ -23,7 +23,7 @@ internal class ConfiguredProjectImplicitActivationTracking : OnceInitializedOnce private readonly IActiveConfigurationGroupService _activeConfigurationGroupService; private readonly ITargetBlock>> _targetBlock; private TaskCompletionSource _isImplicitlyActiveSource = new TaskCompletionSource(); - private IDisposable _subscription; + private IDisposable? _subscription; [ImportingConstructor] public ConfiguredProjectImplicitActivationTracking(ConfiguredProject project, IActiveConfigurationGroupService activeConfigurationGroupService, [Import(ExportContractNames.Scopes.ConfiguredProject)]IProjectAsynchronousTasksService tasksService) @@ -121,7 +121,7 @@ private Task OnActiveConfigurationsChanged(IProjectVersionedValue tasks = ImplicitlyActiveServices.Select(c => c.Value.ActivateAsync()); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/DataFlowUtilities.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/DataFlowUtilities.cs index f1856faca73..e1ab891dc0f 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/DataFlowUtilities.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/DataFlowUtilities.cs @@ -75,7 +75,7 @@ public static IDisposable LinkToAction(this ISourceBlock /// is . /// - public static IDisposable LinkToAction(this ISourceBlock> source, Action> target, bool suppressVersionOnlyUpdates = true, IEnumerable ruleNames = null) + public static IDisposable LinkToAction(this ISourceBlock> source, Action> target, bool suppressVersionOnlyUpdates = true, IEnumerable? ruleNames = null) { Requires.NotNull(source, nameof(source)); Requires.NotNull(target, nameof(target)); @@ -149,7 +149,7 @@ public static IDisposable LinkToAsyncAction(this ISourceBlock /// is . /// - public static IDisposable LinkToAsyncAction(this ISourceBlock> source, Func, Task> target, bool suppressVersionOnlyUpdates = true, IEnumerable ruleNames = null) + public static IDisposable LinkToAsyncAction(this ISourceBlock> source, Func, Task> target, bool suppressVersionOnlyUpdates = true, IEnumerable? ruleNames = null) { Requires.NotNull(source, nameof(source)); Requires.NotNull(target, nameof(target)); @@ -227,7 +227,7 @@ internal static Func CaptureAndApplyExecutionContext(Func< SynchronizationContext currentSynchronizationContext = SynchronizationContext.Current; using (ExecutionContext copy = context.CreateCopy()) { - Task result = null; + Task? result = null; ExecutionContext.Run( copy, state => @@ -236,7 +236,7 @@ internal static Func CaptureAndApplyExecutionContext(Func< result = function(input); }, null); - return result; + return result!; } }; } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/ActiveDebugFrameworkServices.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/ActiveDebugFrameworkServices.cs index 6e6947b6eb7..be7cde3c5b5 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/ActiveDebugFrameworkServices.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/ActiveDebugFrameworkServices.cs @@ -30,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. @@ -57,10 +57,10 @@ 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; } @@ -79,7 +79,7 @@ public async Task GetConfiguredProjectForActiveFrameworkAsync return configProjects.First().Value; } - string activeFramework = await GetActiveDebuggingFrameworkPropertyAsync(); + string? activeFramework = await GetActiveDebuggingFrameworkPropertyAsync(); if (!string.IsNullOrWhiteSpace(activeFramework)) { if (configProjects.TryGetValue(activeFramework, out ConfiguredProject configuredProject)) @@ -90,7 +90,7 @@ 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 f351657b2bf..7e5c841ebf8 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/IActiveDebugFrameworkServices.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/IActiveDebugFrameworkServices.cs @@ -14,7 +14,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 @@ -24,7 +24,7 @@ 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 diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/ILaunchProfile.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/ILaunchProfile.cs index 64effe2b8f3..fac536c82cd 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/ILaunchProfile.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/ILaunchProfile.cs @@ -10,14 +10,14 @@ namespace Microsoft.VisualStudio.ProjectSystem.Debug /// public interface ILaunchProfile { - string Name { get; } - string CommandName { get; } - string ExecutablePath { get; } - string CommandLineArgs { get; } - string WorkingDirectory { get; } + string? Name { get; } + string? CommandName { get; } + string? ExecutablePath { get; } + string? CommandLineArgs { get; } + string? WorkingDirectory { get; } bool LaunchBrowser { get; } - string LaunchUrl { get; } - ImmutableDictionary EnvironmentVariables { get; } - ImmutableDictionary OtherSettings { get; } + string? LaunchUrl { get; } + ImmutableDictionary? EnvironmentVariables { get; } + ImmutableDictionary? OtherSettings { get; } } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/ILaunchSettings.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/ILaunchSettings.cs index f90a112c3b5..398c7f79751 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/ILaunchSettings.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/ILaunchSettings.cs @@ -9,7 +9,7 @@ namespace Microsoft.VisualStudio.ProjectSystem.Debug /// public interface ILaunchSettings { - ILaunchProfile ActiveProfile { get; } + ILaunchProfile? ActiveProfile { get; } /// /// Access to the current set of launch profiles diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/ILaunchSettingsProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/ILaunchSettingsProvider.cs index d8f1bc7d17c..f35642f7aa1 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/ILaunchSettingsProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/ILaunchSettingsProvider.cs @@ -14,12 +14,12 @@ public interface ILaunchSettingsProvider { IReceivableSourceBlock SourceBlock { get; } - ILaunchSettings CurrentSnapshot { get; } + ILaunchSettings? CurrentSnapshot { get; } [Obsolete("Use ILaunchSettingsProvider2.GetLaunchSettingsFilePathAsync instead.")] string LaunchSettingsFile { get; } - ILaunchProfile ActiveProfile { get; } + ILaunchProfile? ActiveProfile { get; } // Replaces the current set of profiles with the contents of profiles. If changes were // made, the file will be checked out and updated. If the active profile is different, the @@ -27,7 +27,7 @@ public interface ILaunchSettingsProvider Task UpdateAndSaveSettingsAsync(ILaunchSettings profiles); // Blocks until at least one snapshot has been generated. - Task WaitForFirstSnapshot(int timeout); + Task WaitForFirstSnapshot(int timeout); /// /// Adds the given profile to the list and saves to disk. If a profile with the same diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/IWritableLaunchProfile.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/IWritableLaunchProfile.cs index 1c65a7f269c..fa567c1521d 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/IWritableLaunchProfile.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/IWritableLaunchProfile.cs @@ -10,13 +10,13 @@ namespace Microsoft.VisualStudio.ProjectSystem.Debug /// public interface IWritableLaunchProfile { - string Name { get; set; } - string CommandName { get; set; } - string ExecutablePath { get; set; } - string CommandLineArgs { get; set; } - string WorkingDirectory { get; set; } + string? Name { get; set; } + string? CommandName { get; set; } + string? ExecutablePath { get; set; } + string? CommandLineArgs { get; set; } + string? WorkingDirectory { get; set; } bool LaunchBrowser { get; set; } - string LaunchUrl { get; set; } + string? LaunchUrl { get; set; } Dictionary EnvironmentVariables { get; } Dictionary OtherSettings { get; } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/IWritableLaunchSettings.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/IWritableLaunchSettings.cs index 97dc2d03568..4f9821e7412 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/IWritableLaunchSettings.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/IWritableLaunchSettings.cs @@ -9,7 +9,7 @@ namespace Microsoft.VisualStudio.ProjectSystem.Debug /// public interface IWritableLaunchSettings { - IWritableLaunchProfile ActiveProfile { get; set; } + IWritableLaunchProfile? ActiveProfile { get; set; } List Profiles { get; } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/LaunchProfile.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/LaunchProfile.cs index 24a14e58707..ba86b2ce2ca 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/LaunchProfile.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/LaunchProfile.cs @@ -62,22 +62,22 @@ public LaunchProfile(IWritableLaunchProfile writableProfile) OtherSettings = writableProfile.OtherSettings.Count == 0 ? null : writableProfile.OtherSettings.ToImmutableDictionary(); } - public string Name { get; set; } - public string CommandName { get; set; } - public string ExecutablePath { get; set; } - public string CommandLineArgs { get; set; } - public string WorkingDirectory { get; set; } + public string? Name { get; set; } + public string? CommandName { get; set; } + public string? ExecutablePath { get; set; } + public string? CommandLineArgs { get; set; } + public string? WorkingDirectory { get; set; } public bool LaunchBrowser { get; set; } - public string LaunchUrl { get; set; } + public string? LaunchUrl { get; set; } public bool DoNotPersist { get; set; } - public ImmutableDictionary EnvironmentVariables { get; set; } - public ImmutableDictionary OtherSettings { get; set; } + public ImmutableDictionary? EnvironmentVariables { get; set; } + public ImmutableDictionary? OtherSettings { get; set; } /// /// Compares two profile names. Using this function ensures case comparison consistency /// - public static bool IsSameProfileName(string name1, string name2) + public static bool IsSameProfileName(string? name1, string? name2) { return string.Equals(name1, name2, StringComparison.Ordinal); } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/LaunchProfileData.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/LaunchProfileData.cs index b80bf135619..e0a4b774bca 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/LaunchProfileData.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/LaunchProfileData.cs @@ -41,33 +41,33 @@ public static bool IsKnownProfileProperty(string propertyName) } // We don't serialize the name as it the dictionary index - public string Name { get; set; } + public string? Name { get; set; } // Or serialize the InMemoryProfile state public bool InMemoryProfile { get; set; } [JsonProperty(PropertyName = Prop_commandName)] - public string CommandName { get; set; } + public string? CommandName { get; set; } [JsonProperty(PropertyName = Prop_executablePath)] - public string ExecutablePath { get; set; } + public string? ExecutablePath { get; set; } [JsonProperty(PropertyName = Prop_commandLineArgs)] - public string CommandLineArgs { get; set; } + public string? CommandLineArgs { get; set; } [JsonProperty(PropertyName = Prop_workingDirectory)] - public string WorkingDirectory { get; set; } + public string? WorkingDirectory { get; set; } [JsonProperty(PropertyName = Prop_launchBrowser)] public bool? LaunchBrowser { get; set; } [JsonProperty(PropertyName = Prop_launchUrl)] - public string LaunchUrl { get; set; } + public string? LaunchUrl { get; set; } [JsonProperty(PropertyName = Prop_environmentVariables)] - public IDictionary EnvironmentVariables { get; set; } + public IDictionary? EnvironmentVariables { get; set; } - public IDictionary OtherSettings { get; set; } + public IDictionary? OtherSettings { get; set; } /// /// To handle custom settings, we serialize using LaunchProfileData first and then walk the settings diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/LaunchSettings.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/LaunchSettings.cs index a60c4f65aee..e93bd674633 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/LaunchSettings.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/LaunchSettings.cs @@ -11,12 +11,12 @@ namespace Microsoft.VisualStudio.ProjectSystem.Debug { internal class LaunchSettings : ILaunchSettings { - private readonly string _activeProfileName; + private readonly string? _activeProfileName; /// /// Represents the current set of launch settings. Creation from an existing set of profiles. /// - public LaunchSettings(IEnumerable profiles, IDictionary globalSettings, string activeProfile = null) + public LaunchSettings(IEnumerable profiles, IDictionary? globalSettings, string? activeProfile = null) { Profiles = ImmutableList.Empty; foreach (ILaunchProfile profile in profiles) @@ -28,12 +28,15 @@ public LaunchSettings(IEnumerable profiles, IDictionary.Empty; - foreach (LaunchProfileData profile in settingsData.Profiles) + if (settingsData.Profiles != null) { - Profiles = Profiles.Add(new LaunchProfile(profile)); + foreach (LaunchProfileData profile in settingsData.Profiles) + { + Profiles = Profiles.Add(new LaunchProfile(profile)); + } } GlobalSettings = settingsData.OtherSettings == null ? ImmutableStringDictionary.EmptyOrdinal : settingsData.OtherSettings.ToImmutableDictionary(); @@ -62,7 +65,7 @@ public LaunchSettings(IWritableLaunchSettings settings) else { string jsonString = JsonConvert.SerializeObject(value, Formatting.Indented, jsonSerializerSettings); - object clonedObject = JsonConvert.DeserializeObject(jsonString, value.GetType()); + object clonedObject = JsonConvert.DeserializeObject(jsonString, value?.GetType()); GlobalSettings = GlobalSettings.Add(key, clonedObject); } } @@ -86,8 +89,8 @@ public object GetGlobalSetting(string settingName) return o; } - private ILaunchProfile _activeProfile; - public ILaunchProfile ActiveProfile + private ILaunchProfile? _activeProfile; + public ILaunchProfile? ActiveProfile { get { @@ -96,7 +99,7 @@ public ILaunchProfile ActiveProfile // If no active profile specified, or the active one is no longer valid, assume the first one if (!string.IsNullOrWhiteSpace(_activeProfileName)) { - _activeProfile = Profiles.FirstOrDefault(p => LaunchProfile.IsSameProfileName(p.Name, _activeProfileName)); + _activeProfile = Profiles.FirstOrDefault(p => LaunchProfile.IsSameProfileName(p?.Name, _activeProfileName)); } if (_activeProfile == null) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/LaunchSettingsData.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/LaunchSettingsData.cs index eb1eb32b144..81f40ba1a92 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/LaunchSettingsData.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/LaunchSettingsData.cs @@ -5,12 +5,12 @@ namespace Microsoft.VisualStudio.ProjectSystem.Debug { /// - /// This class is used to hold the data serialized from the json file. + /// This class is used to hold the data serialized from the json file. /// internal class LaunchSettingsData { - public Dictionary OtherSettings { get; set; } + public Dictionary? OtherSettings { get; set; } - public List Profiles { get; set; } + public List? Profiles { get; set; } } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/LaunchSettingsProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/LaunchSettingsProvider.cs index e080e878935..4f8913ccaff 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/LaunchSettingsProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/LaunchSettingsProvider.cs @@ -62,8 +62,8 @@ public LaunchSettingsProvider(UnconfiguredProject project, IUnconfiguredProjectS protected OrderPrecedenceImportCollection SourceControlIntegrations { get; set; } // The source for our dataflow - private IReceivableSourceBlock _changedSourceBlock; - protected IBroadcastBlock _broadcastBlock; + private IReceivableSourceBlock? _changedSourceBlock; + protected IBroadcastBlock? _broadcastBlock; protected IFileSystem FileManager { get; set; } @@ -83,14 +83,14 @@ public LaunchSettingsProvider(UnconfiguredProject project, IUnconfiguredProjectS // the launch settings file or when there are no profiles specified (like class libraries) public const string ErrorProfileCommandName = "ErrorProfile"; - protected SimpleFileWatcher FileWatcher { get; set; } + protected SimpleFileWatcher? FileWatcher { get; set; } // When we are saving the file we set this to minimize noise from the file change protected bool IgnoreFileChanges { get; set; } protected TimeSpan FileChangeProcessingDelay = TimeSpan.FromMilliseconds(500); - public ITaskDelayScheduler FileChangeScheduler { get; protected set; } + public ITaskDelayScheduler? FileChangeScheduler { get; protected set; } // Tracks when we last read or wrote to the file. Prevents picking up needless changes protected DateTime LastSettingsFileSyncTime { get; set; } @@ -99,9 +99,9 @@ public LaunchSettingsProvider(UnconfiguredProject project, IUnconfiguredProjectS private readonly TaskCompletionSource _firstSnapshotCompletionSource = new TaskCompletionSource(); - protected IDisposable ProjectRuleSubscriptionLink { get; set; } + protected IDisposable? ProjectRuleSubscriptionLink { get; set; } - private SequentialTaskExecutor _sequentialTaskQueue = new SequentialTaskExecutor(); + private SequentialTaskExecutor? _sequentialTaskQueue = new SequentialTaskExecutor(); [Obsolete("Use GetLaunchSettingsFilePathAsync instead.")] public string LaunchSettingsFile @@ -119,11 +119,11 @@ public string LaunchSettingsFile /// Returns the active profile. Looks up the value of the ActiveProfile property. If the value doesn't match the /// any of the profiles, the first one is returned /// - public ILaunchProfile ActiveProfile + public ILaunchProfile? ActiveProfile { get { - ILaunchSettings snapshot = CurrentSnapshot; + ILaunchSettings? snapshot = CurrentSnapshot; return snapshot?.ActiveProfile; } } @@ -135,7 +135,7 @@ public IReceivableSourceBlock SourceBlock get { EnsureInitialized(); - return _changedSourceBlock; + return _changedSourceBlock!; } } @@ -143,8 +143,8 @@ public IReceivableSourceBlock SourceBlock /// IDebugProfileProvider /// Access to the current set of profile information /// - private ILaunchSettings _currentSnapshot; - public ILaunchSettings CurrentSnapshot + private ILaunchSettings? _currentSnapshot; + public ILaunchSettings? CurrentSnapshot { get { @@ -205,9 +205,14 @@ protected async Task ProjectRuleBlock_ChangedAsync(IProjectVersionedValue { @@ -226,7 +231,7 @@ await _sequentialTaskQueue.ExecuteTask(async () => /// protected async Task UpdateActiveProfileInSnapshotAsync(string activeProfile) { - ILaunchSettings snapshot = CurrentSnapshot; + ILaunchSettings? snapshot = CurrentSnapshot; if (snapshot == null || await SettingsFileHasChangedAsync()) { await UpdateProfilesAsync(activeProfile); @@ -243,7 +248,7 @@ protected async Task UpdateActiveProfileInSnapshotAsync(string activeProfile) /// a profile on disk has the same name as an in-memory profile, the one on disk wins. It tries to add the in-memory profiles /// in the same order they appeared prior to the disk change. /// - protected async Task UpdateProfilesAsync(string activeProfile) + protected async Task UpdateProfilesAsync(string? activeProfile) { try { @@ -261,13 +266,18 @@ protected async Task UpdateProfilesAsync(string activeProfile) // If there are no profiles, we will add a default profile to run the project. W/o it our debugger // won't be called on F5 and the user will see a poor error message + if (launchSettingData.Profiles == null) + { + launchSettingData.Profiles = new List(1); + } + if (launchSettingData.Profiles.Count == 0) { launchSettingData.Profiles.Add(new LaunchProfileData() { Name = Path.GetFileNameWithoutExtension(CommonProjectServices.Project.FullPath), CommandName = RunProjectCommandName }); } // If we have a previous snapshot merge in in-memory profiles - ILaunchSettings prevSnapshot = CurrentSnapshot; + ILaunchSettings? prevSnapshot = CurrentSnapshot; if (prevSnapshot != null) { MergeExistingInMemoryProfiles(launchSettingData, prevSnapshot); @@ -310,6 +320,11 @@ protected static void MergeExistingInMemoryProfiles(LaunchSettingsData newSnapsh { // Create a new one from the existing in-memory profile and insert it in the same location, or the end if it // is beyond the end of the list + if (newSnapshot.Profiles == null) + { + newSnapshot.Profiles = new List(1); + } + if (i > newSnapshot.Profiles.Count) { newSnapshot.Profiles.Add(LaunchProfileData.FromILaunchProfile(profile)); @@ -389,7 +404,7 @@ protected async Task FinishUpdateAsync(ILaunchSettings newSnapshot, bool ensureP /// /// Gets the active profile based on the property changes /// - protected string GetActiveProfile(IProjectSubscriptionUpdate projectSubscriptionUpdate) + protected string? GetActiveProfile(IProjectSubscriptionUpdate projectSubscriptionUpdate) { if (projectSubscriptionUpdate.CurrentState.TryGetValue(ProjectDebugger.SchemaName, out IProjectRuleSnapshot ruleSnapshot) && ruleSnapshot.Properties.TryGetValue(ProjectDebugger.ActiveDebugProfileProperty, out string activeProfile)) @@ -448,18 +463,21 @@ protected async Task ReadSettingsFileFromDiskAsync() } else { + // Workaround https://github.com/dotnet/roslyn/issues/31803 + JToken localToken = jToken!; + // Find the matching json serialization handler for this section Lazy handler = JsonSerializationProviders.FirstOrDefault(sp => string.Equals(sp.Metadata.JsonSection, key)); if (handler != null) { - object sectionObject = JsonConvert.DeserializeObject(jToken.ToString(), handler.Metadata.SerializationType); + object sectionObject = JsonConvert.DeserializeObject(localToken.ToString(), handler.Metadata.SerializationType); launchSettingsData.OtherSettings.Add(key, sectionObject); } else { // We still need to remember settings for which we don't have an extensibility component installed. For this we // just keep the jObject which can be serialized back out when the file is written. - launchSettingsData.OtherSettings.Add(key, jToken); + launchSettingsData.OtherSettings.Add(key, localToken); } } } @@ -478,7 +496,7 @@ public Task GetLaunchSettingsFilePathAsync() /// Does a quick validation to make sure at least a name is present in each profile. Removes bad ones and /// logs errors. Returns the resultant profiles as a list /// - private static List FixupProfilesAndLogErrors(Dictionary profilesData) + private static List? FixupProfilesAndLogErrors(Dictionary profilesData) { if (profilesData == null) { @@ -538,7 +556,7 @@ protected static Dictionary GetSettingsToSerialize(ILaunchSettin var profileData = new Dictionary>(StringComparer.Ordinal); foreach (ILaunchProfile profile in curSettings.Profiles) { - if (ProfileShouldBePersisted(profile)) + if (ProfileShouldBePersisted(profile) && profile.Name != null) { profileData.Add(profile.Name, LaunchProfileData.ToSerializableForm(profile)); } @@ -594,7 +612,7 @@ private void LaunchSettingsFile_Changed(object sender, FileSystemEventArgs e) HandleLaunchSettingsFileChangedAsync().Forget(); } - protected Task HandleLaunchSettingsFileChangedAsync() + protected Task? HandleLaunchSettingsFileChangedAsync() { if (!IgnoreFileChanges) { @@ -606,15 +624,21 @@ protected Task HandleLaunchSettingsFileChangedAsync() // throttle. if (!FileManager.FileExists(fileName) || FileManager.LastFileWriteTime(fileName) != LastSettingsFileSyncTime) { - return FileChangeScheduler.ScheduleAsyncTask(token => + return FileChangeScheduler?.ScheduleAsyncTask(token => { if (token.IsCancellationRequested) { return Task.CompletedTask; } + SequentialTaskExecutor? sequentialTaskQueue = _sequentialTaskQueue; + if (sequentialTaskQueue == null) + { + throw new ObjectDisposedException(nameof(LaunchSettingsProvider)); + } + // Updates need to be sequenced - return _sequentialTaskQueue.ExecuteTask(() => UpdateProfilesAsync(null)); + return sequentialTaskQueue.ExecuteTask((() => UpdateProfilesAsync(null))); }).Task; } } @@ -719,6 +743,11 @@ protected override void Dispose(bool disposing) /// public Task UpdateAndSaveSettingsAsync(ILaunchSettings newSettings) { + if (_sequentialTaskQueue == null) + { + throw new ObjectDisposedException(nameof(LaunchSettingsProvider)); + } + // Updates need to be sequenced. Do not call this version from within an ExecuteTask as it // will deadlock return _sequentialTaskQueue.ExecuteTask(() => UpdateAndSaveSettingsInternalAsync(newSettings)); @@ -737,7 +766,7 @@ protected async Task UpdateAndSaveSettingsInternalAsync(ILaunchSettings newSetti } // Make sure the profiles are copied. We don't want them to mutate. - string activeProfileName = ActiveProfile?.Name; + string? activeProfileName = ActiveProfile?.Name; ILaunchSettings newSnapshot = new LaunchSettings(newSettings.Profiles, newSettings.GlobalSettings, activeProfileName); if (persistToDisk) @@ -752,7 +781,7 @@ protected async Task UpdateAndSaveSettingsInternalAsync(ILaunchSettings newSetti /// This function blocks until a snapshot is available. It will return null if the timeout occurs /// prior to the snapshot is available /// - public async Task WaitForFirstSnapshot(int timeout) + public async Task WaitForFirstSnapshot(int timeout) { if (CurrentSnapshot != null) { @@ -772,11 +801,16 @@ public async Task WaitForFirstSnapshot(int timeout) /// public Task AddOrUpdateProfileAsync(ILaunchProfile profile, bool addToFront) { + if (_sequentialTaskQueue == null) + { + throw new ObjectDisposedException(nameof(LaunchSettingsProvider)); + } + // Updates need to be sequenced return _sequentialTaskQueue.ExecuteTask(async () => { ILaunchSettings currentSettings = await GetSnapshotThrowIfErrors(); - ILaunchProfile existingProfile = null; + ILaunchProfile? existingProfile = null; int insertionIndex = 0; foreach (ILaunchProfile p in currentSettings.Profiles) { @@ -823,6 +857,11 @@ public Task AddOrUpdateProfileAsync(ILaunchProfile profile, bool addToFront) /// public Task RemoveProfileAsync(string profileName) { + if (_sequentialTaskQueue == null) + { + throw new ObjectDisposedException(nameof(LaunchSettingsProvider)); + } + // Updates need to be sequenced return _sequentialTaskQueue.ExecuteTask(async () => { @@ -846,6 +885,11 @@ public Task RemoveProfileAsync(string profileName) /// public Task AddOrUpdateGlobalSettingAsync(string settingName, object settingContent) { + if (_sequentialTaskQueue == null) + { + throw new ObjectDisposedException(nameof(LaunchSettingsProvider)); + } + // Updates need to be sequenced return _sequentialTaskQueue.ExecuteTask(async () => { @@ -873,6 +917,11 @@ public Task AddOrUpdateGlobalSettingAsync(string settingName, object settingCont public Task RemoveGlobalSettingAsync(string settingName) { // Updates need to be sequenced + if (_sequentialTaskQueue == null) + { + throw new ObjectDisposedException(nameof(LaunchSettingsProvider)); + } + return _sequentialTaskQueue.ExecuteTask(async () => { ILaunchSettings currentSettings = await GetSnapshotThrowIfErrors(); @@ -892,7 +941,7 @@ public Task RemoveGlobalSettingAsync(string settingName) /// public async Task GetSnapshotThrowIfErrors() { - ILaunchSettings currentSettings = await WaitForFirstSnapshot(WaitForFirstSnapshotDelay); + ILaunchSettings? currentSettings = await WaitForFirstSnapshot(WaitForFirstSnapshotDelay); if (currentSettings == null || (currentSettings.Profiles.Count == 1 && string.Equals(currentSettings.Profiles[0].CommandName, ErrorProfileCommandName, StringComparison.Ordinal))) { string fileName = await GetLaunchSettingsFilePathAsync(); @@ -919,7 +968,7 @@ internal async Task GetLaunchSettingsFilePathNoCacheAsync() // even though it can change over the lifetime of the project. We should fix this and convert to using dataflow // see: https://github.com/dotnet/project-system/issues/2316. - string folder = await _appDesignerSpecialFileProvider.Value.GetFileAsync(SpecialFiles.AppDesigner, SpecialFileFlags.FullPath); + string? folder = await _appDesignerSpecialFileProvider.Value.GetFileAsync(SpecialFiles.AppDesigner, SpecialFileFlags.FullPath); if (folder == null) // AppDesigner capability not present, or the project has set AppDesignerFolder to empty folder = Path.GetDirectoryName(CommonProjectServices.Project.FullPath); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/WritableLaunchProfile.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/WritableLaunchProfile.cs index e69c5798bb4..ea0039ccf1a 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/WritableLaunchProfile.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/WritableLaunchProfile.cs @@ -40,13 +40,13 @@ public WritableLaunchProfile(ILaunchProfile profile) } } - public string Name { get; set; } - public string CommandName { get; set; } - public string ExecutablePath { get; set; } - public string CommandLineArgs { get; set; } - public string WorkingDirectory { get; set; } + public string? Name { get; set; } + public string? CommandName { get; set; } + public string? ExecutablePath { get; set; } + public string? CommandLineArgs { get; set; } + public string? WorkingDirectory { get; set; } public bool LaunchBrowser { get; set; } - public string LaunchUrl { get; set; } + public string? LaunchUrl { get; set; } public bool DoNotPersist { get; set; } public Dictionary EnvironmentVariables { get; } = new Dictionary(StringComparer.Ordinal); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/WritableLaunchSettings.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/WritableLaunchSettings.cs index 930a76d04fe..056eab66f61 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/WritableLaunchSettings.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/WritableLaunchSettings.cs @@ -42,7 +42,8 @@ public WritableLaunchSettings(ILaunchSettings settings) else { string jsonString = JsonConvert.SerializeObject(value, Formatting.Indented, jsonSerializerSettings); - object clonedObject = JsonConvert.DeserializeObject(jsonString, value.GetType()); + // TODO: Bug in nullable flow analysis her? + object clonedObject = JsonConvert.DeserializeObject(jsonString, value!.GetType()); GlobalSettings.Add(key, clonedObject); } } @@ -50,11 +51,11 @@ public WritableLaunchSettings(ILaunchSettings settings) if (settings.ActiveProfile != null) { - ActiveProfile = Profiles.FirstOrDefault((profile) => LaunchProfile.IsSameProfileName(profile.Name, settings.ActiveProfile.Name)); + ActiveProfile = Profiles.FirstOrDefault((profile) => LaunchProfile.IsSameProfileName(profile.Name, settings.ActiveProfile?.Name)); } } - public IWritableLaunchProfile ActiveProfile { get; set; } + public IWritableLaunchProfile? ActiveProfile { get; set; } public List Profiles { get; } = new List(); public Dictionary GlobalSettings { get; } = new Dictionary(StringComparer.Ordinal); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/FileItemServices.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/FileItemServices.cs index a7adf49e596..ae1ca5cd453 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/FileItemServices.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/FileItemServices.cs @@ -12,7 +12,7 @@ internal static class FileItemServices /// Returns the logical folder names of the specified , starting /// at , using 'Link' metadata if it represents a linked file. /// - public static string[] GetLogicalFolderNames(string basePath, string fullPath, IImmutableDictionary metadata) + public static string[]? GetLogicalFolderNames(string basePath, string fullPath, IImmutableDictionary metadata) { Requires.NotNullOrEmpty(basePath, nameof(basePath)); Requires.NotNullOrEmpty(fullPath, nameof(fullPath)); @@ -43,7 +43,7 @@ public static string[] GetLogicalFolderNames(string basePath, string fullPath, I return relativeDirectoryName.Split(Delimiter.Path); } - private static string GetLinkFilePath(IImmutableDictionary metadata) + private static string? GetLinkFilePath(IImmutableDictionary metadata) { // This mimic's CPS's handling of Link metadata if (metadata.TryGetValue(Compile.LinkProperty, out string linkFilePath) && !string.IsNullOrWhiteSpace(linkFilePath)) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/IActiveConfiguredProjectsProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/IActiveConfiguredProjectsProvider.cs index 325645eaa4a..22e393443f7 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/IActiveConfiguredProjectsProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/IActiveConfiguredProjectsProvider.cs @@ -38,7 +38,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. @@ -53,6 +53,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/ICreateFileFromTemplateService.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ICreateFileFromTemplateService.cs index 2559b351d9a..aee12265a0b 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ICreateFileFromTemplateService.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ICreateFileFromTemplateService.cs @@ -16,6 +16,6 @@ internal interface ICreateFileFromTemplateService /// The path to the node to which the new file will be added. /// The name of the file to be created. /// true if file is added successfully. - Task CreateFileAsync(string templateFile, string parentDocumentMoniker, string fileName); + Task CreateFileAsync(string templateFile, string? parentDocumentMoniker, string fileName); } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Imaging/IProjectImageProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Imaging/IProjectImageProvider.cs index 215ea0859c9..6a88b5428d8 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Imaging/IProjectImageProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Imaging/IProjectImageProvider.cs @@ -11,6 +11,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/ProjectImageProviderAggregator.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Imaging/ProjectImageProviderAggregator.cs index 7f5e89b91cc..1743d38fb62 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Imaging/ProjectImageProviderAggregator.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Imaging/ProjectImageProviderAggregator.cs @@ -25,13 +25,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) return image; diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/AggregateWorkspaceProjectContext.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/AggregateWorkspaceProjectContext.cs index 34e71758029..992f250e223 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/AggregateWorkspaceProjectContext.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/AggregateWorkspaceProjectContext.cs @@ -65,7 +65,7 @@ public void SetProjectFilePathAndDisplayName(string projectFilePath, string disp } } - public IWorkspaceProjectContext GetInnerProjectContext(ProjectConfiguration projectConfiguration, out bool isActiveConfiguration) + public IWorkspaceProjectContext? GetInnerProjectContext(ProjectConfiguration projectConfiguration, out bool isActiveConfiguration) { if (projectConfiguration.IsCrossTargeting()) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/ApplyChangesToWorkspaceContext.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/ApplyChangesToWorkspaceContext.cs index e779a6c0eda..597a3130529 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/ApplyChangesToWorkspaceContext.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/ApplyChangesToWorkspaceContext.cs @@ -23,8 +23,8 @@ internal class ApplyChangesToWorkspaceContext : OnceInitializedOnceDisposed, IAp private readonly ConfiguredProject _project; private readonly IProjectLogger _logger; private readonly ExportFactory[] _workspaceContextHandlerFactories; - private IWorkspaceProjectContext _context; - private ExportLifetimeContext[] _handlers; + private IWorkspaceProjectContext? _context; + private ExportLifetimeContext[]? _handlers; [ImportingConstructor] public ApplyChangesToWorkspaceContext(ConfiguredProject project, IProjectLogger logger, [ImportMany]ExportFactory[] workspaceContextHandlerFactories) @@ -137,7 +137,7 @@ protected override void Initialize() foreach (ExportLifetimeContext handler in _handlers) { - handler.Value.Initialize(_context); + handler.Value.Initialize(_context!); } } @@ -147,15 +147,19 @@ private void ProcessProjectBuildFailure(IProjectRuleSnapshot snapshot) // // We still forward those 'removes' of references, sources, etc onto Roslyn to avoid duplicate/incorrect results when the next // successful build occurs, because it will be diff between it and this failed build. - _context.LastDesignTimeBuildSucceeded = snapshot.IsEvaluationSucceeded(); + if (_context != null) + _context.LastDesignTimeBuildSucceeded = snapshot.IsEvaluationSucceeded(); } private void ProcessOptions(IProjectRuleSnapshot snapshot) { - // We just pass all options to Roslyn - string commandlineArguments = string.Join(" ", snapshot.Items.Keys); + if (_context != null) + { + // We just pass all options to Roslyn + string commandlineArguments = string.Join(" ", snapshot.Items.Keys); - _context.SetOptions(commandlineArguments); + _context.SetOptions(commandlineArguments); + } } private void ProcessCommandLine(IComparable version, IProjectChangeDiff differences, bool isActiveContext, CancellationToken cancellationToken) @@ -174,6 +178,9 @@ private void ProcessCommandLine(IComparable version, IProjectChangeDiff differen private void ProcessCommandLineHandlers(IComparable version, BuildOptions added, BuildOptions removed, bool isActiveContext, CancellationToken cancellationToken) { + if (_handlers == null) + return; + foreach (ExportLifetimeContext handler in _handlers) { if (cancellationToken.IsCancellationRequested) @@ -188,6 +195,9 @@ private void ProcessCommandLineHandlers(IComparable version, BuildOptions added, private void ProcessProjectEvaluationHandlers(IComparable version, IProjectVersionedValue update, bool isActiveContext, CancellationToken cancellationToken) { + if (_handlers == null) + return; + foreach (ExportLifetimeContext handler in _handlers) { if (cancellationToken.IsCancellationRequested) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/ContextHandlerProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/ContextHandlerProvider.cs index 0a016b2c59e..7fa6fd9155a 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/ContextHandlerProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/ContextHandlerProvider.cs @@ -79,9 +79,9 @@ private Handlers CreateHandlers(IWorkspaceProjectContext context) return new Handlers(evaluationHandlers.ToImmutableAndFree(), commandLineHandlers.ToImmutableAndFree()); } - private static ImmutableArray<(HandlerFactory factory, string evaluationRuleName)> CreateHandlerFactories() + private static ImmutableArray<(HandlerFactory factory, string? evaluationRuleName)> CreateHandlerFactories() { - return ImmutableArray.Create<(HandlerFactory factory, string evaluationRuleName)>( + return ImmutableArray.Create<(HandlerFactory factory, string? evaluationRuleName)>( // Factory EvaluationRuleName Description diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/Handlers/AbstractWorkspaceContextHandler.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/Handlers/AbstractWorkspaceContextHandler.cs index 3e671e34a47..f3dbc9958c7 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/Handlers/AbstractWorkspaceContextHandler.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/Handlers/AbstractWorkspaceContextHandler.cs @@ -8,7 +8,7 @@ namespace Microsoft.VisualStudio.ProjectSystem.LanguageServices.Handlers { internal class AbstractWorkspaceContextHandler : IWorkspaceContextHandler { - private IWorkspaceProjectContext _context; + private IWorkspaceProjectContext? _context; protected AbstractWorkspaceContextHandler() { @@ -20,7 +20,7 @@ protected IWorkspaceProjectContext Context { Assumes.NotNull(_context); - return _context; + return _context!; } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/Handlers/DynamicItemHandler.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/Handlers/DynamicItemHandler.cs index 5c2a0f1b1a7..b4e24f9b138 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/Handlers/DynamicItemHandler.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/Handlers/DynamicItemHandler.cs @@ -78,7 +78,7 @@ private void AddToContextIfNotPresent(string includePath, IImmutableDictionary metadata, bool isActiveContext, IProjectLogger logger) { - string[] folderNames = FileItemServices.GetLogicalFolderNames(Path.GetDirectoryName(_project.FullPath), fullPath, metadata); + string[]? folderNames = FileItemServices.GetLogicalFolderNames(Path.GetDirectoryName(_project.FullPath), fullPath, metadata); logger.WriteLine("Adding source file '{0}'", fullPath); Context.AddSourceFile(fullPath, isInCurrentContext: isActiveContext, folderNames: folderNames); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/ILanguageServiceHost.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/ILanguageServiceHost.cs index e4717bd251d..a5840a97da1 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/ILanguageServiceHost.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/ILanguageServiceHost.cs @@ -20,7 +20,7 @@ internal interface ILanguageServiceHost /// /// Within a Visual Studio host, this is typically an object implementing IVsLanguageServiceBuildErrorReporter2. /// - object HostSpecificErrorReporter + object? HostSpecificErrorReporter { get; } @@ -31,7 +31,7 @@ object HostSpecificErrorReporter /// /// An that provides access to the language service for the active configured project. /// - IWorkspaceProjectContext ActiveProjectContext + IWorkspaceProjectContext? ActiveProjectContext { get; } @@ -39,7 +39,7 @@ IWorkspaceProjectContext ActiveProjectContext /// /// Gets the object that represents the host specific Edit and Continue Service. /// - object HostSpecificEditAndContinueService + object? HostSpecificEditAndContinueService { get; } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/IProjectContextProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/IProjectContextProvider.cs index 0ea18530224..756d650b0a6 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/IProjectContextProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/IProjectContextProvider.cs @@ -22,7 +22,7 @@ internal interface IProjectContextProvider /// When finished with the return , callers must call /// . /// - Task CreateProjectContextAsync(); + Task CreateProjectContextAsync(); /// /// Releases a previously created . diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/IUnconfiguredProjectHostObject.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/IUnconfiguredProjectHostObject.cs index c465d37005e..1d60b44643d 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/IUnconfiguredProjectHostObject.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/IUnconfiguredProjectHostObject.cs @@ -12,7 +12,7 @@ internal interface IUnconfiguredProjectHostObject : IDisposable /// /// for the active intellisense project. /// - IConfiguredProjectHostObject ActiveIntellisenseProjectHostObject { get; set; } + IConfiguredProjectHostObject? ActiveIntellisenseProjectHostObject { get; set; } /// /// Flag indicating that we are currently disposing inner configured projects. diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/IWorkspaceProjectContextProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/IWorkspaceProjectContextProvider.cs index ed3f2a6a26f..5a41dde0826 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/IWorkspaceProjectContextProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/IWorkspaceProjectContextProvider.cs @@ -22,7 +22,7 @@ internal interface IWorkspaceProjectContextProvider /// /// is . /// - Task CreateProjectContextAsync(ConfiguredProject project); + Task CreateProjectContextAsync(ConfiguredProject project); /// /// Release the . diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/LanguageServiceHost.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/LanguageServiceHost.cs index b6ce6f14e0a..476ac2987f4 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/LanguageServiceHost.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/LanguageServiceHost.cs @@ -42,12 +42,12 @@ internal partial class LanguageServiceHost : OnceInitializedOnceDisposedAsync, I /// Note that at any given time, we can have only a single non-disposed aggregate project context. /// Otherwise, we can end up with an invalid state of multiple workspace project contexts for the same configured project. /// - private AggregateWorkspaceProjectContext _currentAggregateProjectContext; + private AggregateWorkspaceProjectContext? _currentAggregateProjectContext; /// /// Current TargetFramework for non-cross targeting project - accesses to this field must be done with a lock on . /// - private string _currentTargetFramework; + private string? _currentTargetFramework; [ImportingConstructor] @@ -70,11 +70,11 @@ public LanguageServiceHost(IUnconfiguredProjectCommonServices commonServices, _projectConfigurationsWithSubscriptions = new HashSet(); } - public object HostSpecificErrorReporter => _currentAggregateProjectContext?.HostSpecificErrorReporter; + public object? HostSpecificErrorReporter => _currentAggregateProjectContext?.HostSpecificErrorReporter; - public IWorkspaceProjectContext ActiveProjectContext => _currentAggregateProjectContext?.ActiveProjectContext; + public IWorkspaceProjectContext? ActiveProjectContext => _currentAggregateProjectContext?.ActiveProjectContext; - public object HostSpecificEditAndContinueService => _currentAggregateProjectContext?.ENCProjectConfig; + public object? HostSpecificEditAndContinueService => _currentAggregateProjectContext?.ENCProjectConfig; #pragma warning disable RS0030 // symbol ProjectAutoLoad is banned [ProjectAutoLoad(completeBy: ProjectLoadCheckpoint.ProjectFactoryCompleted)] @@ -122,10 +122,10 @@ await _tasksService.LoadedProjectAsync(async () => private async Task UpdateProjectContextAndSubscriptionsAsync() { - AggregateWorkspaceProjectContext previousProjectContext = _currentAggregateProjectContext; - AggregateWorkspaceProjectContext newProjectContext = await UpdateProjectContextAsync(); + AggregateWorkspaceProjectContext? previousProjectContext = _currentAggregateProjectContext; + AggregateWorkspaceProjectContext? newProjectContext = await UpdateProjectContextAsync(); - if (previousProjectContext != newProjectContext) + if (previousProjectContext != newProjectContext && newProjectContext != null) { // Add subscriptions for the new configured projects in the new project context. await AddSubscriptionsAsync(newProjectContext); @@ -146,34 +146,35 @@ private Task ExecuteWithinLockAsync(Func task) /// Ensures that is updated for the latest target frameworks from the project properties /// and returns this value. /// - private Task UpdateProjectContextAsync() + private Task UpdateProjectContextAsync() { // Ensure that only single thread is attempting to create a project context. - AggregateWorkspaceProjectContext previousContextToDispose = null; + AggregateWorkspaceProjectContext? previousContextToDispose = null; return ExecuteWithinLockAsync(async () => { await _commonServices.ThreadingService.SwitchToUIThread(); - string newTargetFramework = null; + string? newTargetFramework = null; ConfigurationGeneral projectProperties = await _commonServices.ActiveConfiguredProjectProperties.GetConfigurationGeneralPropertiesAsync(); // Check if we have already computed the project context. - if (_currentAggregateProjectContext != null) + AggregateWorkspaceProjectContext? currentAggregateProjectContext = _currentAggregateProjectContext; + if (currentAggregateProjectContext != null) { // For non-cross targeting projects, we can use the current project context if the TargetFramework hasn't changed. // For cross-targeting projects, we need to verify that the current project context matches latest frameworks targeted by the project. // If not, we create a new one and dispose the current one. - if (!_currentAggregateProjectContext.IsCrossTargeting) + if (!currentAggregateProjectContext.IsCrossTargeting) { newTargetFramework = (string)await projectProperties.TargetFramework.GetValueAsync(); if (StringComparers.PropertyValues.Equals(_currentTargetFramework, newTargetFramework)) { - return _currentAggregateProjectContext; + return currentAggregateProjectContext; } // Dispose the old workspace project context for the previous target framework. - await DisposeAggregateProjectContextAsync(_currentAggregateProjectContext); + await DisposeAggregateProjectContextAsync(currentAggregateProjectContext); } else { @@ -181,12 +182,12 @@ private Task UpdateProjectContextAsync() ProjectConfiguration activeProjectConfiguration = _commonServices.ActiveConfiguredProject.ProjectConfiguration; IImmutableSet knownProjectConfigurations = await _commonServices.Project.Services.ProjectConfigurationsService.GetKnownProjectConfigurationsAsync(); if (knownProjectConfigurations.All(c => c.IsCrossTargeting()) && - _currentAggregateProjectContext.HasMatchingTargetFrameworks(activeProjectConfiguration, knownProjectConfigurations)) + currentAggregateProjectContext.HasMatchingTargetFrameworks(activeProjectConfiguration, knownProjectConfigurations)) { - return _currentAggregateProjectContext; + return currentAggregateProjectContext; } - previousContextToDispose = _currentAggregateProjectContext; + previousContextToDispose = currentAggregateProjectContext; } } else @@ -208,7 +209,7 @@ private Task UpdateProjectContextAsync() await DisposeAggregateProjectContextAsync(previousContextToDispose); } - return _currentAggregateProjectContext; + return currentAggregateProjectContext; }); } @@ -267,7 +268,8 @@ await ExecuteWithinLockAsync(async () => } // Get the inner workspace project context to update for this change. - IWorkspaceProjectContext projectContextToUpdate = _currentAggregateProjectContext.GetInnerProjectContext(update.Value.ProjectConfiguration, out bool isActiveContext); + bool isActiveContext = false; + IWorkspaceProjectContext? projectContextToUpdate = _currentAggregateProjectContext?.GetInnerProjectContext(update.Value.ProjectConfiguration, out isActiveContext); if (projectContextToUpdate == null) { return; @@ -300,9 +302,10 @@ protected override async Task DisposeCoreAsync(bool initialized) await ExecuteWithinLockAsync(async () => { - if (_currentAggregateProjectContext != null) + AggregateWorkspaceProjectContext? currentAggregateProjectContext = _currentAggregateProjectContext; + if (currentAggregateProjectContext != null) { - await _contextProvider.Value.ReleaseProjectContextAsync(_currentAggregateProjectContext); + await _contextProvider.Value.ReleaseProjectContextAsync(currentAggregateProjectContext); } }); } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/UnconfiguredProjectContextProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/UnconfiguredProjectContextProvider.cs index 0d4e5cc167b..0427bd095a4 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/UnconfiguredProjectContextProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/UnconfiguredProjectContextProvider.cs @@ -45,11 +45,11 @@ public UnconfiguredProjectContextProvider(IUnconfiguredProjectCommonServices com _unconfiguredProjectHostObject = _projectHostProvider.UnconfiguredProjectHostObject; } - public async Task CreateProjectContextAsync() + public async Task CreateProjectContextAsync() { EnsureInitialized(); - AggregateWorkspaceProjectContext context = await CreateProjectContextAsyncCore(); + AggregateWorkspaceProjectContext? context = await CreateProjectContextAsyncCore(); if (context == null) return null; @@ -181,8 +181,8 @@ private bool TryGetConfiguredProjectState(ConfiguredProject configuredProject, o } else { - workspaceProjectContext = null; - configuredProjectHostObject = null; + workspaceProjectContext = null!; + configuredProjectHostObject = null!; return false; } } @@ -197,7 +197,7 @@ private void AddConfiguredProjectState(ConfiguredProject configuredProject, IWor } } - private async Task CreateProjectContextAsyncCore() + private async Task CreateProjectContextAsyncCore() { string languageName = await GetLanguageServiceName(); if (string.IsNullOrEmpty(languageName)) @@ -225,7 +225,7 @@ private async Task CreateProjectContextAsyncCo var innerProjectContextsBuilder = PooledDictionary.GetInstance(); string activeTargetFramework = string.Empty; - IConfiguredProjectHostObject activeIntellisenseProjectHostObject = null; + IConfiguredProjectHostObject? activeIntellisenseProjectHostObject = null; foreach ((string targetFramework, ConfiguredProject configuredProject) in configuredProjectsMap) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/WorkspaceContextHost.WorkspaceContextHostInstance.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/WorkspaceContextHost.WorkspaceContextHostInstance.cs index 0a84c23ceff..429fead4fd4 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/WorkspaceContextHost.WorkspaceContextHostInstance.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/WorkspaceContextHost.WorkspaceContextHostInstance.cs @@ -25,9 +25,9 @@ internal partial class WorkspaceContextHostInstance : OnceInitializedOnceDispose private readonly IActiveWorkspaceProjectContextTracker _activeWorkspaceProjectContextTracker; private readonly ExportFactory _applyChangesToWorkspaceContextFactory; - private DisposableBag _subscriptions; - private IWorkspaceProjectContext _context; - private ExportLifetimeContext _applyChangesToWorkspaceContext; + private DisposableBag? _subscriptions; + private IWorkspaceProjectContext? _context; + private ExportLifetimeContext? _applyChangesToWorkspaceContext; public WorkspaceContextHostInstance(ConfiguredProject project, IProjectThreadingService threadingService, @@ -103,15 +103,17 @@ await ExecuteUnderLockAsync(ct => private void ApplyProjectChangesUnderLock(IProjectVersionedValue update, bool evaluation, CancellationToken cancellationToken) { - bool isActiveContext = _activeWorkspaceProjectContextTracker.IsActiveContext(_context); + bool isActiveContext = _context != null + ? _activeWorkspaceProjectContextTracker.IsActiveContext(_context) + : false; if (evaluation) { - _applyChangesToWorkspaceContext.Value.ApplyProjectEvaluation(update, isActiveContext, cancellationToken); + _applyChangesToWorkspaceContext?.Value.ApplyProjectEvaluation(update, isActiveContext, cancellationToken); } else { - _applyChangesToWorkspaceContext.Value.ApplyProjectBuild(update, isActiveContext, cancellationToken); + _applyChangesToWorkspaceContext?.Value.ApplyProjectBuild(update, isActiveContext, cancellationToken); } } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/WorkspaceProjectContextProvider.ForegroundWorkspaceProjectContext.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/WorkspaceProjectContextProvider.ForegroundWorkspaceProjectContext.cs index 685645ddde4..06ea8f9e7d2 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/WorkspaceProjectContextProvider.ForegroundWorkspaceProjectContext.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/WorkspaceProjectContextProvider.ForegroundWorkspaceProjectContext.cs @@ -82,7 +82,7 @@ public void AddAnalyzerReference(string referencePath) UnderlyingContext.AddAnalyzerReference(referencePath); } - public void AddDynamicFile(string filePath, IEnumerable folderNames = null) + public void AddDynamicFile(string filePath, IEnumerable? folderNames = null) { UnderlyingContext.AddDynamicFile(filePath, folderNames); } @@ -97,7 +97,7 @@ public void AddProjectReference(IWorkspaceProjectContext project, MetadataRefere UnderlyingContext.AddProjectReference(project, properties); } - public void AddSourceFile(string filePath, bool isInCurrentContext = true, IEnumerable folderNames = null, SourceCodeKind sourceCodeKind = SourceCodeKind.Regular) + public void AddSourceFile(string filePath, bool isInCurrentContext = true, IEnumerable? folderNames = null, SourceCodeKind sourceCodeKind = SourceCodeKind.Regular) { UnderlyingContext.AddSourceFile(filePath, isInCurrentContext, folderNames, sourceCodeKind); } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/WorkspaceProjectContextProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/WorkspaceProjectContextProvider.cs index 5eca6322248..5e3fe43441e 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/WorkspaceProjectContextProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/WorkspaceProjectContextProvider.cs @@ -41,7 +41,7 @@ public WorkspaceProjectContextProvider(UnconfiguredProject project, _projectGuidService = projectGuidService; } - public async Task CreateProjectContextAsync(ConfiguredProject project) + public async Task CreateProjectContextAsync(ConfiguredProject project) { Requires.NotNull(project, nameof(project)); @@ -51,7 +51,7 @@ public async Task CreateProjectContextAsync(Configured object hostObject = _project.Services.HostObject; - IWorkspaceProjectContext context = await CreateProjectContextHandlingFaultAsync(data, hostObject); + IWorkspaceProjectContext? context = await CreateProjectContextHandlingFaultAsync(data, hostObject); if (context == null) return null; @@ -81,7 +81,7 @@ public async Task ReleaseProjectContextAsync(IWorkspaceProjectContext projectCon } } - private async Task CreateProjectContextHandlingFaultAsync(ProjectContextInitData data, object hostObject) + private async Task CreateProjectContextHandlingFaultAsync(ProjectContextInitData data, object hostObject) { // TODO: https://github.com/dotnet/project-system/issues/353. await _threadingService.SwitchToUIThread(); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Logging/ProjectLoggerExtensions.ProjectLoggerBatch.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Logging/ProjectLoggerExtensions.ProjectLoggerBatch.cs index 21cb00ec541..23b7fd5ce63 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Logging/ProjectLoggerExtensions.ProjectLoggerBatch.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Logging/ProjectLoggerExtensions.ProjectLoggerBatch.cs @@ -12,7 +12,7 @@ internal partial class ProjectLoggerExtensions private class ProjectLoggerBatch : IProjectLoggerBatch { private readonly IProjectLogger _logger; - private StringBuilder _builder; + private StringBuilder? _builder; private int _indentLevel; internal ProjectLoggerBatch(IProjectLogger logger) @@ -43,41 +43,43 @@ public void WriteLine(in StringFormat format) { if (IsEnabled) { - Init(); - WriteNewLineIfNeeded(); - WriteIndent(); - Write(format); + StringBuilder builder = GetOrCreateBuilder(); + WriteNewLineIfNeeded(builder); + WriteIndent(builder, _indentLevel); + Write(builder, format); } } - private void Init() + private StringBuilder GetOrCreateBuilder() { if (_builder == null) _builder = new StringBuilder(); + + return _builder; } - private void WriteNewLineIfNeeded() + private static void WriteNewLineIfNeeded(StringBuilder builder) { // Need to factor in that when we eventually write to the logger // it's going to append a new line to the string we write, so we // only append the new line just before we write another string. - if (_builder.Length != 0) + if (builder.Length != 0) { - _builder.AppendLine(); + builder.AppendLine(); } } - private void WriteIndent() + private static void WriteIndent(StringBuilder builder, int indentLevel) { - for (int i = 0; i < _indentLevel; i++) + for (int i = 0; i < indentLevel; i++) { - _builder.Append(" "); + builder.Append(" "); } } - private void Write(in StringFormat format) + private static void Write(StringBuilder builder, in StringFormat format) { - _builder.AppendFormat(format); + builder.AppendFormat(format); } public void Dispose() diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ProjectChangeDiff.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ProjectChangeDiff.cs index 5fdca260efb..9bff16ee35d 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ProjectChangeDiff.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ProjectChangeDiff.cs @@ -9,7 +9,7 @@ namespace Microsoft.VisualStudio.ProjectSystem /// internal class ProjectChangeDiff : IProjectChangeDiff { - public ProjectChangeDiff(IImmutableSet addedItems = null, IImmutableSet removedItems = null, IImmutableSet changedItems = null, IImmutableDictionary renamedItems = null) + public ProjectChangeDiff(IImmutableSet? addedItems = null, IImmutableSet? removedItems = null, IImmutableSet? changedItems = null, IImmutableDictionary? renamedItems = null) { AddedItems = addedItems ?? ImmutableStringHashSet.EmptyOrdinal; RemovedItems = removedItems ?? ImmutableStringHashSet.EmptyOrdinal; diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ProjectRootImageProjectTreePropertiesProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ProjectRootImageProjectTreePropertiesProvider.cs index 4b0f36634bc..3d9db59958b 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ProjectRootImageProjectTreePropertiesProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ProjectRootImageProjectTreePropertiesProvider.cs @@ -45,7 +45,7 @@ public void CalculatePropertyValues(IProjectTreeCustomizablePropertyContext prop private void SetImage(IProjectTreeCustomizablePropertyValues propertyValues, string imageKey) { - ProjectImageMoniker icon = _imageProvider.GetProjectImage(imageKey); + ProjectImageMoniker? icon = _imageProvider.GetProjectImage(imageKey); if (icon != null) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ProjectTreeProviderExtensions.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ProjectTreeProviderExtensions.cs index 08ffecc5d17..b6a90382ebd 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ProjectTreeProviderExtensions.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ProjectTreeProviderExtensions.cs @@ -31,7 +31,7 @@ internal static class ProjectTreeProviderExtensions /// /// is . /// - public static string GetRootedAddNewItemDirectory(this IProjectTreeProvider provider, IProjectTree target) + public static string? GetRootedAddNewItemDirectory(this IProjectTreeProvider provider, IProjectTree target) { Requires.NotNull(provider, nameof(provider)); Requires.NotNull(target, nameof(target)); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/AssemblyAttributeProperties/AssemblyInfoProperties.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/AssemblyAttributeProperties/AssemblyInfoProperties.cs index 9903f88ca6f..32424010e22 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/AssemblyAttributeProperties/AssemblyInfoProperties.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/AssemblyAttributeProperties/AssemblyInfoProperties.cs @@ -58,7 +58,7 @@ private static ImmutableDictionary /// Get the unevaluated property value. /// - public override async Task GetUnevaluatedPropertyValueAsync(string propertyName) + public override async Task GetUnevaluatedPropertyValueAsync(string propertyName) { if (_attributeValueProviderMap.ContainsKey(propertyName) && !await IsAssemblyInfoPropertyGeneratedByBuild(propertyName)) @@ -72,7 +72,7 @@ public override async Task GetUnevaluatedPropertyValueAsync(string prope /// /// Get the value of a property. /// - public override async Task GetEvaluatedPropertyValueAsync(string propertyName) + public override async Task GetEvaluatedPropertyValueAsync(string propertyName) { if (_attributeValueProviderMap.ContainsKey(propertyName) && !await IsAssemblyInfoPropertyGeneratedByBuild(propertyName)) @@ -86,7 +86,7 @@ public override async Task GetEvaluatedPropertyValueAsync(string propert /// /// Get the value of a property from source assembly attribute. /// - private async Task GetPropertyValueFromSourceAttributeAsync(string propertyName) + private async Task GetPropertyValueFromSourceAttributeAsync(string propertyName) { if (_attributeValueProviderMap.TryGetValue(propertyName, out SourceAssemblyAttributePropertyValueProvider provider)) { @@ -99,12 +99,15 @@ private async Task GetPropertyValueFromSourceAttributeAsync(string prope /// /// Set the value of a property. /// - public override async Task SetPropertyValueAsync(string propertyName, string unevaluatedPropertyValue, IReadOnlyDictionary dimensionalConditions = null) + public override async Task SetPropertyValueAsync(string propertyName, string? unevaluatedPropertyValue, IReadOnlyDictionary? dimensionalConditions = null) { if (_attributeValueProviderMap.TryGetValue(propertyName, out SourceAssemblyAttributePropertyValueProvider provider) && !await IsAssemblyInfoPropertyGeneratedByBuild(propertyName)) { +#pragma warning disable CS8604 await provider.SetPropertyValueAsync(unevaluatedPropertyValue); +#pragma warning restore CS8604 + } else { @@ -119,7 +122,7 @@ private async Task IsAssemblyInfoPropertyGeneratedByBuild(string propertyN // Generate property in project file only if: // 1. "GenerateAssemblyInfo" is true AND // 2. "GenerateXXX" for this specific property is true. - string propertyValue = await base.GetEvaluatedPropertyValueAsync("GenerateAssemblyInfo"); + string? propertyValue = await base.GetEvaluatedPropertyValueAsync("GenerateAssemblyInfo"); if (!bool.TryParse(propertyValue, out bool value) || !value) { return false; diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/AssemblyAttributeProperties/SourceAssemblyAttributePropertyValueProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/AssemblyAttributeProperties/SourceAssemblyAttributePropertyValueProvider.cs index 1c649f0d2ed..e3aeef539b5 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/AssemblyAttributeProperties/SourceAssemblyAttributePropertyValueProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/AssemblyAttributeProperties/SourceAssemblyAttributePropertyValueProvider.cs @@ -33,7 +33,7 @@ public SourceAssemblyAttributePropertyValueProvider( _threadingService = threadingService; } - private Project GetActiveProject() + private Project? GetActiveProject() { ProjectId activeProjectId = _getActiveProjectId(); if (activeProjectId == null) @@ -47,15 +47,15 @@ private Project GetActiveProject() /// /// Gets the value of the property from the source assembly attribute. /// - public async Task GetPropertyValueAsync() + public async Task GetPropertyValueAsync() { - Project project = GetActiveProject(); + Project? project = GetActiveProject(); if (project == null) { return null; } - AttributeData attribute = await GetAttributeAsync(_assemblyAttributeFullName, project); + AttributeData? attribute = await GetAttributeAsync(_assemblyAttributeFullName, project); return attribute?.ConstructorArguments.FirstOrDefault().Value?.ToString(); } @@ -67,13 +67,13 @@ public async Task GetPropertyValueAsync() /// public async Task SetPropertyValueAsync(string value) { - Project project = GetActiveProject(); + Project? project = GetActiveProject(); if (project == null) { return; } - AttributeData attribute = await GetAttributeAsync(_assemblyAttributeFullName, project); + AttributeData? attribute = await GetAttributeAsync(_assemblyAttributeFullName, project); if (attribute == null) { return; @@ -110,7 +110,7 @@ public async Task SetPropertyValueAsync(string value) /// /// Get the attribute corresponding to the given property from the given project. /// - private static async Task GetAttributeAsync(string assemblyAttributeFullName, Project project) + private static async Task GetAttributeAsync(string assemblyAttributeFullName, Project project) { Compilation compilation = await project.GetCompilationAsync(); ImmutableArray assemblyAttributes = compilation.Assembly.GetAttributes(); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/DelegatedProjectPropertiesBase.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/DelegatedProjectPropertiesBase.cs index 37c1ef95777..0957dbf301e 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/DelegatedProjectPropertiesBase.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/DelegatedProjectPropertiesBase.cs @@ -29,25 +29,25 @@ public DelegatedProjectPropertiesBase(IProjectProperties properties) public virtual Task DeleteDirectPropertiesAsync() => DelegatedProperties.DeleteDirectPropertiesAsync(); - public virtual Task DeletePropertyAsync(string propertyName, IReadOnlyDictionary dimensionalConditions = null) + public virtual Task DeletePropertyAsync(string propertyName, IReadOnlyDictionary? dimensionalConditions = null) => DelegatedProperties.DeletePropertyAsync(propertyName, dimensionalConditions); public virtual Task> GetDirectPropertyNamesAsync() => DelegatedProperties.GetDirectPropertyNamesAsync(); - public virtual Task GetEvaluatedPropertyValueAsync(string propertyName) + public virtual Task GetEvaluatedPropertyValueAsync(string propertyName) => DelegatedProperties.GetEvaluatedPropertyValueAsync(propertyName); public virtual Task> GetPropertyNamesAsync() => DelegatedProperties.GetPropertyNamesAsync(); - public virtual Task GetUnevaluatedPropertyValueAsync(string propertyName) + public virtual Task GetUnevaluatedPropertyValueAsync(string propertyName) => DelegatedProperties.GetUnevaluatedPropertyValueAsync(propertyName); public virtual Task IsValueInheritedAsync(string propertyName) => DelegatedProperties.IsValueInheritedAsync(propertyName); - public virtual Task SetPropertyValueAsync(string propertyName, string unevaluatedPropertyValue, IReadOnlyDictionary dimensionalConditions = null) + public virtual Task SetPropertyValueAsync(string propertyName, string? unevaluatedPropertyValue, IReadOnlyDictionary? dimensionalConditions = null) => DelegatedProperties.SetPropertyValueAsync(propertyName, unevaluatedPropertyValue, dimensionalConditions); } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/InterceptedProjectProperties/ApplicationManifestValueProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/InterceptedProjectProperties/ApplicationManifestValueProvider.cs index 5c493c15ef2..6e0a9e515ae 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/InterceptedProjectProperties/ApplicationManifestValueProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/InterceptedProjectProperties/ApplicationManifestValueProvider.cs @@ -36,7 +36,7 @@ public ApplicationManifestValueProvider(UnconfiguredProject project) /// These three values map to two MSBuild properties - ApplicationManifest (specified if it's a path) or NoWin32Manifest /// which is true for the second case and false or non-existent for the third. /// - public override async Task OnGetEvaluatedPropertyValueAsync(string evaluatedPropertyValue, IProjectProperties defaultProperties) + public override async Task OnGetEvaluatedPropertyValueAsync(string? evaluatedPropertyValue, IProjectProperties defaultProperties) { if (!string.IsNullOrEmpty(evaluatedPropertyValue)) { @@ -56,9 +56,9 @@ public override async Task OnGetEvaluatedPropertyValueAsync(string evalu /// /// Sets the application manifest property /// - public override async Task OnSetPropertyValueAsync(string unevaluatedPropertyValue, IProjectProperties defaultProperties, IReadOnlyDictionary dimensionalConditions = null) + public override async Task OnSetPropertyValueAsync(string? unevaluatedPropertyValue, IProjectProperties defaultProperties, IReadOnlyDictionary? dimensionalConditions = null) { - string returnValue = null; + string? returnValue = null; // We treat NULL/empty value as reset to default and remove the two properties from the project. if (string.IsNullOrEmpty(unevaluatedPropertyValue) || string.Equals(unevaluatedPropertyValue, DefaultManifestValue, StringComparison.InvariantCultureIgnoreCase)) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/InterceptedProjectProperties/IInterceptingPropertyValueProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/InterceptedProjectProperties/IInterceptingPropertyValueProvider.cs index 7185ffb83d0..2386d304fbf 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/InterceptedProjectProperties/IInterceptingPropertyValueProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/InterceptedProjectProperties/IInterceptingPropertyValueProvider.cs @@ -14,16 +14,16 @@ internal interface IInterceptingPropertyValueProvider /// /// Validate and/or transform the given evaluated property value. /// - Task OnGetEvaluatedPropertyValueAsync(string evaluatedPropertyValue, IProjectProperties defaultProperties); + Task OnGetEvaluatedPropertyValueAsync(string? evaluatedPropertyValue, IProjectProperties defaultProperties); /// /// Validate and/or transform the given unevaluated property value, i.e. "raw" value read from the project file. /// - Task OnGetUnevaluatedPropertyValueAsync(string unevaluatedPropertyValue, IProjectProperties defaultProperties); + Task OnGetUnevaluatedPropertyValueAsync(string? unevaluatedPropertyValue, IProjectProperties defaultProperties); /// /// Validate and/or transform the given unevaluated property value to be written back to the project file. /// - Task OnSetPropertyValueAsync(string unevaluatedPropertyValue, IProjectProperties defaultProperties, IReadOnlyDictionary dimensionalConditions = null); + Task OnSetPropertyValueAsync(string? unevaluatedPropertyValue, IProjectProperties defaultProperties, IReadOnlyDictionary? dimensionalConditions = null); } -} \ No newline at end of file +} diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/InterceptedProjectProperties/InterceptedProjectProperties.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/InterceptedProjectProperties/InterceptedProjectProperties.cs index 616f6e1855b..105ebffdc1e 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/InterceptedProjectProperties/InterceptedProjectProperties.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/InterceptedProjectProperties/InterceptedProjectProperties.cs @@ -37,9 +37,9 @@ public InterceptedProjectProperties(ImmutableArray GetEvaluatedPropertyValueAsync(string propertyName) + public override async Task GetEvaluatedPropertyValueAsync(string propertyName) { - string evaluatedProperty = await base.GetEvaluatedPropertyValueAsync(propertyName); + string? evaluatedProperty = await base.GetEvaluatedPropertyValueAsync(propertyName); if (_valueProviders.TryGetValue(propertyName, out Lazy valueProvider)) { evaluatedProperty = await valueProvider.Value.OnGetEvaluatedPropertyValueAsync(evaluatedProperty, DelegatedProperties); @@ -48,9 +48,9 @@ public override async Task GetEvaluatedPropertyValueAsync(string propert return evaluatedProperty; } - public override async Task GetUnevaluatedPropertyValueAsync(string propertyName) + public override async Task GetUnevaluatedPropertyValueAsync(string propertyName) { - string unevaluatedProperty = await base.GetUnevaluatedPropertyValueAsync(propertyName); + string? unevaluatedProperty = await base.GetUnevaluatedPropertyValueAsync(propertyName); if (_valueProviders.TryGetValue(propertyName, out Lazy valueProvider)) { unevaluatedProperty = await valueProvider.Value.OnGetUnevaluatedPropertyValueAsync(unevaluatedProperty, DelegatedProperties); @@ -59,7 +59,7 @@ public override async Task GetUnevaluatedPropertyValueAsync(string prope return unevaluatedProperty; } - public override async Task SetPropertyValueAsync(string propertyName, string unevaluatedPropertyValue, IReadOnlyDictionary dimensionalConditions = null) + public override async Task SetPropertyValueAsync(string propertyName, string? unevaluatedPropertyValue, IReadOnlyDictionary? dimensionalConditions = null) { if (_valueProviders.TryGetValue(propertyName, out Lazy valueProvider)) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/InterceptedProjectProperties/InterceptingPropertyValueProviderBase.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/InterceptedProjectProperties/InterceptingPropertyValueProviderBase.cs index 0af3f6676e9..cbdf8b568ba 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/InterceptedProjectProperties/InterceptingPropertyValueProviderBase.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/InterceptedProjectProperties/InterceptingPropertyValueProviderBase.cs @@ -12,21 +12,21 @@ namespace Microsoft.VisualStudio.ProjectSystem.Properties internal abstract class InterceptingPropertyValueProviderBase : IInterceptingPropertyValueProvider { /// - public virtual Task OnGetEvaluatedPropertyValueAsync(string evaluatedPropertyValue, IProjectProperties defaultProperties) + public virtual Task OnGetEvaluatedPropertyValueAsync(string? evaluatedPropertyValue, IProjectProperties defaultProperties) { return Task.FromResult(evaluatedPropertyValue); } /// - public virtual Task OnGetUnevaluatedPropertyValueAsync(string unevaluatedPropertyValue, IProjectProperties defaultProperties) + public virtual Task OnGetUnevaluatedPropertyValueAsync(string? unevaluatedPropertyValue, IProjectProperties defaultProperties) { return Task.FromResult(unevaluatedPropertyValue); } /// - public virtual Task OnSetPropertyValueAsync(string unevaluatedPropertyValue, IProjectProperties defaultProperties, IReadOnlyDictionary dimensionalConditions = null) + public virtual Task OnSetPropertyValueAsync(string? unevaluatedPropertyValue, IProjectProperties defaultProperties, IReadOnlyDictionary? dimensionalConditions = null) { return Task.FromResult(unevaluatedPropertyValue); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/InterceptedProjectProperties/PackagePropertyPage/BaseVersionValueProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/InterceptedProjectProperties/PackagePropertyPage/BaseVersionValueProvider.cs index 9ce4900188e..feea3a4b41b 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/InterceptedProjectProperties/PackagePropertyPage/BaseVersionValueProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/InterceptedProjectProperties/PackagePropertyPage/BaseVersionValueProvider.cs @@ -30,7 +30,7 @@ protected virtual async Task GetDefaultVersionAsync(IProjectProperties return Version.TryParse(versionStr, out Version version) ? version : DefaultVersion; } - public override async Task OnGetEvaluatedPropertyValueAsync(string evaluatedPropertyValue, IProjectProperties defaultProperties) + public override async Task OnGetEvaluatedPropertyValueAsync(string? evaluatedPropertyValue, IProjectProperties defaultProperties) { if (!string.IsNullOrEmpty(evaluatedPropertyValue)) { @@ -42,7 +42,7 @@ public override async Task OnGetEvaluatedPropertyValueAsync(string evalu return version.ToString(); } - public override async Task OnSetPropertyValueAsync(string unevaluatedPropertyValue, IProjectProperties defaultProperties, IReadOnlyDictionary dimensionalConditions = null) + public override async Task OnSetPropertyValueAsync(string? unevaluatedPropertyValue, IProjectProperties defaultProperties, IReadOnlyDictionary? dimensionalConditions = null) { // Don't set the new value if both of the following is true: // 1. There is no existing property entry AND diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/InterceptedProjectProperties/SigningPropertyPage/AssemblyOriginatorKeyFileValueProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/InterceptedProjectProperties/SigningPropertyPage/AssemblyOriginatorKeyFileValueProvider.cs index f0b0afe6b89..75a50bce30e 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/InterceptedProjectProperties/SigningPropertyPage/AssemblyOriginatorKeyFileValueProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/InterceptedProjectProperties/SigningPropertyPage/AssemblyOriginatorKeyFileValueProvider.cs @@ -18,7 +18,7 @@ public AssemblyOriginatorKeyFileValueProvider(UnconfiguredProject project) _unconfiguredProject = project; } - public override Task OnSetPropertyValueAsync(string unevaluatedPropertyValue, IProjectProperties defaultProperties, IReadOnlyDictionary dimensionalConditions = null) + public override Task OnSetPropertyValueAsync(string? unevaluatedPropertyValue, IProjectProperties defaultProperties, IReadOnlyDictionary? dimensionalConditions = null) { if (Path.IsPathRooted(unevaluatedPropertyValue) && PathHelper.TryMakeRelativeToProjectDirectory(_unconfiguredProject, unevaluatedPropertyValue, out string relativePath)) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/InterceptedProjectProperties/TargetFrameworkValueProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/InterceptedProjectProperties/TargetFrameworkValueProvider.cs index 9941c7fb24e..c2b907b5b52 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/InterceptedProjectProperties/TargetFrameworkValueProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/InterceptedProjectProperties/TargetFrameworkValueProvider.cs @@ -17,7 +17,7 @@ public TargetFrameworkValueProvider(ProjectProperties properties) _properties = properties; } - public override async Task OnGetEvaluatedPropertyValueAsync(string evaluatedPropertyValue, IProjectProperties defaultProperties) + public override async Task OnGetEvaluatedPropertyValueAsync(string? evaluatedPropertyValue, IProjectProperties defaultProperties) { ConfigurationGeneral configuration = await _properties.GetConfigurationGeneralPropertiesAsync(); string targetFrameworkMoniker = (string)await configuration.TargetFrameworkMoniker.GetValueAsync(); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/ProjectRuleSnapshotExtensions.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/ProjectRuleSnapshotExtensions.cs index 18cc5ad48f3..3ab4b310b8e 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/ProjectRuleSnapshotExtensions.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/ProjectRuleSnapshotExtensions.cs @@ -12,7 +12,7 @@ internal static class ProjectRuleSnapshotExtensions /// /// Gets the value that is associated with the specified rule and property. /// - public static string GetPropertyOrDefault(this IImmutableDictionary snapshots, string ruleName, string propertyName, string defaultValue) + public static string? GetPropertyOrDefault(this IImmutableDictionary snapshots, string ruleName, string propertyName, string? defaultValue) { Requires.NotNull(snapshots, nameof(snapshots)); Requires.NotNullOrEmpty(ruleName, nameof(ruleName)); @@ -32,7 +32,7 @@ public static string GetPropertyOrDefault(this IImmutableDictionary public static bool IsPropertyTrue(this IImmutableDictionary snapshots, string ruleName, string propertyName, bool defaultValue) { - string value = snapshots.GetPropertyOrDefault(ruleName, propertyName, defaultValue ? "true" : "false"); + string? value = snapshots.GetPropertyOrDefault(ruleName, propertyName, defaultValue ? "true" : "false"); return StringComparers.PropertyValues.Equals(value, "true"); } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/RuleExtensions.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/RuleExtensions.cs index 05aa345ce5b..14d57b1c5ac 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/RuleExtensions.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/RuleExtensions.cs @@ -16,7 +16,7 @@ internal static class RuleExtensions /// /// The item type the rule represents. May be null or empty to represent a project-level property rule. /// An empty rule. - internal static Rule SynthesizeEmptyRule(string itemType = null) + internal static Rule SynthesizeEmptyRule(string? itemType = null) { var emptyRule = new Rule { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/SpecialFileProviders/AbstractSpecialFileProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/SpecialFileProviders/AbstractSpecialFileProvider.cs index 7e26c61dea7..b39dbdb9074 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/SpecialFileProviders/AbstractSpecialFileProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/SpecialFileProviders/AbstractSpecialFileProvider.cs @@ -85,7 +85,7 @@ protected abstract string TemplateName public async Task GetFileAsync(SpecialFiles fileId, SpecialFileFlags flags, CancellationToken cancellationToken = default) { // Search for the file in the app designer and root folders. - IProjectTree specialFileNode = await FindFileAsync(Name); + IProjectTree? specialFileNode = await FindFileAsync(Name); if (specialFileNode != null) { if (await IsNodeInSyncWithDiskAsync(specialFileNode, forceSync: flags.HasFlag(SpecialFileFlags.CreateIfNotExist), cancellationToken: cancellationToken)) @@ -116,15 +116,15 @@ public async Task GetFileAsync(SpecialFiles fileId, SpecialFileFlags fla /// Look under the appdesigner folder for files that normally live there. /// Look under the project root for all files. /// - protected virtual async Task FindFileAsync(string specialFileName) + protected virtual async Task FindFileAsync(string specialFileName) { IProjectTree rootNode = _projectTree.CurrentTree; - IProjectTree specialFileNode; + IProjectTree? specialFileNode; // First, we look in the AppDesigner folder. if (CreatedByDefaultUnderAppDesignerFolder) { - IProjectTree appDesignerFolder = await GetAppDesignerFolderAsync(createIfNotExists: false); + IProjectTree? appDesignerFolder = await GetAppDesignerFolderAsync(createIfNotExists: false); if (appDesignerFolder != null) { specialFileNode = FindFileWithinNode(appDesignerFolder, specialFileName); @@ -148,7 +148,7 @@ protected virtual async Task FindFileAsync(string specialFileName) /// /// Find a file with the given filename within the given node. /// - private static IProjectTree FindFileWithinNode(IProjectTree parentNode, string fileName) + private static IProjectTree? FindFileWithinNode(IProjectTree parentNode, string fileName) { parentNode.TryFindImmediateChild(fileName, out IProjectTree fileNode); @@ -206,7 +206,7 @@ private async Task CreateFileAsync(string specialFileName) { IProjectTree rootNode = await GetParentFolderAsync(createIfNotExists: true); - string parentPath = _projectTree.TreeProvider.GetRootedAddNewItemDirectory(rootNode); + string? parentPath = _projectTree.TreeProvider.GetRootedAddNewItemDirectory(rootNode); string specialFilePath = Path.Combine(parentPath, specialFileName); // If we can create the file from the template do it, otherwise just create an empty file. @@ -233,7 +233,7 @@ private async Task GetParentFolderAsync(bool createIfNotExists) { if (CreatedByDefaultUnderAppDesignerFolder) { - IProjectTree tree = await GetAppDesignerFolderAsync(createIfNotExists); + IProjectTree? tree = await GetAppDesignerFolderAsync(createIfNotExists); if (tree != null) return tree; } @@ -241,7 +241,7 @@ private async Task GetParentFolderAsync(bool createIfNotExists) return _projectTree.CurrentTree; } - private async Task GetAppDesignerFolderAsync(bool createIfNotExists) + private async Task GetAppDesignerFolderAsync(bool createIfNotExists) { SpecialFileFlags flags = SpecialFileFlags.FullPath; if (createIfNotExists) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/SpecialFileProviders/AppDesignerFolderSpecialFileProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/SpecialFileProviders/AppDesignerFolderSpecialFileProvider.cs index 0e849350d2e..878c5f47c9d 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/SpecialFileProviders/AppDesignerFolderSpecialFileProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/SpecialFileProviders/AppDesignerFolderSpecialFileProvider.cs @@ -28,17 +28,12 @@ public AppDesignerFolderSpecialFileProvider(Lazy projectTr _properties = properties; } - // For unit tests - protected AppDesignerFolderSpecialFileProvider() - { - } - - public virtual async Task GetFileAsync(SpecialFiles fileId, SpecialFileFlags flags, CancellationToken cancellationToken = default) + public virtual async Task GetFileAsync(SpecialFiles fileId, SpecialFileFlags flags, CancellationToken cancellationToken = default) { // Make sure at least have a tree before we start searching it await _projectTree.Value.TreeService.PublishAnyNonLoadingTreeAsync(cancellationToken); - string path = FindAppDesignerFolder(); + string? path = FindAppDesignerFolder(); if (path == null) { // Not found, let's find the default path and create it if needed @@ -54,7 +49,7 @@ public virtual async Task GetFileAsync(SpecialFiles fileId, SpecialFileF return path; } - private string FindAppDesignerFolder() + private string? FindAppDesignerFolder() { IProjectTree root = _projectTree.Value.CurrentTree; @@ -65,9 +60,9 @@ private string FindAppDesignerFolder() return _projectTree.Value.TreeProvider.GetRootedAddNewItemDirectory(folder); } - private async Task GetDefaultAppDesignerFolderPathAsync() + private async Task GetDefaultAppDesignerFolderPathAsync() { - string rootPath = _projectTree.Value.TreeProvider.GetRootedAddNewItemDirectory(_projectTree.Value.CurrentTree); + string? rootPath = _projectTree.Value.TreeProvider.GetRootedAddNewItemDirectory(_projectTree.Value.CurrentTree); string folderName = await GetDefaultAppDesignerFolderNameAsync(); if (string.IsNullOrEmpty(folderName)) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/SpecialFileProviders/AppManifestSpecialFileProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/SpecialFileProviders/AppManifestSpecialFileProvider.cs index fd5f42f80c9..857bdb78c3f 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/SpecialFileProviders/AppManifestSpecialFileProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/SpecialFileProviders/AppManifestSpecialFileProvider.cs @@ -32,7 +32,7 @@ public AppManifestSpecialFileProvider(IPhysicalProjectTree projectTree, protected override string TemplateName => "AppManifestInternal.zip"; - protected override async Task FindFileAsync(string specialFileName) + protected override async Task FindFileAsync(string specialFileName) { // If the ApplicationManifest property is defined then we should just use that - otherwise fall back to the default logic to find app.manifest. ConfigurationGeneralBrowseObject configurationGeneral = await _projectProperties.GetConfigurationGeneralBrowseObjectPropertiesAsync(); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/UnconfiguredProjectTasksService.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/UnconfiguredProjectTasksService.cs index 7f1e01f6128..42583369b1e 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/UnconfiguredProjectTasksService.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/UnconfiguredProjectTasksService.cs @@ -95,12 +95,12 @@ public Task PrioritizedProjectLoadedInHostAsync(Func action) public void OnProjectLoadedInHost() { - _projectLoadedInHost.SetResult(null); + _projectLoadedInHost.SetResult(null!); } public void OnPrioritizedProjectLoadedInHost() { - _prioritizedProjectLoadedInHost.SetResult(null); + _prioritizedProjectLoadedInHost.SetResult(null!); _threadingService.ExecuteSynchronously(() => _prioritizedTaskQueue.DrainAsync()); } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/UpToDate/BuildUpToDateCheck.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/UpToDate/BuildUpToDateCheck.cs index 8db18b28da8..c2dd652e6bf 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/UpToDate/BuildUpToDateCheck.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/UpToDate/BuildUpToDateCheck.cs @@ -56,21 +56,21 @@ internal sealed class BuildUpToDateCheck : OnceInitializedOnceDisposed, IBuildUp private readonly ITelemetryService _telemetryService; private readonly IFileSystem _fileSystem; - private IDisposable _link; - private IComparable _lastVersionSeen; + private IDisposable? _link; + private IComparable? _lastVersionSeen; private bool _isDisabled = true; private bool _itemsChangedSinceLastCheck = true; - private string _msBuildProjectFullPath; - private string _msBuildProjectDirectory; - private string _markerFile; - private string _outputRelativeOrFullPath; - private string _newestImportInput; + private string? _msBuildProjectFullPath; + private string? _msBuildProjectDirectory; + private string? _markerFile; + private string? _outputRelativeOrFullPath; + private string? _newestImportInput; private DateTime _lastCheckTimeUtc = DateTime.MinValue; private readonly HashSet _itemTypes = new HashSet(StringComparers.ItemTypes); - private readonly Dictionary> _items = new Dictionary>(StringComparers.ItemTypes); + private readonly Dictionary> _items = new Dictionary>(StringComparers.ItemTypes); private readonly HashSet _customInputs = new HashSet(StringComparers.Paths); private readonly HashSet _customOutputs = new HashSet(StringComparers.Paths); private readonly HashSet _builtOutputs = new HashSet(StringComparers.Paths); @@ -128,12 +128,12 @@ private void OnProjectChanged(IProjectSubscriptionUpdate e) _msBuildProjectFullPath = e.CurrentState.GetPropertyOrDefault(ConfigurationGeneral.SchemaName, ConfigurationGeneral.MSBuildProjectFullPathProperty, _msBuildProjectFullPath); _msBuildProjectDirectory = e.CurrentState.GetPropertyOrDefault(ConfigurationGeneral.SchemaName, ConfigurationGeneral.MSBuildProjectDirectoryProperty, _msBuildProjectDirectory); _outputRelativeOrFullPath = e.CurrentState.GetPropertyOrDefault(ConfigurationGeneral.SchemaName, ConfigurationGeneral.OutputPathProperty, _outputRelativeOrFullPath); - string msBuildAllProjects = e.CurrentState.GetPropertyOrDefault(ConfigurationGeneral.SchemaName, ConfigurationGeneral.MSBuildAllProjectsProperty, ""); + string? msBuildAllProjects = e.CurrentState.GetPropertyOrDefault(ConfigurationGeneral.SchemaName, ConfigurationGeneral.MSBuildAllProjectsProperty, ""); // The first item in this semicolon-separated list of project files will always be the one // with the newest timestamp. As we are only interested in timestamps on these files, we can // save memory and time by only considering this first path (dotnet/project-system#4333). - _newestImportInput = new LazyStringSplit(msBuildAllProjects, ';').FirstOrDefault(); + _newestImportInput = msBuildAllProjects == null ? null : new LazyStringSplit(msBuildAllProjects, ';').FirstOrDefault(); if (e.ProjectChanges.TryGetValue(ResolvedAnalyzerReference.SchemaName, out IProjectChangeDescription changes) && changes.Difference.AnyChanges) @@ -206,7 +206,7 @@ private void OnProjectChanged(IProjectSubscriptionUpdate e) } } - private static string GetLink(IImmutableDictionary itemMetadata) => + private static string? GetLink(IImmutableDictionary itemMetadata) => itemMetadata.TryGetValue(Link, out string link) ? link : null; private static CopyToOutputDirectoryType GetCopyType(IImmutableDictionary itemMetadata) @@ -246,7 +246,7 @@ private void OnSourceItemChanged(IProjectSubscriptionUpdate e, IProjectItemSchem if (!itemTypesChanged && !changes.Difference.AnyChanges) continue; - _items[itemType] = new HashSet<(string path, string link, CopyToOutputDirectoryType copyType)>( + _items[itemType] = new HashSet<(string path, string? link, CopyToOutputDirectoryType copyType)>( changes.After.Items.Select(item => (item.Key, GetLink(item.Value), GetCopyType(item.Value))), UpToDateCheckItemComparer.Instance); _itemsChangedSinceLastCheck = true; @@ -337,8 +337,11 @@ private bool CheckGlobalConditions(BuildAction buildAction, BuildUpToDateCheckLo private IEnumerable CollectInputs(BuildUpToDateCheckLogger logger) { logger.Verbose("Adding project file inputs:"); - logger.Verbose(" '{0}'", _msBuildProjectFullPath); - yield return _msBuildProjectFullPath; + if (_msBuildProjectFullPath != null) + { + logger.Verbose(" '{0}'", _msBuildProjectFullPath); + yield return _msBuildProjectFullPath; + } if (_newestImportInput != null) { @@ -384,7 +387,7 @@ private IEnumerable CollectInputs(BuildUpToDateCheckLogger logger) if (_customInputs.Count != 0) { logger.Verbose("Adding " + UpToDateCheckInput.SchemaName + " inputs:"); - foreach (string input in _customInputs.Select(_configuredProject.UnconfiguredProject.MakeRooted)) + foreach (string input in _customInputs.Select(s => _configuredProject.UnconfiguredProject.MakeRooted(s))) { logger.Verbose(" '{0}'", input); yield return input; @@ -398,7 +401,7 @@ private IEnumerable CollectOutputs(BuildUpToDateCheckLogger logger) { logger.Verbose("Adding " + UpToDateCheckOutput.SchemaName + " outputs:"); - foreach (string output in _customOutputs.Select(_configuredProject.UnconfiguredProject.MakeRooted)) + foreach (string output in _customOutputs.Select(s =>_configuredProject.UnconfiguredProject.MakeRooted(s))) { logger.Verbose(" '{0}'", output); yield return output; @@ -409,7 +412,7 @@ private IEnumerable CollectOutputs(BuildUpToDateCheckLogger logger) { logger.Verbose("Adding " + UpToDateCheckBuilt.SchemaName + " outputs:"); - foreach (string output in _builtOutputs.Select(_configuredProject.UnconfiguredProject.MakeRooted)) + foreach (string output in _builtOutputs.Select(s => _configuredProject.UnconfiguredProject.MakeRooted(s))) { logger.Verbose(" '{0}'", output); yield return output; @@ -417,10 +420,10 @@ private IEnumerable CollectOutputs(BuildUpToDateCheckLogger logger) } } - private (DateTime time, string path) GetLatestInput(IEnumerable inputs, IDictionary timestampCache) + private (DateTime time, string? path) GetLatestInput(IEnumerable inputs, IDictionary timestampCache) { DateTime latest = DateTime.MinValue; - string latestPath = null; + string? latestPath = null; foreach (string input in inputs) { @@ -428,7 +431,9 @@ private IEnumerable CollectOutputs(BuildUpToDateCheckLogger logger) if (time > latest) { +#pragma warning disable CS8629 // Workaround https://github.com/dotnet/roslyn/issues/31863 latest = time.Value; +#pragma warning restore CS8629 latestPath = input; } } @@ -444,10 +449,10 @@ private IEnumerable CollectOutputs(BuildUpToDateCheckLogger logger) /// (null, null) when there were no outputs /// /// - private (DateTime? time, string path) GetEarliestOutput(IEnumerable outputs, IDictionary timestampCache) + private (DateTime? time, string? path) GetEarliestOutput(IEnumerable outputs, IDictionary timestampCache) { DateTime? earliest = DateTime.MaxValue; - string earliestPath = null; + string? earliestPath = null; bool hasOutput = false; foreach (string output in outputs) @@ -468,9 +473,11 @@ private IEnumerable CollectOutputs(BuildUpToDateCheckLogger logger) hasOutput = true; } +#pragma warning disable CS8626 // Workaround https://github.com/dotnet/roslyn/issues/31864 return hasOutput ? (earliest, earliestPath) : (null, null); +#pragma warning restore CS8626 } private bool CheckOutputs(BuildUpToDateCheckLogger logger, IDictionary timestampCache) @@ -613,7 +620,7 @@ private bool CheckCopiedOutputFiles(BuildUpToDateCheckLogger logger, IDictionary private bool CheckCopyToOutputDirectoryFiles(BuildUpToDateCheckLogger logger, IDictionary timestampCache) { - IEnumerable<(string path, string link, CopyToOutputDirectoryType copyType)> items = _items.SelectMany(kvp => kvp.Value).Where(item => item.copyType == CopyToOutputDirectoryType.CopyIfNewer); + IEnumerable<(string path, string? link, CopyToOutputDirectoryType copyType)> items = _items.SelectMany(kvp => kvp.Value).Where(item => item.copyType == CopyToOutputDirectoryType.CopyIfNewer); string outputFullPath = Path.Combine(_msBuildProjectDirectory, _outputRelativeOrFullPath); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/UpToDate/BuildUpToDateCheckLogger.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/UpToDate/BuildUpToDateCheckLogger.cs index 84c55ede9ad..4b3b078bb39 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/UpToDate/BuildUpToDateCheckLogger.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/UpToDate/BuildUpToDateCheckLogger.cs @@ -18,7 +18,7 @@ public BuildUpToDateCheckLogger(TextWriter logger, LogLevel requestedLogLevel, s _fileName = Path.GetFileNameWithoutExtension(projectPath); } - private void Log(LogLevel level, string message, params object[] values) + private void Log(LogLevel level, string message, params object?[] values) { if (level <= _requestedLogLevel) { @@ -29,7 +29,7 @@ private void Log(LogLevel level, string message, params object[] values) _logger?.WriteLine($"FastUpToDate: {string.Format(message, values)} ({_fileName})"); } } - private static void ConvertToLocalTimes(object[] values) + private static void ConvertToLocalTimes(object?[] values) { for (int i = 0; i < values.Length; i++) { @@ -40,7 +40,7 @@ private static void ConvertToLocalTimes(object[] values) } } - public void Info(string message, params object[] values) => Log(LogLevel.Info, message, values); - public void Verbose(string message, params object[] values) => Log(LogLevel.Verbose, message, values); + public void Info(string message, params object?[] values) => Log(LogLevel.Info, message, values); + public void Verbose(string message, params object?[] values) => Log(LogLevel.Verbose, message, values); } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/UpToDate/UpToDateCheckItemComparer.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/UpToDate/UpToDateCheckItemComparer.cs index 66cda381c53..7af4a6693fc 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/UpToDate/UpToDateCheckItemComparer.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/UpToDate/UpToDateCheckItemComparer.cs @@ -2,7 +2,7 @@ namespace Microsoft.VisualStudio.ProjectSystem.UpToDate { - internal class UpToDateCheckItemComparer : IEqualityComparer<(string path, string link, CopyToOutputDirectoryType copyType)> + internal class UpToDateCheckItemComparer : IEqualityComparer<(string path, string? link, CopyToOutputDirectoryType copyType)> { public static UpToDateCheckItemComparer Instance = new UpToDateCheckItemComparer(); @@ -11,14 +11,14 @@ private UpToDateCheckItemComparer() } public bool Equals( - (string path, string link, CopyToOutputDirectoryType copyType) x, - (string path, string link, CopyToOutputDirectoryType copyType) y) + (string path, string? link, CopyToOutputDirectoryType copyType) x, + (string path, string? link, CopyToOutputDirectoryType copyType) y) { return StringComparers.Paths.Equals(x.path, y.path); } public int GetHashCode( - (string path, string link, CopyToOutputDirectoryType copyType) obj) + (string path, string? link, CopyToOutputDirectoryType copyType) obj) { return StringComparers.Paths.GetHashCode(obj.path); } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/StringComparers.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/StringComparers.cs index c384f36659c..b444a6bb805 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/StringComparers.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/StringComparers.cs @@ -16,7 +16,7 @@ internal static class StringComparers public static IEqualityComparer WorkspaceProjectContextIds => StringComparer.Ordinal; public static IEqualityComparer Paths => StringComparer.OrdinalIgnoreCase; public static IEqualityComparer PropertyNames => StringComparer.OrdinalIgnoreCase; - public static IEqualityComparer PropertyValues => StringComparer.OrdinalIgnoreCase; + public static IEqualityComparer PropertyValues => StringComparer.OrdinalIgnoreCase; public static IEqualityComparer RuleNames => StringComparer.OrdinalIgnoreCase; public static IEqualityComparer ConfigurationDimensionNames => StringComparer.Ordinal; public static IEqualityComparer DependencyProviderTypes => StringComparer.OrdinalIgnoreCase; diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/StringFormat.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/StringFormat.cs index 45d5cbc83e5..c230991afc9 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/StringFormat.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/StringFormat.cs @@ -18,9 +18,9 @@ internal readonly struct StringFormat private static readonly object[] s_twoArgumentArray = new object[2]; private static readonly object[] s_threeArgumentArray = new object[3]; private readonly string _format; - private readonly object _argument1; - private readonly object _argument2; - private readonly object _argument3; + private readonly object? _argument1; + private readonly object? _argument2; + private readonly object? _argument3; private readonly object[] _arguments; public StringFormat(string text) @@ -68,17 +68,17 @@ public StringFormat(string format, object[] arguments) _arguments = arguments; } - public object Argument1 + public object? Argument1 { get { return _argument1; } } - public object Argument2 + public object? Argument2 { get { return _argument2; } } - public object Argument3 + public object? Argument3 { get { return _argument3; } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Text/LazyStringSplit.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Text/LazyStringSplit.cs index 8805d0d0580..adbabcf952e 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Text/LazyStringSplit.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Text/LazyStringSplit.cs @@ -50,7 +50,7 @@ public string First() return FirstOrDefault() ?? throw new InvalidOperationException("Sequence is empty."); } - public string FirstOrDefault() + public string? FirstOrDefault() { var enumerator = new Enumerator(this); return enumerator.MoveNext() ? enumerator.Current : null; @@ -67,7 +67,7 @@ internal Enumerator(in LazyStringSplit split) _index = 0; _input = split._input; _delimiter = split._delimiter; - Current = null; + Current = null!; } public string Current { get; private set; } @@ -106,7 +106,7 @@ public bool MoveNext() void IEnumerator.Reset() { _index = 0; - Current = default; + Current = null!; } void IDisposable.Dispose() {} @@ -120,7 +120,7 @@ internal static class LazyStringSplitExtensions /// can compute its result without allocation. /// /// - public static string FirstOrDefault(this LazyStringSplit lazyStringSplit) + public static string? FirstOrDefault(this LazyStringSplit lazyStringSplit) { LazyStringSplit.Enumerator enumerator = lazyStringSplit.GetEnumerator(); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Threading/Tasks/CancellationSeries.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Threading/Tasks/CancellationSeries.cs index 6e6a0f2ba06..0a349dcf59f 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Threading/Tasks/CancellationSeries.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Threading/Tasks/CancellationSeries.cs @@ -103,7 +103,9 @@ public void Dispose() GC.SuppressFinalize(this); #endif +#pragma warning disable CS8625 // Workaround https://github.com/dotnet/roslyn/issues/31865 CancellationTokenSource source = Interlocked.Exchange(ref _cts, null); +#pragma warning restore CS8625 if (source == null) { From 10ad70b2072467ccc84ec38781044b132d52d4e6 Mon Sep 17 00:00:00 2001 From: Kevin Pilch Date: Mon, 17 Dec 2018 10:24:29 -0800 Subject: [PATCH 05/20] Switch to #pragmas and link to issues --- .../ProjectSystem/AbstractMultiLifetimeComponent.cs | 4 +++- .../AppDesignerFolderProjectTreePropertiesProvider.cs | 6 ++++-- .../Build/ImplicitlyActiveConfiguredProjectReadyToBuild.cs | 4 +++- .../ConfiguredProjectImplicitActivationTracking.cs | 4 +++- .../ProjectSystem/Debug/LaunchSettings.cs | 4 +++- .../ProjectSystem/Debug/WritableLaunchSettings.cs | 5 +++-- 6 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/AbstractMultiLifetimeComponent.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/AbstractMultiLifetimeComponent.cs index 50088c11a08..acfe814c3b9 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/AbstractMultiLifetimeComponent.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/AbstractMultiLifetimeComponent.cs @@ -65,7 +65,9 @@ private async Task LoadCoreAsync() // While all callers should wait on InitializeAsync, // only one should complete the completion source await instance.InitializeAsync(); - loadedSource?.SetResult(null!); +#pragma warning disable CS8625 // Workaround for https://github.com/dotnet/roslyn/issues/31865 + loadedSource?.SetResult(null); +#pragma warning restore CS8625 } public Task UnloadAsync() diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/AppDesignerFolderProjectTreePropertiesProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/AppDesignerFolderProjectTreePropertiesProvider.cs index 0e834aa657a..0eaf856a761 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/AppDesignerFolderProjectTreePropertiesProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/AppDesignerFolderProjectTreePropertiesProvider.cs @@ -61,8 +61,10 @@ public void UpdateProjectTreeSettings(IImmutableDictionary tasks = ImplicitlyActiveServices.Select(c => c.Value.ActivateAsync()); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/LaunchSettings.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/LaunchSettings.cs index e93bd674633..0c8b92f2a7a 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/LaunchSettings.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/LaunchSettings.cs @@ -65,7 +65,9 @@ public LaunchSettings(IWritableLaunchSettings settings) else { string jsonString = JsonConvert.SerializeObject(value, Formatting.Indented, jsonSerializerSettings); - object clonedObject = JsonConvert.DeserializeObject(jsonString, value?.GetType()); +#pragma warning disable CS8602 // Workaround https://github.com/dotnet/roslyn/issues/31803 + object clonedObject = JsonConvert.DeserializeObject(jsonString, value.GetType()); +#pragma warning restore CS8602 GlobalSettings = GlobalSettings.Add(key, clonedObject); } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/WritableLaunchSettings.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/WritableLaunchSettings.cs index 056eab66f61..0b103d4fe26 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/WritableLaunchSettings.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/WritableLaunchSettings.cs @@ -42,8 +42,9 @@ public WritableLaunchSettings(ILaunchSettings settings) else { string jsonString = JsonConvert.SerializeObject(value, Formatting.Indented, jsonSerializerSettings); - // TODO: Bug in nullable flow analysis her? - object clonedObject = JsonConvert.DeserializeObject(jsonString, value!.GetType()); +#pragma warning disable CS8602 // Workaround https://github.com/dotnet/roslyn/issues/31803 + object clonedObject = JsonConvert.DeserializeObject(jsonString, value.GetType()); +#pragma warning restore CS8602 GlobalSettings.Add(key, clonedObject); } } From 80cc3543576cff0ebc1fffa30389ba1fb9cc8419 Mon Sep 17 00:00:00 2001 From: Kevin Pilch Date: Mon, 17 Dec 2018 10:29:21 -0800 Subject: [PATCH 06/20] Use ! for invariant the compiler doesn't know --- .../AppDesignerFolderProjectTreePropertiesProvider.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/AppDesignerFolderProjectTreePropertiesProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/AppDesignerFolderProjectTreePropertiesProvider.cs index 0eaf856a761..0870834d9fa 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/AppDesignerFolderProjectTreePropertiesProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/AppDesignerFolderProjectTreePropertiesProvider.cs @@ -58,13 +58,11 @@ public void UpdateProjectTreeSettings(IImmutableDictionary Date: Mon, 17 Dec 2018 10:54:44 -0800 Subject: [PATCH 07/20] Override compiler, when known to be non-null --- .../ProjectSystem/UpToDate/BuildUpToDateCheck.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/UpToDate/BuildUpToDateCheck.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/UpToDate/BuildUpToDateCheck.cs index c2dd652e6bf..7a18dad32ec 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/UpToDate/BuildUpToDateCheck.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/UpToDate/BuildUpToDateCheck.cs @@ -128,12 +128,12 @@ private void OnProjectChanged(IProjectSubscriptionUpdate e) _msBuildProjectFullPath = e.CurrentState.GetPropertyOrDefault(ConfigurationGeneral.SchemaName, ConfigurationGeneral.MSBuildProjectFullPathProperty, _msBuildProjectFullPath); _msBuildProjectDirectory = e.CurrentState.GetPropertyOrDefault(ConfigurationGeneral.SchemaName, ConfigurationGeneral.MSBuildProjectDirectoryProperty, _msBuildProjectDirectory); _outputRelativeOrFullPath = e.CurrentState.GetPropertyOrDefault(ConfigurationGeneral.SchemaName, ConfigurationGeneral.OutputPathProperty, _outputRelativeOrFullPath); - string? msBuildAllProjects = e.CurrentState.GetPropertyOrDefault(ConfigurationGeneral.SchemaName, ConfigurationGeneral.MSBuildAllProjectsProperty, ""); + string msBuildAllProjects = e.CurrentState.GetPropertyOrDefault(ConfigurationGeneral.SchemaName, ConfigurationGeneral.MSBuildAllProjectsProperty, "")!; // The first item in this semicolon-separated list of project files will always be the one // with the newest timestamp. As we are only interested in timestamps on these files, we can // save memory and time by only considering this first path (dotnet/project-system#4333). - _newestImportInput = msBuildAllProjects == null ? null : new LazyStringSplit(msBuildAllProjects, ';').FirstOrDefault(); + _newestImportInput = new LazyStringSplit(msBuildAllProjects, ';').FirstOrDefault(); if (e.ProjectChanges.TryGetValue(ResolvedAnalyzerReference.SchemaName, out IProjectChangeDescription changes) && changes.Difference.AnyChanges) From 23d641e7cf696d2a2d4a1d9763dbd8962e5ef80f Mon Sep 17 00:00:00 2001 From: Kevin Pilch Date: Mon, 17 Dec 2018 11:06:28 -0800 Subject: [PATCH 08/20] Use NotNullWhenTrueAttribute --- .../NotNullWhenTrueAttribute.cs | 9 +++++++++ .../UnconfiguredProjectContextProvider.cs | 12 ++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 src/Microsoft.VisualStudio.ProjectSystem.Managed/NotNullWhenTrueAttribute.cs diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/NotNullWhenTrueAttribute.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/NotNullWhenTrueAttribute.cs new file mode 100644 index 00000000000..904b649cbe5 --- /dev/null +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/NotNullWhenTrueAttribute.cs @@ -0,0 +1,9 @@ +namespace System.Runtime.CompilerServices +{ + [AttributeUsage(AttributeTargets.Parameter, + AllowMultiple = false)] + internal class NotNullWhenTrueAttribute : Attribute + { + public NotNullWhenTrueAttribute() { } + } +} diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/UnconfiguredProjectContextProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/UnconfiguredProjectContextProvider.cs index 0427bd095a4..922e7399654 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/UnconfiguredProjectContextProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/UnconfiguredProjectContextProvider.cs @@ -5,6 +5,7 @@ using System.Collections.Immutable; using System.ComponentModel.Composition; using System.IO; +using System.Runtime.CompilerServices; using System.Threading.Tasks; using Microsoft.VisualStudio.Buffers.PooledObjects; using Microsoft.VisualStudio.LanguageServices.ProjectSystem; @@ -170,7 +171,10 @@ private ProjectData GetProjectData() }; } - private bool TryGetConfiguredProjectState(ConfiguredProject configuredProject, out IWorkspaceProjectContext workspaceProjectContext, out IConfiguredProjectHostObject configuredProjectHostObject) + private bool TryGetConfiguredProjectState( + ConfiguredProject configuredProject, + [NotNullWhenTrue]out IWorkspaceProjectContext? workspaceProjectContext, + [NotNullWhenTrue]out IConfiguredProjectHostObject? configuredProjectHostObject) { lock (_gate) { @@ -181,8 +185,8 @@ private bool TryGetConfiguredProjectState(ConfiguredProject configuredProject, o } else { - workspaceProjectContext = null!; - configuredProjectHostObject = null!; + workspaceProjectContext = null; + configuredProjectHostObject = null; return false; } } @@ -229,7 +233,7 @@ private void AddConfiguredProjectState(ConfiguredProject configuredProject, IWor foreach ((string targetFramework, ConfiguredProject configuredProject) in configuredProjectsMap) { - if (!TryGetConfiguredProjectState(configuredProject, out IWorkspaceProjectContext workspaceProjectContext, out IConfiguredProjectHostObject configuredProjectHostObject)) + if (!TryGetConfiguredProjectState(configuredProject, out IWorkspaceProjectContext? workspaceProjectContext, out IConfiguredProjectHostObject? configuredProjectHostObject)) { // Get the target path for the configured project. ProjectProperties projectProperties = configuredProject.Services.ExportProvider.GetExportedValue(); From 69eba8236ec13960b31622f5c49eddc448cbd109 Mon Sep 17 00:00:00 2001 From: Kevin Pilch Date: Mon, 17 Dec 2018 12:28:55 -0800 Subject: [PATCH 09/20] Switch to Forget() so as to not change behavior --- .../ProjectSystem/VS/PropertyPages/PropertyPage.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/PropertyPage.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/PropertyPage.cs index e0ff15f12d2..d86b2ffe96f 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/PropertyPage.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/PropertyPage.cs @@ -10,6 +10,7 @@ using Microsoft.VisualStudio.OLE.Interop; using Microsoft.VisualStudio.ProjectSystem.Properties; using Microsoft.VisualStudio.Shell.Interop; +using Microsoft.VisualStudio.Threading; namespace Microsoft.VisualStudio.ProjectSystem.VS.PropertyPages { @@ -362,7 +363,7 @@ public void SetObjects(uint cObjects, object[] ppunk) } } - WaitForAsync(() => OnSetObjects(false)); + OnSetObjects(false).Forget(); } } } From 71d300dbe2616954e45a8fb19a547fb083f0fcff Mon Sep 17 00:00:00 2001 From: Kevin Pilch Date: Mon, 17 Dec 2018 12:35:58 -0800 Subject: [PATCH 10/20] Restore constructor used by Moq --- .../AppDesignerFolderSpecialFileProvider.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/SpecialFileProviders/AppDesignerFolderSpecialFileProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/SpecialFileProviders/AppDesignerFolderSpecialFileProvider.cs index 878c5f47c9d..36e18221bd1 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/SpecialFileProviders/AppDesignerFolderSpecialFileProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/SpecialFileProviders/AppDesignerFolderSpecialFileProvider.cs @@ -21,6 +21,13 @@ internal class AppDesignerFolderSpecialFileProvider : ISpecialFileProvider private readonly Lazy _projectTree; private readonly ProjectProperties _properties; + // For unit tests - tests will set the fields too. +#pragma warning disable CS8618 + protected AppDesignerFolderSpecialFileProvider() + { + } +#pragma warning restore CS8618 + [ImportingConstructor] public AppDesignerFolderSpecialFileProvider(Lazy projectTree, ProjectProperties properties) { From 5f9d10b8638d2a087a1f2f1fb5a3afd04682fc27 Mon Sep 17 00:00:00 2001 From: Kevin Pilch Date: Mon, 17 Dec 2018 14:50:01 -0800 Subject: [PATCH 11/20] Mark object IEnumerator.Current as nullable --- .../PooledObjects/PooledArray.Enumerator.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledArray.Enumerator.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledArray.Enumerator.cs index ed4f7643df6..8f394b45545 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledArray.Enumerator.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledArray.Enumerator.cs @@ -32,9 +32,7 @@ public void Dispose() { } -#pragma warning disable CS8603 // Workaround https://github.com/dotnet/roslyn/issues/31867 - object System.Collections.IEnumerator.Current => Current; -#pragma warning restore CS8603 + object? System.Collections.IEnumerator.Current => Current; public void Reset() => _index = -1; } From aff534b384d73b148e10f89b7082e8878a690aee Mon Sep 17 00:00:00 2001 From: Kevin Pilch Date: Mon, 17 Dec 2018 17:20:34 -0800 Subject: [PATCH 12/20] WIP: Annotate MS.VS.ProjectSystem.Managed.VS --- .../PropertyPages/PropertyPageControlTests.cs | 2 +- ...sualStudio.ProjectSystem.Managed.VS.csproj | 3 +- .../Packaging/ManagedProjectSystemPackage.cs | 4 +- .../AbstractExtenderCATIDProvider.cs | 2 +- .../ProjectSystem/VS/Automation/VsProject.cs | 4 +- .../VsProject_VsLangProjectProperties.cs | 2 +- ...rviceErrorListProvider.ErrorListDetails.cs | 2 +- .../Build/LanguageServiceErrorListProvider.cs | 4 +- .../VS/ConnectionPoint/ConnectionPoint.cs | 4 +- .../VS/Debug/ConsoleDebugTargetsProvider.cs | 22 ++--- .../Debug/DebugProfileDebugTargetGenerator.cs | 8 +- .../Debug/DebugProfileEnumValuesGenerator.cs | 4 +- .../Debug/ErrorProfileDebugTargetsProvider.cs | 4 +- .../VS/Debug/ProjectDebuggerProvider.cs | 17 ++-- .../VS/Debug/StartupProjectRegistrar.cs | 4 +- .../DotNetCoreProjectCompatibilityDetector.cs | 23 ++--- .../EditAndContinueProvider.cs | 11 ++- .../AppDesignerFolderProjectImageProvider.cs | 2 +- .../AbstractGenerateNuGetPackageCommand.cs | 10 ++- .../DebugFrameworksDynamicMenuCommand.cs | 8 +- .../DebugFrameworksMenuTextUpdater.cs | 6 +- .../VS/Input/Commands/Ordering/NodeHelper.cs | 12 +-- .../Ordering/OrderAddItemHintReceiver.cs | 6 +- .../Input/Commands/Ordering/OrderingHelper.cs | 26 +++--- .../Input/Commands/Ordering/PasteOrdering.cs | 4 +- .../VS/LanguageServices/AbstractHostObject.cs | 6 +- .../ActiveWorkspaceProjectContextTracker.cs | 4 +- .../ConfiguredProjectHostObject.cs | 4 +- .../ProjectContextCodeModelProvider.cs | 8 +- .../UnconfiguredProjectHostObject.cs | 6 +- .../VsContainedLanguageComponentsFactory.cs | 12 +-- .../IProjectOutputWindowPaneProvider.cs | 2 +- .../ProjectOutputWindowPaneProvider.cs | 8 +- ...itiator.PackageRestoreInitiatorInstance.cs | 20 ++--- .../VS/NuGet/ProjectAssetFileWatcher.cs | 20 ++--- .../VS/NuGet/ProjectRestoreInfo.cs | 8 +- .../VS/NuGet/ProjectRestoreInfoBuilder.cs | 8 +- .../ProjectSystem/VS/NuGet/VsItemList.cs | 8 +- .../ProjectSystem/VS/ProjectSystemOptions.cs | 3 +- .../AbstractProjectConfigurationProperties.cs | 2 +- ...tValueProvider.AbstractBuildEventHelper.cs | 8 +- .../AbstractBuildEventValueProvider.cs | 10 +-- .../OutputTypeValueProviderBase.cs | 7 +- .../TargetFrameworkMonikerValueProvider.cs | 5 +- .../TargetFrameworkMonikersValueProvider.cs | 7 +- ...ectFileOrAssemblyInfoPropertiesProvider.cs | 2 +- .../VS/PropertyPages/BuildMacroInfo.cs | 8 +- .../VS/PropertyPages/DebugPageControl.xaml.cs | 10 +-- .../VS/PropertyPages/DebugPageViewModel.cs | 89 +++++++++---------- .../EnvironmentGridTemplateColumn.cs | 4 +- .../ExecutableLaunchSettingsUIProvider.cs | 2 +- .../ProjectLaunchSettingsUIProvider.cs | 2 +- .../VS/PropertyPages/PropertyPage.cs | 6 +- .../VS/PropertyPages/PropertyPageControl.cs | 32 ++++--- .../VS/PropertyPages/PropertyPageViewModel.cs | 8 +- .../VS/PropertyPages/WatermarkTextBox.cs | 2 +- .../WpfBasedPropertyPage.Designer.cs | 4 +- .../DesignTimeAssemblyResolution.cs | 17 ++-- .../VS/Rename/SimpleRenameStrategy.cs | 6 +- .../VsProjectSpecialFilesManager.cs | 2 +- .../AggregateCrossTargetProjectContext.cs | 2 +- .../ICrossTargetSubscriptionsHost.cs | 2 +- .../CrossTarget/ITargetFrameworkProvider.cs | 4 +- .../CrossTarget/TargetFramework.cs | 2 +- .../CrossTarget/TargetFrameworkProvider.cs | 4 +- .../DependenciesProjectTreeProvider.cs | 20 ++--- .../VS/Tree/Dependencies/DependencyIconSet.cs | 6 +- .../CheckChildrenGraphActionHandler.cs | 2 +- .../Actions/GetChildrenGraphActionHandler.cs | 3 +- .../Actions/GraphActionHandlerBase.cs | 10 +-- .../Actions/SearchGraphActionHandler.cs | 2 +- .../Actions/TrackChangesGraphActionHandler.cs | 2 +- .../GraphNodes/DependenciesGraphProvider.cs | 6 +- .../GraphNodes/GraphNodeIdExtensions.cs | 4 +- .../ViewProviders/GraphViewProviderBase.cs | 2 +- .../ViewProviders/ProjectGraphViewProvider.cs | 30 +++---- .../GroupedByTargetTreeViewProvider.cs | 28 +++--- .../Dependencies/IDependenciesTreeServices.cs | 16 ++-- .../IDependenciesTreeViewProvider.cs | 2 +- .../VS/Tree/Dependencies/IDependencyModel.cs | 6 +- .../Dependencies/Models/DependencyModel.cs | 10 +-- .../Models/IDependencyViewModel.cs | 10 +-- .../PackageFrameworkAssembliesViewModel.cs | 10 +-- .../Dependencies/Models/SdkDependencyModel.cs | 8 +- .../Models/TargetDependencyViewModel.cs | 10 +-- ...nent.SDKVersionTelemetryServiceInstance.cs | 4 +- .../Snapshot/DependenciesSnapshot.cs | 12 +-- .../Tree/Dependencies/Snapshot/Dependency.cs | 16 ++-- .../Snapshot/Filters/AddDependencyContext.cs | 4 +- .../DuplicatedDependenciesSnapshotFilter.cs | 2 +- .../Filters/RemoveDependencyContext.cs | 2 +- .../UnsupportedProjectsSnapshotFilter.cs | 6 +- .../Snapshot/IDependenciesSnapshot.cs | 2 +- .../Tree/Dependencies/Snapshot/IDependency.cs | 8 +- .../Snapshot/IDependencyExtensions.cs | 8 +- .../Snapshot/TargetedDependenciesSnapshot.cs | 10 +-- .../DependencyRulesSubscriber.cs | 8 +- .../DependencySubscriptionsHost.cs | 12 +-- ...geRuleHandler.PackageDependencyMetadata.cs | 4 +- .../RuleHandlers/PackageRuleHandler.cs | 2 +- .../Tree/Dependencies/TreeViewProviderBase.cs | 2 +- .../ProjectSystem/VS/UI/IDialogServices.cs | 2 +- .../VS/UI/IVsShellUtilitiesHelper.cs | 4 +- .../VS/UI/VsShellUtilitiesHelper.cs | 4 +- .../VS/Utilities/MetadataExtensions.cs | 14 +-- .../VS/Utilities/NameValuePair.cs | 16 ++-- .../VS/Utilities/ObservableList.cs | 4 +- .../VS/Utilities/Web/RemoteCacheFile.cs | 4 +- .../ProjectSystem/VS/Utilities/WpfHelper.cs | 10 +-- .../VS/VsSolutionEventListener.cs | 6 +- .../Shell/Interop/VsHierarchyExtensions.cs | 8 +- ...viceProviderToOleServiceProviderAdapter.cs | 5 +- .../Debug/ILaunchSettingsUIProvider.cs | 2 +- .../ICreateFileFromTemplateService.cs | 2 +- ...ectFileOrAssemblyInfoPropertiesProvider.cs | 4 +- .../AssemblyInfoProperties.cs | 4 +- ...eAssemblyAttributePropertyValueProvider.cs | 6 +- .../ISpecialFilesManager.cs | 2 +- .../StringComparers.cs | 2 +- 119 files changed, 486 insertions(+), 460 deletions(-) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS.UnitTests/ProjectSystem/VS/PropertyPages/PropertyPageControlTests.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS.UnitTests/ProjectSystem/VS/PropertyPages/PropertyPageControlTests.cs index 09e2eaaf7e8..6124d89dc87 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS.UnitTests/ProjectSystem/VS/PropertyPages/PropertyPageControlTests.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS.UnitTests/ProjectSystem/VS/PropertyPages/PropertyPageControlTests.cs @@ -29,7 +29,7 @@ public void Test() private void CallPropertyPageControl() { var ppvm = new Mock(); - ppvm.Setup(m => m.Save()).ReturnsAsync(VSConstants.S_OK); + ppvm.Setup(m => m.Save()); ppvm.Setup(m => m.Initialize()).Returns(new Task(() => { })); ppvm.CallBase = true; diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/Microsoft.VisualStudio.ProjectSystem.Managed.VS.csproj b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/Microsoft.VisualStudio.ProjectSystem.Managed.VS.csproj index 2f385ccab47..b41b28578a8 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/Microsoft.VisualStudio.ProjectSystem.Managed.VS.csproj +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/Microsoft.VisualStudio.ProjectSystem.Managed.VS.csproj @@ -13,7 +13,8 @@ Microsoft VisualStudio ProjectSystem for Managed Languages Project hosts that interact with VisualStudio interfaces. Microsoft VisualStudio Managed Project System VS Components Roslyn Managed Project System VisualStudio - $(NoWarn);NU5125 + $(NoWarn);NU5125 + true diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/Packaging/ManagedProjectSystemPackage.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/Packaging/ManagedProjectSystemPackage.cs index d2746621cb7..f11a09393c4 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/Packaging/ManagedProjectSystemPackage.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/Packaging/ManagedProjectSystemPackage.cs @@ -40,7 +40,7 @@ internal partial class ManagedProjectSystemPackage : AsyncPackage ProjectCapability.LanguageService + "; " + ProjectCapability.DotNet; - private IDotNetCoreProjectCompatibilityDetector _dotNetCoreCompatibilityDetector; + private IDotNetCoreProjectCompatibilityDetector? _dotNetCoreCompatibilityDetector; public ManagedProjectSystemPackage() { @@ -53,7 +53,7 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke var componentModel = (IComponentModel)(await GetServiceAsync(typeof(SComponentModel))); Lazy debugFrameworksCmd = componentModel.DefaultExportProvider.GetExport(); - var mcs = (await GetServiceAsync(typeof(IMenuCommandService))) as OleMenuCommandService; + var mcs = (OleMenuCommandService)await GetServiceAsync(typeof(IMenuCommandService)); mcs.AddCommand(debugFrameworksCmd.Value); Lazy debugFrameworksMenuTextUpdater = componentModel.DefaultExportProvider.GetExport(); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Automation/AbstractExtenderCATIDProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Automation/AbstractExtenderCATIDProvider.cs index 438345aa376..fe9a109d8d4 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Automation/AbstractExtenderCATIDProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Automation/AbstractExtenderCATIDProvider.cs @@ -15,7 +15,7 @@ protected AbstractExtenderCATIDProvider() { } - public string GetExtenderCATID(ExtenderCATIDType extenderCATIDType, IProjectTree treeNode) + public string? GetExtenderCATID(ExtenderCATIDType extenderCATIDType, IProjectTree treeNode) { // CPS's implementation of ExtenderCATIDType incorrectly treats the same "instances" as distinct items based // where they are accessed in CPS. It also incorrectly maps "HierarchyExtensionObject" and "HierarchyBrowseObject" diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Automation/VsProject.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Automation/VsProject.cs index 75370e9ed1a..9c58a7417d1 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Automation/VsProject.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Automation/VsProject.cs @@ -135,13 +135,13 @@ public string GetUniqueFilename(object pDispatch, string bstrRoot, string bstrDe #region IConnectionPointContainer - public void EnumConnectionPoints(out IEnumConnectionPoints ppEnum) + public void EnumConnectionPoints(out IEnumConnectionPoints? ppEnum) { ppEnum = null; (_vsProject as IConnectionPointContainer)?.EnumConnectionPoints(out ppEnum); } - public void FindConnectionPoint(ref Guid riid, out IConnectionPoint ppCP) + public void FindConnectionPoint(ref Guid riid, out IConnectionPoint? ppCP) { ppCP = null; (_vsProject as IConnectionPointContainer)?.FindConnectionPoint(ref riid, out ppCP); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Automation/VsProject_VsLangProjectProperties.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Automation/VsProject_VsLangProjectProperties.cs index 84b9f7fea6e..1b3ba19be74 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Automation/VsProject_VsLangProjectProperties.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Automation/VsProject_VsLangProjectProperties.cs @@ -106,7 +106,7 @@ public string OutputFileName } } - public string ExtenderCATID => null; + public string? ExtenderCATID => null; public string AbsoluteProjectDirectory { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Build/LanguageServiceErrorListProvider.ErrorListDetails.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Build/LanguageServiceErrorListProvider.ErrorListDetails.cs index 5c5ee7cf2e2..9ac74a25089 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Build/LanguageServiceErrorListProvider.ErrorListDetails.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Build/LanguageServiceErrorListProvider.ErrorListDetails.cs @@ -34,7 +34,7 @@ public string File public string GetFileFullPath(ILanguageServiceHost languageServiceHost) { - string projectFile = ProjectFile; + string? projectFile = ProjectFile; if (string.IsNullOrEmpty(projectFile)) { projectFile = languageServiceHost.ActiveProjectContext?.ProjectFilePath; diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Build/LanguageServiceErrorListProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Build/LanguageServiceErrorListProvider.cs index e5fa5991f0a..098481d92d4 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Build/LanguageServiceErrorListProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Build/LanguageServiceErrorListProvider.cs @@ -22,7 +22,7 @@ internal partial class LanguageServiceErrorListProvider : IVsErrorListProvider private static readonly Task s_handledAndStopProcessing = Task.FromResult(AddMessageResult.HandledAndStopProcessing); private static readonly Task s_notHandled = Task.FromResult(AddMessageResult.NotHandled); private readonly ILanguageServiceHost _host; - private IVsLanguageServiceBuildErrorReporter2 _languageServiceBuildErrorReporter; + private IVsLanguageServiceBuildErrorReporter2? _languageServiceBuildErrorReporter; /// /// must be imported in the contructor in order for scope of this class' export to be correct. @@ -101,7 +101,7 @@ private void InitializeBuildErrorReporter() // We defer grabbing error reporter the until the first build event, because the language service is initialized asynchronously if (_languageServiceBuildErrorReporter == null) { - _languageServiceBuildErrorReporter = (IVsLanguageServiceBuildErrorReporter2)_host.HostSpecificErrorReporter; + _languageServiceBuildErrorReporter = (IVsLanguageServiceBuildErrorReporter2?)_host.HostSpecificErrorReporter; } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/ConnectionPoint/ConnectionPoint.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/ConnectionPoint/ConnectionPoint.cs index 90b94e33abd..6dcc5f96faf 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/ConnectionPoint/ConnectionPoint.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/ConnectionPoint/ConnectionPoint.cs @@ -38,9 +38,9 @@ public void Advise(object pUnkSink, out uint pdwCookie) Marshal.ThrowExceptionForHR(VSConstants.E_NOINTERFACE); } - _sinks.Add(_nextCookie, sink); + _sinks.Add(_nextCookie, sink!); pdwCookie = _nextCookie; - _source.OnSinkAdded(sink); + _source.OnSinkAdded(sink!); _nextCookie += 1; } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Debug/ConsoleDebugTargetsProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Debug/ConsoleDebugTargetsProvider.cs index 07bbf4007ec..11c965cc98a 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Debug/ConsoleDebugTargetsProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Debug/ConsoleDebugTargetsProvider.cs @@ -139,7 +139,7 @@ private async Task> QueryDebugTargetsAsync(D /// /// Does some basic validation of the settings. If we don't, the error messages are terrible. /// - public void ValidateSettings(string executable, string workingDir, string profileName) + public void ValidateSettings(string? executable, string workingDir, string? profileName) { if (string.IsNullOrEmpty(executable)) { @@ -158,12 +158,12 @@ public void ValidateSettings(string executable, string workingDir, string profil /// /// Helper returns cmd.exe as the launcher for Ctrl-F5 (useCmdShell == true), otherwise just the exe and args passed in. /// - public static void GetExeAndArguments(bool useCmdShell, string debugExe, string debugArgs, out string finalExePath, out string finalArguments) + public static void GetExeAndArguments(bool useCmdShell, string? debugExe, string? debugArgs, out string? finalExePath, out string? finalArguments) { if (useCmdShell) { // Escape the characters ^<>& so that they are passed to the application rather than interpreted by cmd.exe. - string escapedArgs = EscapeString(debugArgs, s_escapedChars); + string? escapedArgs = EscapeString(debugArgs, s_escapedChars); finalArguments = $"/c \"\"{debugExe}\" {escapedArgs} & pause\""; finalExePath = Path.Combine(Environment.SystemDirectory, "cmd.exe"); } @@ -201,7 +201,7 @@ private async Task GetConsoleTargetForProfile(ILaunchProfil { var settings = new DebugLaunchSettings(launchOptions); - string executable, arguments; + string? executable, arguments; string projectFolder = Path.GetDirectoryName(_project.FullPath); ConfiguredProject configuredProject = await GetConfiguredProjectForDebugAsync(); @@ -283,7 +283,7 @@ private async Task GetConsoleTargetForProfile(ILaunchProfil { // Try to resolve against the current working directory (for compat) and failing that, the environment path. string exeName = executable.EndsWith(".exe", StringComparison.OrdinalIgnoreCase) ? executable : executable + ".exe"; - string fullPath = _fileSystem.GetFullPath(exeName); + string? fullPath = _fileSystem.GetFullPath(exeName); if (_fileSystem.FileExists(fullPath)) { executable = fullPath; @@ -338,7 +338,7 @@ private async Task GetConsoleTargetForProfile(ILaunchProfil useCmdShell = UseCmdShellForConsoleLaunch(resolvedProfile, settings.LaunchOptions); } - GetExeAndArguments(useCmdShell, executable, arguments, out string finalExecutable, out string finalArguments); + GetExeAndArguments(useCmdShell, executable, arguments, out string? finalExecutable, out string? finalArguments); settings.Executable = finalExecutable; settings.Arguments = finalArguments; @@ -394,7 +394,7 @@ private async Task GetTargetCommandAsync( bool validateSettings) { // First try "RunCommand" property - string runCommand = await GetRunCommandAsync(properties); + string? runCommand = await GetRunCommandAsync(properties); if (string.IsNullOrEmpty(runCommand)) { @@ -412,7 +412,7 @@ private async Task GetTargetCommandAsync( } - private async Task GetRunCommandAsync(IProjectProperties properties) + private async Task GetRunCommandAsync(IProjectProperties properties) { string runCommand = await properties.GetEvaluatedPropertyValueAsync("RunCommand"); @@ -429,7 +429,7 @@ private async Task GetRunCommandAsync(IProjectProperties properties) // If the path is just the name of an exe like dotnet.exe then we try to find it on the path if (runCommand.IndexOf(Path.DirectorySeparatorChar) == -1) { - string executable = GetFullPathOfExeFromEnvironmentPath(runCommand); + string? executable = GetFullPathOfExeFromEnvironmentPath(runCommand); if (executable != null) { runCommand = executable; @@ -458,7 +458,7 @@ private static async Task GetDebuggingEngineAsync(ConfiguredProject config /// Searches the path variable for the first match of exeToSearchFor. Returns /// null if not found. /// - public string GetFullPathOfExeFromEnvironmentPath(string exeToSearchFor) + public string? GetFullPathOfExeFromEnvironmentPath(string exeToSearchFor) { string pathEnv = _environment.GetEnvironmentVariable("Path"); @@ -492,7 +492,7 @@ public string GetFullPathOfExeFromEnvironmentPath(string exeToSearchFor) /// The string to escape. /// The characters to escape in the string. /// The escaped string. - internal static string EscapeString(string unescaped, char[] toEscape) + internal static string? EscapeString(string? unescaped, char[] toEscape) { if (string.IsNullOrWhiteSpace(unescaped)) return unescaped; diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Debug/DebugProfileDebugTargetGenerator.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Debug/DebugProfileDebugTargetGenerator.cs index 4ace4840794..6a87c737461 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Debug/DebugProfileDebugTargetGenerator.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Debug/DebugProfileDebugTargetGenerator.cs @@ -25,13 +25,13 @@ namespace Microsoft.VisualStudio.ProjectSystem.VS.Debug [ExportMetadata("Name", "DebugProfileProvider")] internal class DebugProfileDebugTargetGenerator : ProjectValueDataSourceBase>, IDynamicEnumValuesProvider, IDynamicDebugTargetsGenerator { - private IReceivableSourceBlock>> _publicBlock; + private IReceivableSourceBlock>>? _publicBlock; // Represents the link to the launch profiles - private IDisposable _launchProfileProviderLink; + private IDisposable? _launchProfileProviderLink; // Represents the link to our source provider - private IDisposable _debugProviderLink; + private IDisposable? _debugProviderLink; [ImportingConstructor] public DebugProfileDebugTargetGenerator( @@ -63,7 +63,7 @@ public override IReceivableSourceBlock>(delegate { - ILaunchSettings curSnapshot = profileProvider.CurrentSnapshot; + ILaunchSettings? curSnapshot = profileProvider.CurrentSnapshot; if (curSnapshot != null) { return Task.FromResult(GetEnumeratorEnumValues(curSnapshot)); @@ -83,7 +83,7 @@ from profile in profiles.Profiles return result; } - private static string EscapeMnemonics(string text) + private static string? EscapeMnemonics(string? text) { return text?.Replace("&", "&&"); } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Debug/ErrorProfileDebugTargetsProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Debug/ErrorProfileDebugTargetsProvider.cs index 324580853f3..655889d4d57 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Debug/ErrorProfileDebugTargetsProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Debug/ErrorProfileDebugTargetsProvider.cs @@ -62,7 +62,9 @@ public Task OnAfterLaunchAsync(DebugLaunchOptions launchOptions, ILaunchProfile /// public Task> QueryDebugTargetsAsync(DebugLaunchOptions launchOptions, ILaunchProfile activeProfile) { - if (activeProfile.OtherSettings.TryGetValue("ErrorString", out object objErrorString) && objErrorString is string errorString) + if (activeProfile.OtherSettings != null && + activeProfile.OtherSettings.TryGetValue("ErrorString", out object objErrorString) && + objErrorString is string errorString) { throw new Exception(string.Format(VSResources.ErrorInProfilesFile2, Path.GetFileNameWithoutExtension(_configuredProject.UnconfiguredProject.FullPath), errorString)); } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Debug/ProjectDebuggerProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Debug/ProjectDebuggerProvider.cs index 2634b96547b..d9438fb44ca 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Debug/ProjectDebuggerProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Debug/ProjectDebuggerProvider.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.ComponentModel.Composition; using System.Linq; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Threading.Tasks; using Microsoft.VisualStudio.Buffers.PooledObjects; @@ -60,7 +61,7 @@ public ProjectDebuggerProvider(ConfiguredProject configuredProject, ILaunchSetti private ILaunchSettingsProvider LaunchSettingsProvider { get; } // Tracks the last launched provider so we can forward calls to IDeployedProjectItemMappingProvider - public IDebugProfileLaunchTargetsProvider LastLaunchProvider { get; private set; } + public IDebugProfileLaunchTargetsProvider? LastLaunchProvider { get; private set; } /// /// Called by CPS to determine whether we can launch @@ -114,8 +115,8 @@ private async Task> QueryDebugTargetsInterna { // Get the active debug profile (timeout of 5s, though in reality is should never take this long as even in error conditions // a snapshot is produced). - ILaunchSettings currentProfiles = await LaunchSettingsProvider.WaitForFirstSnapshot(5000); - ILaunchProfile activeProfile = currentProfiles?.ActiveProfile; + ILaunchSettings? currentProfiles = await LaunchSettingsProvider.WaitForFirstSnapshot(5000); + ILaunchProfile? activeProfile = currentProfiles?.ActiveProfile; // Should have a profile if (activeProfile == null) @@ -144,7 +145,7 @@ private async Task> QueryDebugTargetsInterna /// /// Returns the provider which knows how to launch the profile type. /// - public IDebugProfileLaunchTargetsProvider GetLaunchTargetsProvider(ILaunchProfile profile) + public IDebugProfileLaunchTargetsProvider? GetLaunchTargetsProvider(ILaunchProfile? profile) { // We search through the imports in order to find the one which supports the profile foreach (Lazy provider in ProfileLaunchTargetsProviders) @@ -165,9 +166,9 @@ public override async Task LaunchAsync(DebugLaunchOptions launchOptions) { IReadOnlyList targets = await QueryDebugTargetsInternalAsync(launchOptions, fromDebugLaunch: true); - ILaunchProfile activeProfile = LaunchSettingsProvider.ActiveProfile; + ILaunchProfile? activeProfile = LaunchSettingsProvider.ActiveProfile; - IDebugProfileLaunchTargetsProvider targetProfile = GetLaunchTargetsProvider(activeProfile); + IDebugProfileLaunchTargetsProvider? targetProfile = GetLaunchTargetsProvider(activeProfile); if (targetProfile != null) { await targetProfile.OnBeforeLaunchAsync(launchOptions, activeProfile); @@ -297,7 +298,7 @@ internal static void FreeVsDebugTargetInfoStruct(VsDebugTargetInfo4 nativeStruct /// Converts the environment key value pairs to a valid environment string of the form /// key=value/0key2=value2/0/0, with nulls between each entry and a double null terminator. /// - private static string GetSerializedEnvironmentString(IDictionary environment) + private static string? GetSerializedEnvironmentString(IDictionary environment) { // If no dictionary was set, or its empty, the debugger wants null for its environment block. if (environment == null || environment.Count == 0) @@ -346,7 +347,7 @@ private static byte[] GetGuidBytes(IList guids) /// IDeployedProjectItemMappingProvider /// Implemented so that we can map URL's back to local file item paths /// - public bool TryGetProjectItemPathFromDeployedPath(string deployedPath, out string localPath) + public bool TryGetProjectItemPathFromDeployedPath(string deployedPath, [NotNullWhenTrue]out string? localPath) { // Just delegate to the last provider. It needs to figure out how best to map the items localPath = null; diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Debug/StartupProjectRegistrar.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Debug/StartupProjectRegistrar.cs index 76d50fda715..a7d08422429 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Debug/StartupProjectRegistrar.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Debug/StartupProjectRegistrar.cs @@ -22,7 +22,7 @@ internal class StartupProjectRegistrar : OnceInitializedOnceDisposedAsync private readonly ActiveConfiguredProject _launchProviders; private Guid _projectGuid; - private IDisposable _subscription; + private IDisposable? _subscription; /// /// must be imported in the contructor in order for scope of this class' export to be correct. @@ -72,7 +72,7 @@ protected override Task DisposeCoreAsync(bool initialized) return Task.CompletedTask; } - internal async Task OnProjectChangedAsync(IProjectVersionedValue e = null) + internal async Task OnProjectChangedAsync(IProjectVersionedValue? e = null) { bool isDebuggable = await _launchProviders.Value.IsDebuggableAsync(); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/DotNetCoreProjectCompatibilityDetector.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/DotNetCoreProjectCompatibilityDetector.cs index f0bf956cf48..24159086484 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/DotNetCoreProjectCompatibilityDetector.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/DotNetCoreProjectCompatibilityDetector.cs @@ -81,8 +81,8 @@ public DotNetCoreProjectCompatibilityDetector(Lazy proj private readonly IVsService _vsAppIdService; private readonly IVsService _vsShellService; - private RemoteCacheFile _versionDataCacheFile; - private Version _ourVSVersion; + private RemoteCacheFile? _versionDataCacheFile; + private Version? _ourVSVersion; private uint _solutionCookie = VSConstants.VSCOOKIE_NIL; private bool _solutionOpened; @@ -90,15 +90,15 @@ public DotNetCoreProjectCompatibilityDetector(Lazy proj // Tracks how often we meed to look for new data private DateTime _timeCurVersionDataLastUpdatedUtc = DateTime.MinValue; - private VersionCompatibilityData _curVersionCompatibilityData; - private IVsSolution _vsSolution; + private VersionCompatibilityData? _curVersionCompatibilityData; + private IVsSolution? _vsSolution; public async Task InitializeAsync() { await _threadHandling.Value.SwitchToUIThread(); // Initialize our cache file - string appDataFolder = await _shellUtilitiesHelper.Value.GetLocalAppDataFolderAsync(_vsShellService); + string? appDataFolder = await _shellUtilitiesHelper.Value.GetLocalAppDataFolderAsync(_vsShellService); if (appDataFolder != null) { _versionDataCacheFile = new RemoteCacheFile(Path.Combine(appDataFolder, VersionDataFilename), VersionCompatibilityDownloadFwlink, @@ -376,7 +376,7 @@ private VersionCompatibilityData GetVersionCompatibilityData() try { // Try the cache file - Dictionary versionCompatData = GetCompabilityDataFromCacheFile(); + Dictionary? versionCompatData = GetCompabilityDataFromCacheFile(); // See if the cache file needs refreshing and if so, kick off a task to do so if (_versionDataCacheFile != null && _versionDataCacheFile.CacheFileIsStale()) @@ -390,8 +390,11 @@ private VersionCompatibilityData GetVersionCompatibilityData() if (versionCompatData != null) { + // This is never null after InitializeAsync (which is called during package load) + Version ourVSVersion = _ourVSVersion!; + // First try to match exactly on our VS version and if that fails, match on just major, minor - if (versionCompatData.TryGetValue(_ourVSVersion, out VersionCompatibilityData compatData) || versionCompatData.TryGetValue(new Version(_ourVSVersion.Major, _ourVSVersion.Minor), out compatData)) + if (versionCompatData.TryGetValue(ourVSVersion, out VersionCompatibilityData compatData) || versionCompatData.TryGetValue(new Version(ourVSVersion.Major, ourVSVersion.Minor), out compatData)) { // Now fix up missing data if (string.IsNullOrEmpty(compatData.OpenSupportedMessage)) @@ -423,7 +426,7 @@ private VersionCompatibilityData GetVersionCompatibilityData() }); } - return _curVersionCompatibilityData; + return _curVersionCompatibilityData!; } private void UpdateInMemoryCachedData(VersionCompatibilityData newData) @@ -435,11 +438,11 @@ private void UpdateInMemoryCachedData(VersionCompatibilityData newData) /// /// If the cached file exists reads the data and returns it /// - private Dictionary GetCompabilityDataFromCacheFile() + private Dictionary? GetCompabilityDataFromCacheFile() { try { - string data = _versionDataCacheFile?.ReadCacheFile(); + string? data = _versionDataCacheFile?.ReadCacheFile(); if (data != null) { return VersionCompatibilityData.DeserializeVersionData(data); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/EditAndContinue/EditAndContinueProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/EditAndContinue/EditAndContinueProvider.cs index 5bcba489385..0c380eb9324 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/EditAndContinue/EditAndContinueProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/EditAndContinue/EditAndContinueProvider.cs @@ -19,8 +19,8 @@ namespace Microsoft.VisualStudio.ProjectSystem.VS.EditAndContinue [AppliesTo(ProjectCapability.EditAndContinue)] internal class EditAndContinueProvider : IVsENCRebuildableProjectCfg, IVsENCRebuildableProjectCfg2, IVsENCRebuildableProjectCfg4, IDisposable { - private ILanguageServiceHost _host; - private IProjectThreadingService _threadingService; + private ILanguageServiceHost? _host; + private IProjectThreadingService? _threadingService; [ImportingConstructor] public EditAndContinueProvider(ILanguageServiceHost host, IProjectThreadingService threadingService) @@ -116,11 +116,14 @@ public int HasCustomMetadataEmitter(out bool value) private int Invoke(Func action) { + if (_threadingService == null) + throw new ObjectDisposedException(nameof(EditAndContinueProvider)); + return _threadingService.ExecuteSynchronously(async () => { await _threadingService.SwitchToUIThread(); - var encProvider = (IVsENCRebuildableProjectCfg2)_host?.HostSpecificEditAndContinueService; + var encProvider = (IVsENCRebuildableProjectCfg2?)_host?.HostSpecificEditAndContinueService; if (encProvider != null) { return action(encProvider); @@ -140,7 +143,7 @@ public void Dispose() // NOTE: Managed ENC always calls through IVsENCRebuildableProjectCfg2/IVsENCRebuildableProjectCfg4. // We implement IVsENCRebuildableProjectCfg as this used to sniff the project for EnC support. - int IVsENCRebuildableProjectCfg.ENCRebuild(object in_pProgram, out object out_ppSnapshot) + int IVsENCRebuildableProjectCfg.ENCRebuild(object in_pProgram, out object? out_ppSnapshot) { out_ppSnapshot = null; return HResult.NotImplemented; diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Imaging/AppDesignerFolderProjectImageProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Imaging/AppDesignerFolderProjectImageProvider.cs index 5a2bc9ec46c..9022650d1ac 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Imaging/AppDesignerFolderProjectImageProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Imaging/AppDesignerFolderProjectImageProvider.cs @@ -19,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.VS/ProjectSystem/VS/Input/Commands/AbstractGenerateNuGetPackageCommand.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Input/Commands/AbstractGenerateNuGetPackageCommand.cs index bc6639a3bbe..67550a097c3 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Input/Commands/AbstractGenerateNuGetPackageCommand.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Input/Commands/AbstractGenerateNuGetPackageCommand.cs @@ -16,7 +16,7 @@ internal abstract class AbstractGenerateNuGetPackageCommand : AbstractSingleNode private readonly IProjectThreadingService _threadingService; private readonly IVsService _vsSolutionBuildManagerService; private readonly GeneratePackageOnBuildPropertyProvider _generatePackageOnBuildPropertyProvider; - private IVsSolutionBuildManager2 _buildManager; + private IVsSolutionBuildManager2? _buildManager; private uint _solutionEventsCookie; protected AbstractGenerateNuGetPackageCommand( @@ -58,7 +58,7 @@ private async Task IsReadyToBuildAsync() // Ensure build manager is initialized. await EnsureBuildManagerInitializedAsync(); - ErrorHandler.ThrowOnFailure(_buildManager.QueryBuildManagerBusy(out int busy)); + ErrorHandler.ThrowOnFailure(_buildManager!.QueryBuildManagerBusy(out int busy)); return busy == 0; } @@ -90,14 +90,14 @@ protected override async Task TryHandleCommandAsync(IProjectTree node, boo // Save documents before build. var projectVsHierarchy = (IVsHierarchy)Project.Services.HostObject; - ErrorHandler.ThrowOnFailure(_buildManager.SaveDocumentsBeforeBuild(projectVsHierarchy, (uint)VSConstants.VSITEMID.Root, 0 /*docCookie*/)); + ErrorHandler.ThrowOnFailure(_buildManager!.SaveDocumentsBeforeBuild(projectVsHierarchy, (uint)VSConstants.VSITEMID.Root, 0 /*docCookie*/)); // Enable generating package on build ("GeneratePackageOnBuild") for all projects being built. _generatePackageOnBuildPropertyProvider.OverrideGeneratePackageOnBuild(true); // Kick off the build. uint dwFlags = (uint)(VSSOLNBUILDUPDATEFLAGS.SBF_SUPPRESS_SAVEBEFOREBUILD_QUERY | VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_BUILD); - ErrorHandler.ThrowOnFailure(_buildManager.StartSimpleUpdateProjectConfiguration(projectVsHierarchy, null, null, dwFlags, 0, 0)); + ErrorHandler.ThrowOnFailure(_buildManager!.StartSimpleUpdateProjectConfiguration(projectVsHierarchy, null, null, dwFlags, 0, 0)); } return true; @@ -148,9 +148,11 @@ protected virtual void Dispose(bool disposing) if (_buildManager != null) { +#pragma warning disable CS8602 // Workaround https://github.com/dotnet/roslyn/issues/31620 // Unregister solution build events. _buildManager.UnadviseUpdateSolutionEvents(_solutionEventsCookie); _buildManager = null; +#pragma warning restore CS8602 } }); } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Input/Commands/DebugFrameworksDynamicMenuCommand.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Input/Commands/DebugFrameworksDynamicMenuCommand.cs index ed25c0cd713..d1df76c920f 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Input/Commands/DebugFrameworksDynamicMenuCommand.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Input/Commands/DebugFrameworksDynamicMenuCommand.cs @@ -46,7 +46,7 @@ public override bool ExecCommand(int cmdIndex, EventArgs e) { foreach (IActiveDebugFrameworkServices activeDebugFramework in activeDebugFrameworks) { - List frameworks = await activeDebugFramework.GetProjectFrameworksAsync(); + List? frameworks = await activeDebugFramework.GetProjectFrameworksAsync(); if (frameworks != null && cmdIndex >= 0 && cmdIndex < frameworks.Count) { await activeDebugFramework.SetActiveDebuggingFrameworkPropertyAsync(frameworks[cmdIndex]); @@ -69,11 +69,11 @@ public override bool QueryStatusCommand(int cmdIndex, EventArgs e) if (activeDebugFrameworks.Length > 0) { // See if the projects support at least two runtimes - List frameworks = null; - string activeFramework = null; + List? frameworks = null; + string? activeFramework = null; ExecuteSynchronously(async () => { - List first = null; + List? first = null; foreach (IActiveDebugFrameworkServices activeDebugFramework in activeDebugFrameworks) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Input/Commands/DebugFrameworksMenuTextUpdater.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Input/Commands/DebugFrameworksMenuTextUpdater.cs index f19df86addf..aabfb20ea8c 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Input/Commands/DebugFrameworksMenuTextUpdater.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Input/Commands/DebugFrameworksMenuTextUpdater.cs @@ -63,11 +63,11 @@ public void QueryStatus() ImmutableArray activeDebugFrameworks = StartupProjectHelper.GetExportFromDotNetStartupProjects(ProjectCapability.LaunchProfiles); if (activeDebugFrameworks.Length > 0) { - string activeFramework = null; - List frameworks = null; + string? activeFramework = null; + List? frameworks = null; ExecuteSynchronously(async () => { - List first = null; + List? first = null; foreach (IActiveDebugFrameworkServices activeDebugFramework in activeDebugFrameworks) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Input/Commands/Ordering/NodeHelper.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Input/Commands/Ordering/NodeHelper.cs index 1833005102d..e73d0b995a1 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Input/Commands/Ordering/NodeHelper.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Input/Commands/Ordering/NodeHelper.cs @@ -37,15 +37,15 @@ private static void Select(ConfiguredProject configuredProject, IServiceProvider UseWindow(configuredProject, serviceProvider, (hierarchy, window) => { // We need to unselect the item if it is already selected to re-select it correctly. - window.ExpandItem(hierarchy, itemId, EXPANDFLAGS.EXPF_UnSelectItem); - window.ExpandItem(hierarchy, itemId, EXPANDFLAGS.EXPF_SelectItem); + window?.ExpandItem(hierarchy, itemId, EXPANDFLAGS.EXPF_UnSelectItem); + window?.ExpandItem(hierarchy, itemId, EXPANDFLAGS.EXPF_SelectItem); }); } /// /// Callbacks with a hierarchy and hierarchy window for use. /// - private static void UseWindow(ConfiguredProject configuredProject, IServiceProvider serviceProvider, Action callback) + private static void UseWindow(ConfiguredProject configuredProject, IServiceProvider serviceProvider, Action callback) { var hierarchy = (IVsUIHierarchy)configuredProject.UnconfiguredProject.Services.HostObject; callback(hierarchy, GetUIHierarchyWindow(serviceProvider, VSConstants.StandardToolWindows.SolutionExplorer)); @@ -59,7 +59,7 @@ private static void UseWindow(ConfiguredProject configuredProject, IServiceProvi /// The caller of this method can use predefined identifiers that map to tool windows if those tool windows /// are known to the caller. /// A reference to an IVsUIHierarchyWindow interface, or null if the window isn't available, such as command line mode. - private static IVsUIHierarchyWindow GetUIHierarchyWindow(IServiceProvider serviceProvider, Guid persistenceSlot) + private static IVsUIHierarchyWindow? GetUIHierarchyWindow(IServiceProvider serviceProvider, Guid persistenceSlot) { Requires.NotNull(serviceProvider, nameof(serviceProvider)); @@ -71,8 +71,8 @@ private static IVsUIHierarchyWindow GetUIHierarchyWindow(IServiceProvider servic IVsUIShell shell = serviceProvider.GetService(); - object pvar = null; - IVsUIHierarchyWindow uiHierarchyWindow = null; + object? pvar = null; + IVsUIHierarchyWindow? uiHierarchyWindow = null; try { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Input/Commands/Ordering/OrderAddItemHintReceiver.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Input/Commands/Ordering/OrderAddItemHintReceiver.cs index 3f788934ad3..1c8fd195a24 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Input/Commands/Ordering/OrderAddItemHintReceiver.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Input/Commands/Ordering/OrderAddItemHintReceiver.cs @@ -18,7 +18,7 @@ internal class OrderAddItemHintReceiver : IProjectChangeHintReceiver private ImmutableHashSet _previousIncludes = ImmutableHashSet.Empty; private OrderingMoveAction _action = OrderingMoveAction.NoOp; - private IProjectTree _target = null; + private IProjectTree? _target = null; private bool _isHinting = false; [ImportingConstructor] @@ -35,7 +35,9 @@ public async Task HintedAsync(IImmutableDictionary> GetAllEvaluatedIncludes(ConfiguredP /// /// Checks to see if the project tree has a valid display order. /// - public static bool HasValidDisplayOrder(IProjectTree projectTree) + public static bool HasValidDisplayOrder(IProjectTree? projectTree) { return IsValidDisplayOrder(GetDisplayOrder(projectTree)); } @@ -73,7 +73,7 @@ public static bool HasValidDisplayOrder(IProjectTree projectTree) /// /// Gets the display order for a project tree. /// - public static int GetDisplayOrder(IProjectTree projectTree) + public static int GetDisplayOrder(IProjectTree? projectTree) { if (projectTree is IProjectTree2 projectTree2) { @@ -133,7 +133,7 @@ public static bool TryMoveElementsAbove(Project project, ImmutableArray.Empty, MoveAction.Above); + ProjectItemElement? referenceElement = TryGetReferenceElement(project, target, ImmutableArray.Empty, MoveAction.Above); if (referenceElement == null) { return false; @@ -150,7 +150,7 @@ public static bool TryMoveElementsBelow(Project project, ImmutableArray.Empty, MoveAction.Below); + ProjectItemElement? referenceElement = TryGetReferenceElement(project, target, ImmutableArray.Empty, MoveAction.Below); if (referenceElement == null) { return false; @@ -177,7 +177,7 @@ public static bool TryMoveElementsToTop(Project project, ImmutableArray x.Include).ToImmutableArray(); - ProjectItemElement referenceElement = GetChildren(newTarget).Select(x => TryGetReferenceElement(project, x, excludeIncludes, MoveAction.Above)).FirstOrDefault(x => x != null); + ProjectItemElement? referenceElement = GetChildren(newTarget).Select(x => TryGetReferenceElement(project, x, excludeIncludes, MoveAction.Above)).FirstOrDefault(x => x != null); if (referenceElement == null) { return false; @@ -288,7 +288,7 @@ private static ImmutableArray GetChildren(IProjectTree projectTree /// the given project tree /// passes the index of the given project tree from the given ordered sequence, expecting to return a sibling /// a sibling - private static IProjectTree2 GetSiblingByDisplayOrder(IProjectTree projectTree, Func, IProjectTree2> returnSibling) + private static IProjectTree2? GetSiblingByDisplayOrder(IProjectTree projectTree, Func, IProjectTree2?> returnSibling) { IProjectTree parent = projectTree.Parent; int displayOrder = GetDisplayOrder(projectTree); @@ -314,7 +314,7 @@ private static IProjectTree2 GetSiblingByDisplayOrder(IProjectTree projectTree, /// /// Gets the previous sibling of the given project tree, if there is any. Can return null. /// - private static IProjectTree2 GetPreviousSibling(IProjectTree projectTree) + private static IProjectTree2? GetPreviousSibling(IProjectTree projectTree) { return GetSiblingByDisplayOrder(projectTree, (i, orderedChildren) => { @@ -330,7 +330,7 @@ private static IProjectTree2 GetPreviousSibling(IProjectTree projectTree) /// /// Gets the next sibling of the given project tree, if there is any. Can return null. /// - private static IProjectTree2 GetNextSibling(IProjectTree projectTree) + private static IProjectTree2? GetNextSibling(IProjectTree projectTree) { return GetSiblingByDisplayOrder(projectTree, (i, orderedChildren) => { @@ -346,7 +346,7 @@ private static IProjectTree2 GetNextSibling(IProjectTree projectTree) /// /// Gets a sibling of the given project tree based on the move action. Can return null. /// - private static IProjectTree GetSiblingByMoveAction(IProjectTree projectTree, MoveAction moveAction) + private static IProjectTree? GetSiblingByMoveAction(IProjectTree projectTree, MoveAction moveAction) { switch (moveAction) { @@ -364,7 +364,7 @@ private static IProjectTree GetSiblingByMoveAction(IProjectTree projectTree, Mov /// Gets a reference element based on the given project tree and move action. Can return null. /// The reference element is the element for which moved items will be above or below it. /// - private static ProjectItemElement TryGetReferenceElement(Project project, IProjectTree projectTree, ImmutableArray excludeIncludes, MoveAction moveAction) + private static ProjectItemElement? TryGetReferenceElement(Project project, IProjectTree projectTree, ImmutableArray excludeIncludes, MoveAction moveAction) { switch (moveAction) { @@ -444,7 +444,7 @@ private static bool TryMoveElements(ImmutableArray elements, /// Move project elements based on the given project tree, reference project tree and move action. /// Will modify the project if successful, but not save; only dirty. /// - private static bool TryMove(Project project, IProjectTree projectTree, IProjectTree referenceProjectTree, MoveAction moveAction) + private static bool TryMove(Project project, IProjectTree projectTree, IProjectTree? referenceProjectTree, MoveAction moveAction) { if (!HasValidDisplayOrder(projectTree) || !HasValidDisplayOrder(referenceProjectTree)) { @@ -459,7 +459,7 @@ private static bool TryMove(Project project, IProjectTree projectTree, IProjectT if (referenceProjectTree != null) { // The reference element is the element for which moved items will be above or below it. - ProjectItemElement referenceElement = TryGetReferenceElement(project, referenceProjectTree, ImmutableArray.Empty, moveAction); + ProjectItemElement? referenceElement = TryGetReferenceElement(project, referenceProjectTree, ImmutableArray.Empty, moveAction); if (referenceElement != null) { @@ -478,7 +478,7 @@ private static bool TryMove(Project project, IProjectTree projectTree, IProjectT private static bool TryMove(Project project, IProjectTree projectTree, MoveAction moveAction) { // Determine what sibling we want to look at based on if we are moving up or down. - IProjectTree sibling = GetSiblingByMoveAction(projectTree, moveAction); + IProjectTree? sibling = GetSiblingByMoveAction(projectTree, moveAction); return TryMove(project, projectTree, sibling, moveAction); } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Input/Commands/Ordering/PasteOrdering.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Input/Commands/Ordering/PasteOrdering.cs index 42f3f4d81dc..65175793fe8 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Input/Commands/Ordering/PasteOrdering.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Input/Commands/Ordering/PasteOrdering.cs @@ -21,7 +21,7 @@ internal class PasteOrdering : IPasteHandler, IPasteDataObjectProcessor private readonly ConfiguredProject _configuredProject; private readonly IProjectAccessor _accessor; - private IProjectTree _dropTarget; + private IProjectTree? _dropTarget; [ImportingConstructor] public PasteOrdering(UnconfiguredProject unconfiguredProject, IProjectAccessor accessor) @@ -104,7 +104,7 @@ public async Task PasteItemsAsync(IEnumerable ImmutableHashSet previousIncludes = await OrderingHelper.GetAllEvaluatedIncludes(_configuredProject, _accessor); PasteItemsResult result = await PasteHandler.PasteItemsAsync(items, effect); - await OrderingHelper.Move(_configuredProject, _accessor, previousIncludes, _dropTarget, OrderingMoveAction.MoveToTop); + await OrderingHelper.Move(_configuredProject, _accessor, previousIncludes, _dropTarget!, OrderingMoveAction.MoveToTop); return result; } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/LanguageServices/AbstractHostObject.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/LanguageServices/AbstractHostObject.cs index 97bb35145c7..999b29ae186 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/LanguageServices/AbstractHostObject.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/LanguageServices/AbstractHostObject.cs @@ -26,7 +26,7 @@ protected AbstractHostObject(IVsHierarchy innerHierarchy, IVsProject4 innerVsPro protected IVsHierarchy InnerHierarchy { get; } protected IVsProject4 InnerVsProject { get; } - public abstract string ActiveWorkspaceProjectContextId { get; } + public abstract string? ActiveWorkspaceProjectContextId { get; } #region IVsHierarchy members @@ -55,7 +55,7 @@ public virtual int GetNestedHierarchy(uint itemid, ref Guid iidHierarchyNested, return InnerHierarchy.GetNestedHierarchy(itemid, ref iidHierarchyNested, out ppHierarchyNested, out pitemidNested); } - public virtual int GetProperty(uint itemid, int propid, out object pvar) + public virtual int GetProperty(uint itemid, int propid, out object? pvar) { return InnerHierarchy.GetProperty(itemid, propid, out pvar); } @@ -124,7 +124,7 @@ public virtual int Unused4() #region IVsContainedLanguageProjectNameProvider members - public int GetProjectName(uint itemid, out string pbstrProjectName) + public int GetProjectName(uint itemid, out string? pbstrProjectName) { pbstrProjectName = ActiveWorkspaceProjectContextId; return VSConstants.S_OK; diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/LanguageServices/ActiveWorkspaceProjectContextTracker.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/LanguageServices/ActiveWorkspaceProjectContextTracker.cs index b02f2977576..3872f1fa14b 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/LanguageServices/ActiveWorkspaceProjectContextTracker.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/LanguageServices/ActiveWorkspaceProjectContextTracker.cs @@ -29,13 +29,13 @@ public ActiveWorkspaceProjectContextTracker(UnconfiguredProject project) // For { } - public string ActiveIntellisenseProjectContext + public string? ActiveIntellisenseProjectContext { get; set; } - public int GetProjectName(uint itemid, out string pbstrProjectName) + public int GetProjectName(uint itemid, out string? pbstrProjectName) { if (itemid == HierarchyId.Nil || itemid == HierarchyId.Selection || itemid == HierarchyId.Empty) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/LanguageServices/ConfiguredProjectHostObject.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/LanguageServices/ConfiguredProjectHostObject.cs index 9993533428e..52e86bd3baa 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/LanguageServices/ConfiguredProjectHostObject.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/LanguageServices/ConfiguredProjectHostObject.cs @@ -27,11 +27,11 @@ public ConfiguredProjectHostObject(UnconfiguredProjectHostObject unconfiguredPro } public string WorkspaceProjectContextId => _workspaceProjectContextId; - public override string ActiveWorkspaceProjectContextId => _unconfiguredProjectHostObject.ActiveWorkspaceProjectContextId; + public override string? ActiveWorkspaceProjectContextId => _unconfiguredProjectHostObject.ActiveWorkspaceProjectContextId; #region IVsHierarchy overrides - public override int GetProperty(uint itemid, int propid, out object pvar) + public override int GetProperty(uint itemid, int propid, out object? pvar) { switch (propid) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/LanguageServices/ProjectContextCodeModelProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/LanguageServices/ProjectContextCodeModelProvider.cs index b71f1cb20c5..124793b7c91 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/LanguageServices/ProjectContextCodeModelProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/LanguageServices/ProjectContextCodeModelProvider.cs @@ -30,11 +30,11 @@ public ProjectContextCodeModelProvider(IProjectThreadingService threadingService _languageServiceHost = languageServiceHost; } - public CodeModel GetCodeModel(Project project) + public CodeModel? GetCodeModel(Project project) { Requires.NotNull(project, nameof(project)); - IWorkspaceProjectContext projectContext = _languageServiceHost.ActiveProjectContext; + IWorkspaceProjectContext? projectContext = _languageServiceHost.ActiveProjectContext; if (projectContext == null) return null; @@ -46,11 +46,11 @@ public CodeModel GetCodeModel(Project project) }); } - public FileCodeModel GetFileCodeModel(ProjectItem fileItem) + public FileCodeModel? GetFileCodeModel(ProjectItem fileItem) { Requires.NotNull(fileItem, nameof(fileItem)); - IWorkspaceProjectContext projectContext = _languageServiceHost.ActiveProjectContext; + IWorkspaceProjectContext? projectContext = _languageServiceHost.ActiveProjectContext; if (projectContext == null) return null; diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/LanguageServices/UnconfiguredProjectHostObject.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/LanguageServices/UnconfiguredProjectHostObject.cs index 59735b88a9c..ca61b3226d3 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/LanguageServices/UnconfiguredProjectHostObject.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/LanguageServices/UnconfiguredProjectHostObject.cs @@ -20,8 +20,8 @@ public UnconfiguredProjectHostObject(IUnconfiguredProjectVsServices projectVsSer { } - public IConfiguredProjectHostObject ActiveIntellisenseProjectHostObject { get; set; } - public override string ActiveWorkspaceProjectContextId => ActiveIntellisenseProjectHostObject?.WorkspaceProjectContextId; + public IConfiguredProjectHostObject? ActiveIntellisenseProjectHostObject { get; set; } + public override string? ActiveWorkspaceProjectContextId => ActiveIntellisenseProjectHostObject?.WorkspaceProjectContextId; public bool DisposingConfiguredProjectHostObjects { get; set; } public void PushPendingIntellisenseProjectHostObjectUpdates() @@ -49,7 +49,7 @@ public override int AdviseHierarchyEvents(IVsHierarchyEvents pEventSink, out uin return hr; } - public override int GetProperty(uint itemid, int propid, out object pvar) + public override int GetProperty(uint itemid, int propid, out object? pvar) { if (ActiveIntellisenseProjectHostObject != null) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/LanguageServices/VsContainedLanguageComponentsFactory.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/LanguageServices/VsContainedLanguageComponentsFactory.cs index e10686710c3..2a8de447664 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/LanguageServices/VsContainedLanguageComponentsFactory.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/LanguageServices/VsContainedLanguageComponentsFactory.cs @@ -23,7 +23,7 @@ internal class VsContainedLanguageComponentsFactory : IVsContainedLanguageCompon private readonly IUnconfiguredProjectVsServices _projectVsServices; private readonly IProjectHostProvider _projectHostProvider; private readonly ILanguageServiceHost _languageServiceHost; - private readonly AsyncLazy _containedLanguageFactory; + private readonly AsyncLazy _containedLanguageFactory; [ImportingConstructor] public VsContainedLanguageComponentsFactory(IVsService serviceProvider, @@ -36,7 +36,7 @@ public VsContainedLanguageComponentsFactory(IVsService(GetContainedLanguageFactoryAsync, projectVsServices.ThreadingService.JoinableTaskFactory); + _containedLanguageFactory = new AsyncLazy(GetContainedLanguageFactoryAsync, projectVsServices.ThreadingService.JoinableTaskFactory); } public int GetContainedLanguageFactoryForFile(string filePath, @@ -52,7 +52,7 @@ public int GetContainedLanguageFactoryForFile(string filePath, return (hierarchy == null || containedLanguageFactory == null) ? HResult.Fail : HResult.OK; } - private async Task<(HierarchyId itemid, IVsHierarchy hierarchy, IVsContainedLanguageFactory containedLanguageFactory)> GetContainedLanguageFactoryForFileAsync(string filePath) + private async Task<(HierarchyId itemid, IVsHierarchy? hierarchy, IVsContainedLanguageFactory? containedLanguageFactory)> GetContainedLanguageFactoryForFileAsync(string filePath) { await _languageServiceHost.InitializeAsync(); @@ -65,19 +65,19 @@ public int GetContainedLanguageFactoryForFile(string filePath, Assumes.False(itemid == HierarchyId.Nil); - IVsContainedLanguageFactory containedLanguageFactory = await _containedLanguageFactory.GetValueAsync(); + IVsContainedLanguageFactory? containedLanguageFactory = await _containedLanguageFactory.GetValueAsync(); if (containedLanguageFactory == null) return (HierarchyId.Nil, null, null); - var hierarchy = (IVsHierarchy)_projectHostProvider.UnconfiguredProjectHostObject.ActiveIntellisenseProjectHostObject; + var hierarchy = (IVsHierarchy?)_projectHostProvider.UnconfiguredProjectHostObject.ActiveIntellisenseProjectHostObject; if (hierarchy == null) return (HierarchyId.Nil, null, null); return (itemid, hierarchy, containedLanguageFactory); } - private async Task GetContainedLanguageFactoryAsync() + private async Task GetContainedLanguageFactoryAsync() { Guid languageServiceId = await GetLanguageServiceId(); if (languageServiceId == Guid.Empty) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Logging/IProjectOutputWindowPaneProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Logging/IProjectOutputWindowPaneProvider.cs index b8814b28644..17b8c38c9ed 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Logging/IProjectOutputWindowPaneProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Logging/IProjectOutputWindowPaneProvider.cs @@ -18,6 +18,6 @@ internal interface IProjectOutputWindowPaneProvider /// The project object, or /// if the service is not present. /// - Task GetOutputWindowPaneAsync(); + Task GetOutputWindowPaneAsync(); } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Logging/ProjectOutputWindowPaneProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Logging/ProjectOutputWindowPaneProvider.cs index 400a95af00a..c4fda910465 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Logging/ProjectOutputWindowPaneProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Logging/ProjectOutputWindowPaneProvider.cs @@ -16,22 +16,22 @@ internal class ProjectOutputWindowPaneProvider : IProjectOutputWindowPaneProvide private readonly IProjectThreadingService _threadingService; private readonly IVsUIService _outputWindow; - private readonly AsyncLazy _outputWindowPane; + private readonly AsyncLazy _outputWindowPane; [ImportingConstructor] public ProjectOutputWindowPaneProvider(IProjectThreadingService threadingService, IVsUIService outputWindow) { _threadingService = threadingService; _outputWindow = outputWindow; - _outputWindowPane = new AsyncLazy(CreateOutputWindowPaneAsync, threadingService.JoinableTaskFactory); + _outputWindowPane = new AsyncLazy(CreateOutputWindowPaneAsync, threadingService.JoinableTaskFactory); } - public Task GetOutputWindowPaneAsync() + public Task GetOutputWindowPaneAsync() { return _outputWindowPane.GetValueAsync(); } - private async Task CreateOutputWindowPaneAsync() + private async Task CreateOutputWindowPaneAsync() { await _threadingService.SwitchToUIThread(); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/PackageRestoreInitiator.PackageRestoreInitiatorInstance.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/PackageRestoreInitiator.PackageRestoreInitiatorInstance.cs index f4b2a249fdc..e98f6c4a420 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/PackageRestoreInitiator.PackageRestoreInitiatorInstance.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/PackageRestoreInitiator.PackageRestoreInitiatorInstance.cs @@ -28,8 +28,8 @@ private class PackageRestoreInitiatorInstance : OnceInitializedOnceDisposedAsync private readonly IVsSolutionRestoreService _solutionRestoreService; private readonly IActiveConfigurationGroupService _activeConfigurationGroupService; private readonly IProjectLogger _logger; - private IDisposable _configurationsSubscription; - private DisposableBag _designTimeBuildSubscriptionLink; + private IDisposable? _configurationsSubscription; + private DisposableBag? _designTimeBuildSubscriptionLink; private static readonly ImmutableHashSet s_designTimeBuildWatchedRules = Empty.OrdinalIgnoreCaseStringSet .Add(NuGetRestore.SchemaName) @@ -126,7 +126,7 @@ private static IPropagatorBlock, TIdentityDictionary> sources) { - var capabilitiesSnapshot = sources.Item1[0] as IProjectVersionedValue; + var capabilitiesSnapshot = (IProjectVersionedValue)sources.Item1[0]; using (ProjectCapabilitiesContext.CreateIsolatedContext(_projectVsServices.Project, capabilitiesSnapshot.Value)) { NominateProject(sources.Item1.RemoveAt(0)); @@ -135,7 +135,7 @@ private void ProjectPropertyChanged(Tuple, private void NominateProject(ImmutableList sources) { - IVsProjectRestoreInfo projectRestoreInfo = ProjectRestoreInfoBuilder.Build(sources, _projectVsServices.Project); + IVsProjectRestoreInfo? projectRestoreInfo = ProjectRestoreInfoBuilder.Build(sources, _projectVsServices.Project); if (projectRestoreInfo != null) { @@ -172,8 +172,8 @@ private void LogProjectRestoreInfo(string fullPath, IVsProjectRestoreInfo projec logger.WriteLine($"BaseIntermediatePath: {projectRestoreInfo.BaseIntermediatePath}"); logger.WriteLine($"OriginalTargetFrameworks: {projectRestoreInfo.OriginalTargetFrameworks}"); - LogTargetFrameworks(logger, projectRestoreInfo.TargetFrameworks as TargetFrameworks); - LogReferenceItems(logger, "Tool References", projectRestoreInfo.ToolReferences as ReferenceItems); + LogTargetFrameworks(logger, (TargetFrameworks)projectRestoreInfo.TargetFrameworks); + LogReferenceItems(logger, "Tool References", (ReferenceItems)projectRestoreInfo.ToolReferences); logger.IndentLevel--; logger.WriteLine(); @@ -202,7 +202,7 @@ private static void LogTargetFrameworks(IProjectLoggerBatch logger, TargetFramew foreach (IVsTargetFrameworkInfo tf in targetFrameworks) { - LogTargetFramework(logger, tf as TargetFrameworkInfo); + LogTargetFramework(logger, (TargetFrameworkInfo)tf); } logger.IndentLevel--; } @@ -212,9 +212,9 @@ private static void LogTargetFramework(IProjectLoggerBatch logger, TargetFramewo logger.WriteLine(targetFrameworkInfo.TargetFrameworkMoniker); logger.IndentLevel++; - LogReferenceItems(logger, "Project References", targetFrameworkInfo.ProjectReferences as ReferenceItems); - LogReferenceItems(logger, "Package References", targetFrameworkInfo.PackageReferences as ReferenceItems); - LogProperties(logger, "Target Framework Properties", targetFrameworkInfo.Properties as ProjectProperties); + LogReferenceItems(logger, "Project References", (ReferenceItems)targetFrameworkInfo.ProjectReferences); + LogReferenceItems(logger, "Package References", (ReferenceItems)targetFrameworkInfo.PackageReferences); + LogProperties(logger, "Target Framework Properties", (ProjectProperties)targetFrameworkInfo.Properties); logger.IndentLevel--; } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/ProjectAssetFileWatcher.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/ProjectAssetFileWatcher.cs index bf4eb125bcd..0a3da0d6879 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/ProjectAssetFileWatcher.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/ProjectAssetFileWatcher.cs @@ -37,7 +37,7 @@ internal class ProjectAssetFileWatcher : OnceInitializedOnceDisposedAsync, IVsFr private IDisposable _treeWatcher; private uint _filechangeCookie; private string _fileBeingWatched; - private byte[] _previousContentsHash; + private byte[]? _previousContentsHash; [ImportingConstructor] public ProjectAssetFileWatcher( @@ -95,7 +95,7 @@ internal async Task DataFlow_ChangedAsync(IProjectVersionedValue items. - string objDirectory = projectUpdate.CurrentState.GetPropertyOrDefault(ConfigurationGeneral.SchemaName, ConfigurationGeneral.BaseIntermediateOutputPathProperty, null); + string? objDirectory = projectUpdate.CurrentState.GetPropertyOrDefault(ConfigurationGeneral.SchemaName, ConfigurationGeneral.BaseIntermediateOutputPathProperty, null); if (string.IsNullOrEmpty(objDirectory)) { @@ -190,7 +190,7 @@ private static string GetProjectAssetsFilePath(IProjectTree newTree, IProjectSub return projectAssetsFilePath; } - private static IProjectTree FindProjectJsonNode(IProjectTree newTree, string projectFilePath) + private static IProjectTree? FindProjectJsonNode(IProjectTree newTree, string projectFilePath) { if (newTree.TryFindImmediateChild("project.json", out IProjectTree projectJsonNode)) { @@ -265,7 +265,7 @@ private async Task HandleFileChangedAsync(CancellationToken cancellationToken) { // Only notify the project if the contents of the watched file have changed. // In the case if we fail to read the contents, we will opt to notify the project. - byte[] newHash = GetFileHashOrNull(_fileBeingWatched); + byte[]? newHash = GetFileHashOrNull(_fileBeingWatched); if (newHash == null || _previousContentsHash == null || !newHash.SequenceEqual(_previousContentsHash)) { TraceUtilities.TraceVerbose("{0} changed on disk. Marking project dirty", _fileBeingWatched); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/ProjectRestoreInfo.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/ProjectRestoreInfo.cs index 0353f74d65f..d0da3a39f4d 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/ProjectRestoreInfo.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/ProjectRestoreInfo.cs @@ -6,12 +6,12 @@ namespace Microsoft.VisualStudio.ProjectSystem.VS.NuGet { internal class ProjectRestoreInfo : IVsProjectRestoreInfo { - public string BaseIntermediatePath { get; set; } + public string? BaseIntermediatePath { get; set; } - public string OriginalTargetFrameworks { get; set; } + public string? OriginalTargetFrameworks { get; set; } - public IVsTargetFrameworks TargetFrameworks { get; set; } + public IVsTargetFrameworks? TargetFrameworks { get; set; } - public IVsReferenceItems ToolReferences { get; set; } + public IVsReferenceItems? ToolReferences { get; set; } } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/ProjectRestoreInfoBuilder.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/ProjectRestoreInfoBuilder.cs index 4ddbca7e407..979050b6728 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/ProjectRestoreInfoBuilder.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/ProjectRestoreInfoBuilder.cs @@ -16,7 +16,7 @@ internal static class ProjectRestoreInfoBuilder private const string DefiningProjectDirectoryProperty = "DefiningProjectDirectory"; private const string ProjectFileFullPathProperty = "ProjectFileFullPath"; - internal static IVsProjectRestoreInfo Build(IEnumerable updates, + internal static IVsProjectRestoreInfo? Build(IEnumerable updates, UnconfiguredProject project) { Requires.NotNull(updates, nameof(updates)); @@ -25,7 +25,7 @@ internal static IVsProjectRestoreInfo Build(IEnumerable u return Build(updates.Cast>(), project); } - internal static IVsProjectRestoreInfo Build(IEnumerable> updates, + internal static IVsProjectRestoreInfo? Build(IEnumerable> updates, UnconfiguredProject project) { Requires.NotNull(updates, nameof(updates)); @@ -37,8 +37,8 @@ internal static IVsProjectRestoreInfo Build(IEnumerable internal abstract class VsItemList : KeyedCollection + where T : class { protected VsItemList() : base() { } @@ -22,18 +24,18 @@ protected VsItemList(IEnumerable collection) : base() } } - public T Item(object index) + public T? Item(object index) { if (index is string) { - TryGetValue((string)index, out T value); + TryGetValue((string)index, out T? value); return value; } return this[(int)index]; } - public bool TryGetValue(string key, out T value) + public bool TryGetValue(string key, [NotNullWhenTrue]out T? value) { // Until we have https://github.com/dotnet/corefx/issues/4690 diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/ProjectSystemOptions.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/ProjectSystemOptions.cs index d3d452afd0d..cbbb39ffd28 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/ProjectSystemOptions.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/ProjectSystemOptions.cs @@ -56,8 +56,9 @@ private bool IsEnabled(string variable, ref bool? result) result = string.Equals(value, "1", StringComparison.OrdinalIgnoreCase); } - +#pragma warning disable CS8629 // Workaround https://github.com/dotnet/roslyn/issues/31871 return result.Value; +#pragma warning restore CS8629 } } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Properties/AbstractProjectConfigurationProperties.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Properties/AbstractProjectConfigurationProperties.cs index 1c2d3e5c09a..f0d666cbcc1 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Properties/AbstractProjectConfigurationProperties.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Properties/AbstractProjectConfigurationProperties.cs @@ -145,7 +145,7 @@ public bool RunCodeAnalysis } } - public object ExtenderNames => null; + public object? ExtenderNames => null; public string __id => throw new System.NotImplementedException(); public bool DebugSymbols { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); } public bool DefineDebug { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Properties/InterceptedProjectProperties/AbstractBuildEventValueProvider.AbstractBuildEventHelper.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Properties/InterceptedProjectProperties/AbstractBuildEventValueProvider.AbstractBuildEventHelper.cs index 5bb431a22db..7ae95d30e75 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Properties/InterceptedProjectProperties/AbstractBuildEventValueProvider.AbstractBuildEventHelper.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Properties/InterceptedProjectProperties/AbstractBuildEventValueProvider.AbstractBuildEventHelper.cs @@ -33,7 +33,7 @@ protected AbstractBuildEventHelper(string buildEvent, private string BuildEvent { get; } private string TargetName { get; } - public async Task<(bool success, string property)> TryGetPropertyAsync(IProjectProperties defaultProperties) + public async Task<(bool success, string? property)> TryGetPropertyAsync(IProjectProperties defaultProperties) { // check if value already exists string unevaluatedPropertyValue = await defaultProperties.GetUnevaluatedPropertyValueAsync(BuildEvent); @@ -44,7 +44,7 @@ protected AbstractBuildEventHelper(string buildEvent, return (false, null); } - public string GetProperty(ProjectRootElement projectXml) + public string? GetProperty(ProjectRootElement projectXml) { return GetFromTargets(projectXml); } @@ -83,7 +83,7 @@ public void SetProperty(string unevaluatedPropertyValue, ProjectRootElement proj SetParameter(projectXml, unevaluatedPropertyValue); } - private string GetFromTargets(ProjectRootElement projectXml) + private string? GetFromTargets(ProjectRootElement projectXml) { (bool success, ProjectTaskElement execTask) = FindExecTaskInTargets(projectXml); @@ -129,7 +129,7 @@ private static bool OnlyWhitespaceCharacters(string unevaluatedPropertyValue) return (success: foundTarget != null, target: foundTarget); } - private void SetParameter(ProjectRootElement projectXml, string unevaluatedPropertyValue) + private void SetParameter(ProjectRootElement projectXml, string? unevaluatedPropertyValue) { (bool success, ProjectTaskElement execTask) result = FindExecTaskInTargets(projectXml); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Properties/InterceptedProjectProperties/AbstractBuildEventValueProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Properties/InterceptedProjectProperties/AbstractBuildEventValueProvider.cs index 2ce3d7a6e1c..d23f0c37e81 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Properties/InterceptedProjectProperties/AbstractBuildEventValueProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Properties/InterceptedProjectProperties/AbstractBuildEventValueProvider.cs @@ -22,8 +22,8 @@ protected AbstractBuildEventValueProvider( _helper = helper; } - public override async Task OnGetEvaluatedPropertyValueAsync( - string evaluatedPropertyValue, + public override async Task OnGetEvaluatedPropertyValueAsync( + string? evaluatedPropertyValue, IProjectProperties defaultProperties) { (bool success, string property) = await _helper.TryGetPropertyAsync(defaultProperties); @@ -35,10 +35,10 @@ public override async Task OnGetEvaluatedPropertyValueAsync( return await _projectAccessor.OpenProjectXmlForReadAsync(_unconfiguredProject, projectXml => _helper.GetProperty(projectXml)); } - public override async Task OnSetPropertyValueAsync( - string unevaluatedPropertyValue, + public override async Task OnSetPropertyValueAsync( + string? unevaluatedPropertyValue, IProjectProperties defaultProperties, - IReadOnlyDictionary dimensionalConditions = null) + IReadOnlyDictionary? dimensionalConditions = null) { if(await _helper.TrySetPropertyAsync(unevaluatedPropertyValue, defaultProperties)) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Properties/InterceptedProjectProperties/OutputTypeValueProviderBase.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Properties/InterceptedProjectProperties/OutputTypeValueProviderBase.cs index 95f1dffa9fd..410a83a172b 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Properties/InterceptedProjectProperties/OutputTypeValueProviderBase.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Properties/InterceptedProjectProperties/OutputTypeValueProviderBase.cs @@ -21,7 +21,7 @@ protected OutputTypeValueProviderBase(ProjectProperties properties) _properties = properties; } - public override async Task OnGetEvaluatedPropertyValueAsync(string evaluatedPropertyValue, IProjectProperties defaultProperties) + public override async Task OnGetEvaluatedPropertyValueAsync(string? evaluatedPropertyValue, IProjectProperties defaultProperties) { ConfigurationGeneral configuration = await _properties.GetConfigurationGeneralPropertiesAsync(); string value = await configuration.OutputType.GetEvaluatedValueAtEndAsync(); @@ -34,7 +34,10 @@ public override async Task OnGetEvaluatedPropertyValueAsync(string evalu } - public override async Task OnSetPropertyValueAsync(string unevaluatedPropertyValue, IProjectProperties defaultProperties, IReadOnlyDictionary dimensionalConditions = null) + public override async Task OnSetPropertyValueAsync( + string? unevaluatedPropertyValue, + IProjectProperties defaultProperties, + IReadOnlyDictionary? dimensionalConditions = null) { string value = SetMap[unevaluatedPropertyValue]; ConfigurationGeneral configuration = await _properties.GetConfigurationGeneralPropertiesAsync(); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Properties/InterceptedProjectProperties/TargetFrameworkMonikerValueProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Properties/InterceptedProjectProperties/TargetFrameworkMonikerValueProvider.cs index f0bff61ed8b..de17d8e19c0 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Properties/InterceptedProjectProperties/TargetFrameworkMonikerValueProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Properties/InterceptedProjectProperties/TargetFrameworkMonikerValueProvider.cs @@ -29,7 +29,10 @@ public TargetFrameworkMonikerValueProvider(IUnconfiguredProjectVsServices unconf _frameworkParser = frameworkParser; } - public override async Task OnSetPropertyValueAsync(string unevaluatedPropertyValue, IProjectProperties defaultProperties, IReadOnlyDictionary dimensionalConditions = null) + public override async Task OnSetPropertyValueAsync( + string? unevaluatedPropertyValue, + IProjectProperties defaultProperties, + IReadOnlyDictionary? dimensionalConditions = null) { ConfigurationGeneral configuration = await _properties.GetConfigurationGeneralPropertiesAsync(); string currentTargetFramework = (string)await configuration.TargetFramework.GetValueAsync(); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Properties/InterceptedProjectProperties/TargetFrameworkMonikersValueProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Properties/InterceptedProjectProperties/TargetFrameworkMonikersValueProvider.cs index 2a762fc9a88..a717b8da9cf 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Properties/InterceptedProjectProperties/TargetFrameworkMonikersValueProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Properties/InterceptedProjectProperties/TargetFrameworkMonikersValueProvider.cs @@ -18,9 +18,12 @@ public TargetFrameworkMonikersValueProvider(IActiveConfiguredProjectsProvider pr _projectProvider = projectProvider; } - public override async Task OnGetEvaluatedPropertyValueAsync(string evaluatedPropertyValue, IProjectProperties defaultProperties) + public override async Task OnGetEvaluatedPropertyValueAsync(string? evaluatedPropertyValue, IProjectProperties defaultProperties) { - ActiveConfiguredObjects configuredProjects = await _projectProvider.GetActiveConfiguredProjectsAsync(); + ActiveConfiguredObjects? configuredProjects = await _projectProvider.GetActiveConfiguredProjectsAsync(); + if (configuredProjects == null) + return null; + var builder = PooledArray.GetInstance(); foreach (ConfiguredProject configuredProject in configuredProjects.Objects) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Properties/ProjectFileOrAssemblyInfoPropertiesProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Properties/ProjectFileOrAssemblyInfoPropertiesProvider.cs index 229c538b77e..e76f18c5bd1 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Properties/ProjectFileOrAssemblyInfoPropertiesProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Properties/ProjectFileOrAssemblyInfoPropertiesProvider.cs @@ -31,7 +31,7 @@ public ProjectFileOrAssemblyInfoPropertiesProvider( VisualStudioWorkspace workspace, IProjectThreadingService threadingService) : base(delegatedProvider, instanceProvider, interceptingValueProviders, project, - getActiveProjectId: () => ((AbstractProject)languageServiceHost.ActiveProjectContext)?.Id, + getActiveProjectId: () => ((AbstractProject?)languageServiceHost.ActiveProjectContext)?.Id, workspace: workspace, threadingService: threadingService) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/BuildMacroInfo.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/BuildMacroInfo.cs index eb4cae1c207..3a6270d7083 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/BuildMacroInfo.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/BuildMacroInfo.cs @@ -14,8 +14,8 @@ namespace Microsoft.VisualStudio.ProjectSystem.VS.PropertyPages [AppliesTo(ProjectCapability.DotNet)] internal class BuildMacroInfo : IVsBuildMacroInfo, IDisposable { - private IProjectThreadingService _threadingService; - private ActiveConfiguredProject _configuredProject; + private IProjectThreadingService? _threadingService; + private ActiveConfiguredProject? _configuredProject; /// /// Initializes a new instance of the class. @@ -37,9 +37,9 @@ public BuildMacroInfo( /// String containing the name of the macro. /// String containing the value or body of the macro. /// If the method succeeds, it returns S_OK. If it fails, it returns an error code. - public int GetBuildMacroValue(string bstrBuildMacroName, out string pbstrBuildMacroValue) + public int GetBuildMacroValue(string bstrBuildMacroName, out string? pbstrBuildMacroValue) { - if (_configuredProject == null) + if (_configuredProject == null || _threadingService == null) { pbstrBuildMacroValue = null; return HResult.Unexpected; diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/DebugPageControl.xaml.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/DebugPageControl.xaml.cs index 8f97fee0024..baf251b30f0 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/DebugPageControl.xaml.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/DebugPageControl.xaml.cs @@ -48,16 +48,16 @@ private void OnClearEnvironmentVariableGridError(object sender, EventArgs e) private void OnFocusEnvironmentVariableGridRow(object sender, EventArgs e) { - if (DataContext != null && DataContext is DebugPageViewModel) + if (DataContext is DebugPageViewModel debugPageViewModel) { ThreadHelper.JoinableTaskFactory.StartOnIdle(async () => { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); - if ((DataContext as DebugPageViewModel).EnvironmentVariables.Count > 0) + if (debugPageViewModel.EnvironmentVariables.Count > 0) { // get the new cell, set focus, then open for edit - DataGridCell cell = WpfHelper.GetCell(dataGridEnvironmentVariables, (DataContext as DebugPageViewModel).EnvironmentVariables.Count - 1, 0); - cell.Focus(); + DataGridCell? cell = WpfHelper.GetCell(dataGridEnvironmentVariables, debugPageViewModel.EnvironmentVariables.Count - 1, 0); + cell?.Focus(); dataGridEnvironmentVariables.BeginEdit(); } }).FileAndForget(TelemetryEvents.ProjectSystemRootPath); @@ -102,7 +102,7 @@ private void DebugPageControl_LayoutUpdated(object sender, EventArgs e) _customControlLayoutUpdateRequired = false; // Get the control that was added to the grid - UserControl customControl = ((DebugPageViewModel)DataContext).ActiveProviderUserControl; + UserControl? customControl = ((DebugPageViewModel)DataContext).ActiveProviderUserControl; if (customControl != null) { if (customControl.Content is Grid childGrid && childGrid.ColumnDefinitions.Count == _mainGrid.ColumnDefinitions.Count) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/DebugPageViewModel.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/DebugPageViewModel.cs index a48096bcb10..d354f674429 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/DebugPageViewModel.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/DebugPageViewModel.cs @@ -25,10 +25,10 @@ namespace Microsoft.VisualStudio.ProjectSystem.VS.PropertyPages internal class DebugPageViewModel : PropertyPageViewModel, INotifyDataErrorInfo { private readonly string _executableFilter = string.Format("{0} (*.exe)|*.exe|{1} (*.*)|*.*", PropertyPageResources.ExecutableFiles, PropertyPageResources.AllFiles); - private IDisposable _debugProfileProviderLink; + private IDisposable? _debugProfileProviderLink; // Unit Tests only - private readonly TaskCompletionSource _firstSnapshotCompleteSource = null; + private readonly TaskCompletionSource? _firstSnapshotCompleteSource = null; private IProjectThreadingService _projectThreadingService; private IProjectThreadingService ProjectThreadingService @@ -99,8 +99,8 @@ public List LaunchTypes } } - private LaunchType _selectedLaunchType; - public LaunchType SelectedLaunchType + private LaunchType? _selectedLaunchType; + public LaunchType? SelectedLaunchType { get { @@ -108,7 +108,7 @@ public LaunchType SelectedLaunchType } set { - ILaunchSettingsUIProvider oldActiveProvider = ActiveProvider; + ILaunchSettingsUIProvider? oldActiveProvider = ActiveProvider; if (OnPropertyChanged(ref _selectedLaunchType, value)) { // Existing commands are shown in the UI as project @@ -149,7 +149,7 @@ public LaunchType SelectedLaunchType /// If we have an existing CustomControl, we disconnect from its change notifications /// and hook into the new ones. Assumes the activeProvider has already been changed /// - public void SwitchProviders(ILaunchSettingsUIProvider oldProvider) + public void SwitchProviders(ILaunchSettingsUIProvider? oldProvider) { // Get the old custom control and disconnect from notifications if (oldProvider?.CustomUI?.DataContext is INotifyPropertyChanged context) @@ -164,18 +164,18 @@ public void SwitchProviders(ILaunchSettingsUIProvider oldProvider) // Now hook into the current providers notifications. We do that after having set the profile on the provider // so that we don't get notifications while the control is initializing. Note that this is likely the first time the // custom control is asked for and we want to call it and have it created prior to setting the active profile - UserControl customControl = ActiveProvider?.CustomUI; + UserControl? customControl = ActiveProvider?.CustomUI; if (customControl != null) { - ActiveProvider.ProfileSelected(CurrentLaunchSettings); + ActiveProvider?.ProfileSelected(CurrentLaunchSettings); - context = customControl.DataContext as INotifyPropertyChanged; - if (context != null) + var inpc = customControl.DataContext as INotifyPropertyChanged; + if (inpc != null) { - context.PropertyChanged += OnCustomUIStateChanged; + inpc.PropertyChanged += OnCustomUIStateChanged; } - if (context is INotifyDataErrorInfo notifyDataErrorInfo) + if (inpc is INotifyDataErrorInfo notifyDataErrorInfo) { notifyDataErrorInfo.ErrorsChanged += OnCustomUIErrorsChanged; } @@ -191,7 +191,7 @@ private void OnCustomUIStateChanged(object sender, PropertyChangedEventArgs e) OnPropertyChanged("CustomUIDirty"); } - public string CommandLineArguments + public string? CommandLineArguments { get { @@ -200,7 +200,7 @@ public string CommandLineArguments return string.Empty; } - return SelectedDebugProfile.CommandLineArgs; + return SelectedDebugProfile?.CommandLineArgs; } set { @@ -212,7 +212,7 @@ public string CommandLineArguments } } - public string ExecutablePath + public string? ExecutablePath { get { @@ -221,7 +221,7 @@ public string ExecutablePath return string.Empty; } - return SelectedDebugProfile.ExecutablePath; + return SelectedDebugProfile?.ExecutablePath; } set { @@ -233,7 +233,7 @@ public string ExecutablePath } } - public string LaunchPage + public string? LaunchPage { get { @@ -242,7 +242,7 @@ public string LaunchPage return string.Empty; } - return SelectedDebugProfile.LaunchUrl; + return SelectedDebugProfile?.LaunchUrl; } set { @@ -254,7 +254,7 @@ public string LaunchPage } } - public string WorkingDirectory + public string? WorkingDirectory { get { @@ -263,7 +263,7 @@ public string WorkingDirectory return string.Empty; } - return SelectedDebugProfile.WorkingDirectory; + return SelectedDebugProfile?.WorkingDirectory; } set { @@ -284,7 +284,7 @@ public bool HasLaunchOption return false; } - return SelectedDebugProfile.LaunchBrowser; + return SelectedDebugProfile?.LaunchBrowser ?? false; } set { @@ -341,7 +341,7 @@ public bool SupportsEnvironmentVariables /// private bool ActiveProviderSupportsProperty(string propertyName) { - ILaunchSettingsUIProvider activeProvider = ActiveProvider; + ILaunchSettingsUIProvider? activeProvider = ActiveProvider; return activeProvider?.ShouldEnableProperty(propertyName) ?? false; } @@ -382,7 +382,7 @@ public bool HasProfiles /// /// Use the active profile in the CurrentLaunchSettings /// - public IWritableLaunchProfile SelectedDebugProfile + public IWritableLaunchProfile? SelectedDebugProfile { get { @@ -392,7 +392,7 @@ public IWritableLaunchProfile SelectedDebugProfile { if (CurrentLaunchSettings != null && CurrentLaunchSettings.ActiveProfile != value) { - IWritableLaunchProfile oldProfile = CurrentLaunchSettings.ActiveProfile; + IWritableLaunchProfile? oldProfile = CurrentLaunchSettings.ActiveProfile; CurrentLaunchSettings.ActiveProfile = value; NotifySelectedChanged(oldProfile); } @@ -476,7 +476,7 @@ public ObservableList EnvironmentVariables /// /// Provides binding to the current UI Provider usercontrol. /// - public UserControl ActiveProviderUserControl + public UserControl? ActiveProviderUserControl { get { @@ -488,7 +488,7 @@ public UserControl ActiveProviderUserControl /// Called when the selection does change. Note that this code relies on the fact the current selection has been /// updated /// - protected virtual void NotifySelectedChanged(IWritableLaunchProfile oldProfile) + protected virtual void NotifySelectedChanged(IWritableLaunchProfile? oldProfile) { // we need to keep the property page control from setting IsDirty when we are just switching between profiles. // we still need to notify the display of the changes though @@ -556,7 +556,7 @@ public virtual async Task SaveLaunchSettings() await provider.UpdateAndSaveSettingsAsync(CurrentLaunchSettings.ToLaunchSettings()); } - private void SetEnvironmentGrid(IWritableLaunchProfile oldProfile) + private void SetEnvironmentGrid(IWritableLaunchProfile? oldProfile) { if (EnvironmentVariables != null && oldProfile != null) { @@ -590,10 +590,9 @@ private void SetEnvironmentGrid(IWritableLaunchProfile oldProfile) ((INotifyPropertyChanged)EnvironmentVariables).PropertyChanged += DebugPageViewModel_EnvironmentVariables_PropertyChanged; } - private void EnvironmentVariables_ValidationStatusChanged(object sender, EventArgs e) + private void EnvironmentVariables_ValidationStatusChanged(object sender, ValidationStatusChangedEventArgs e) { - var args = e as ValidationStatusChangedEventArgs; - EnvironmentVariablesValid = args.ValidationStatus; + EnvironmentVariablesValid = e.ValidationStatus; } /// @@ -617,7 +616,7 @@ internal virtual void InitializeDebugTargetsCore(ILaunchSettings profiles) PushIgnoreEvents(); // Remember the current selection - string curProfileName = SelectedDebugProfile?.Name; + string? curProfileName = SelectedDebugProfile?.Name; // Update the set of settings and generate a property change so the list of profiles gets updated. Note that we always // clear the active profile on the CurrentLaunchSettings so that when we do set one and property changed event is set @@ -642,7 +641,7 @@ internal virtual void InitializeDebugTargetsCore(ILaunchSettings profiles) // Note that we have to be careful since the collection can be empty. if (profiles.ActiveProfile != null && !string.IsNullOrEmpty(profiles.ActiveProfile.Name)) { - SelectedDebugProfile = LaunchProfiles.Where(p => LaunchProfile.IsSameProfileName(p.Name, profiles.ActiveProfile.Name)).Single(); + SelectedDebugProfile = LaunchProfiles.Where(p => LaunchProfile.IsSameProfileName(p.Name, profiles.ActiveProfile?.Name)).Single(); } else { @@ -722,7 +721,7 @@ protected virtual IEnumerable - private ILaunchSettingsUIProvider ActiveProvider + private ILaunchSettingsUIProvider? ActiveProvider { get { @@ -731,7 +730,7 @@ private ILaunchSettingsUIProvider ActiveProvider return null; } - Lazy activeProvider = _uiProviders.FirstOrDefault((p) => string.Equals(p.Value.CommandName, SelectedLaunchType.CommandName, StringComparison.OrdinalIgnoreCase)); + Lazy activeProvider = _uiProviders.FirstOrDefault((p) => string.Equals(p.Value.CommandName, SelectedLaunchType?.CommandName, StringComparison.OrdinalIgnoreCase)); return activeProvider?.Value; } } @@ -746,7 +745,7 @@ public override Task Initialize() /// /// Called when then the user saves the form. /// - public override async Task Save() + public override async Task Save() { if (HasErrors) { @@ -754,8 +753,6 @@ public override async Task Save() } await SaveLaunchSettings(); - - return VSConstants.S_OK; } @@ -802,7 +799,7 @@ public ICommand BrowseDirectoryCommand { using (var dialog = new System.Windows.Forms.FolderBrowserDialog()) { - string folder = WorkingDirectory; + string? folder = WorkingDirectory; if (!string.IsNullOrEmpty(folder) && Directory.Exists(folder)) { dialog.SelectedPath = folder; @@ -827,7 +824,7 @@ public ICommand BrowseExecutableCommand { using (var dialog = new System.Windows.Forms.OpenFileDialog()) { - string file = ExecutablePath; + string? file = ExecutablePath; if (!string.IsNullOrEmpty(file) && (file.IndexOfAny(Path.GetInvalidPathChars()) == -1) && Path.IsPathRooted(file)) { dialog.InitialDirectory = Path.GetDirectoryName(file); @@ -894,7 +891,7 @@ public ICommand DeleteProfileCommand return LazyInitializer.EnsureInitialized(ref _deleteProfileCommand, () => new DelegateCommand(state => { - IWritableLaunchProfile profileToRemove = SelectedDebugProfile; + IWritableLaunchProfile? profileToRemove = SelectedDebugProfile; SelectedDebugProfile = null; CurrentLaunchSettings.Profiles.Remove(profileToRemove); @@ -956,15 +953,15 @@ private void UpdateLaunchTypes() _providerLaunchTypes = new List(); foreach (Lazy provider in _uiProviders) { - if (_providerLaunchTypes.FirstOrDefault((lt) => lt.CommandName.Equals(provider.Value.CommandName)) == null) + if (_providerLaunchTypes.FirstOrDefault((lt) => provider.Value.CommandName.Equals(lt.CommandName)) == null) { _providerLaunchTypes.Add(new LaunchType() { CommandName = provider.Value.CommandName, Name = provider.Value.FriendlyName }); } } } - IWritableLaunchProfile selectedProfile = SelectedDebugProfile; - LaunchType selectedLaunchType = null; + IWritableLaunchProfile? selectedProfile = SelectedDebugProfile; + LaunchType? selectedLaunchType = null; _launchTypes = new List(); if (selectedProfile != null) @@ -1032,7 +1029,7 @@ private void OnCustomUIErrorsChanged(object sender, DataErrorsChangedEventArgs e OnPropertyChanged(nameof(DoesNotHaveErrors)); } - public IEnumerable GetErrors(string propertyName) + public IEnumerable? GetErrors(string propertyName) { return null; } @@ -1063,8 +1060,8 @@ public bool DoesNotHaveErrors public class LaunchType { - public string CommandName { get; set; } - public string Name { get; set; } + public string? CommandName { get; set; } + public string? Name { get; set; } public override bool Equals(object obj) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/EnvironmentGridTemplateColumn.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/EnvironmentGridTemplateColumn.cs index 74c46929949..a2051de0ce4 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/EnvironmentGridTemplateColumn.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/EnvironmentGridTemplateColumn.cs @@ -9,11 +9,11 @@ namespace Microsoft.VisualStudio.ProjectSystem.VS.PropertyPages { internal class EnvironmentDataGridTemplateColumn : DataGridTemplateColumn { - protected override object PrepareCellForEdit(FrameworkElement frameworkElement, RoutedEventArgs routedEventArgs) + protected override object? PrepareCellForEdit(FrameworkElement frameworkElement, RoutedEventArgs routedEventArgs) { if (frameworkElement is ContentPresenter contentPresenter) { - TextBox textBox = WpfHelper.GetVisualChild(contentPresenter); + TextBox? textBox = WpfHelper.GetVisualChild(contentPresenter); if (textBox != null) { textBox.SelectAll(); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/ExecutableLaunchSettingsUIProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/ExecutableLaunchSettingsUIProvider.cs index ce5020bbc06..6eaa7b263b3 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/ExecutableLaunchSettingsUIProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/ExecutableLaunchSettingsUIProvider.cs @@ -56,7 +56,7 @@ public bool ShouldEnableProperty(string propertyName) /// /// No custom UI /// - public UserControl CustomUI { get { return null; } } + public UserControl? CustomUI { get { return null; } } /// /// Called when the selected profile changes to a profile which matches this command. curSettings will contain diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/ProjectLaunchSettingsUIProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/ProjectLaunchSettingsUIProvider.cs index ad017e04bd6..e0b4e890073 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/ProjectLaunchSettingsUIProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/ProjectLaunchSettingsUIProvider.cs @@ -58,7 +58,7 @@ public bool ShouldEnableProperty(string propertyName) /// /// No custom UI /// - public UserControl CustomUI { get { return null; } } + public UserControl? CustomUI { get { return null; } } /// /// Called when the selected profile changes to a profile which matches this command. curSettings will contain diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/PropertyPage.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/PropertyPage.cs index d86b2ffe96f..9be36b7c5b9 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/PropertyPage.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/PropertyPage.cs @@ -18,10 +18,10 @@ public abstract partial class PropertyPage : UserControl, IPropertyPage, IVsDebuggerEvents { - private IPropertyPageSite _site = null; + private IPropertyPageSite? _site = null; private bool _isDirty = false; private readonly bool _ignoreEvents = false; - private IVsDebugger _debugger; + private IVsDebugger? _debugger; private uint _debuggerCookie; private bool _isActivated = false; internal IProjectThreadingService _threadHandling; @@ -42,7 +42,7 @@ internal PropertyPage() AutoScroll = false; } - internal UnconfiguredProject UnconfiguredProject { get; set; } + internal UnconfiguredProject? UnconfiguredProject { get; set; } ///-------------------------------------------------------------------------------------------- diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/PropertyPageControl.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/PropertyPageControl.cs index ea658120ea5..afe01cb0b59 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/PropertyPageControl.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/PropertyPageControl.cs @@ -16,11 +16,11 @@ public PropertyPageControl() public event EventHandler StatusChanged; - public PropertyPageViewModel ViewModel + public PropertyPageViewModel? ViewModel { get { - return DataContext as PropertyPageViewModel; + return (PropertyPageViewModel)DataContext; } set { @@ -56,35 +56,33 @@ public virtual void DetachViewModel() { _ignoreEvents = true; IsDirty = false; - ViewModel.PropertyChanged -= ViewModel_PropertyChanged; + if (ViewModel != null) + { + ViewModel.PropertyChanged -= ViewModel_PropertyChanged; - // Let the view model know we are done. - ViewModel.ViewModelDetached(); - ViewModel.ParentControl = null; - ViewModel = null; + // Let the view model know we are done. + ViewModel.ViewModelDetached(); + ViewModel.ParentControl = null; + ViewModel = null; + } _ignoreEvents = false; } public async Task Apply() { - int result = VSConstants.S_OK; - if (IsDirty) { - result = await OnApply(); - if (result == VSConstants.S_OK) - { - IsDirty = false; - } + await OnApply(); + IsDirty = false; } - return result; + return VSConstants.S_OK; } - protected virtual Task OnApply() { return ViewModel.Save(); } + protected virtual Task OnApply() { return ViewModel == null ? Task.CompletedTask : ViewModel.Save(); } private void ViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { - if (!_ignoreEvents && !ViewModel.IgnoreEvents) + if (!_ignoreEvents && !ViewModel?.IgnoreEvents == true) { IsDirty = true; } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/PropertyPageViewModel.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/PropertyPageViewModel.cs index 227eb36a709..901f45c7b7f 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/PropertyPageViewModel.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/PropertyPageViewModel.cs @@ -11,7 +11,7 @@ internal abstract class PropertyPageViewModel : INotifyPropertyChanged public event PropertyChangedEventHandler PropertyChanged; public UnconfiguredProject Project { get; set; } - public PropertyPageControl ParentControl { get; set; } + public PropertyPageControl? ParentControl { get; set; } /// /// Since calls to ignore events can be nested, a downstream call could change the outer @@ -34,7 +34,7 @@ public void PopIgnoreEvents() } public abstract Task Initialize(); - public abstract Task Save(); + public abstract Task Save(); protected virtual void OnPropertyChanged(string propertyName, bool suppressInvalidation = false) { @@ -50,7 +50,7 @@ protected virtual void OnPropertyChanged(string propertyName, bool suppressInval } } - protected virtual bool OnPropertyChanged(ref T propertyRef, T value, bool suppressInvalidation, [CallerMemberName] string propertyName = null) + protected virtual bool OnPropertyChanged(ref T propertyRef, T value, bool suppressInvalidation, [CallerMemberName] string? propertyName = null) { if (!Equals(propertyRef, value)) { @@ -61,7 +61,7 @@ protected virtual bool OnPropertyChanged(ref T propertyRef, T value, bool sup return false; } - protected virtual bool OnPropertyChanged(ref T propertyRef, T value, [CallerMemberName] string propertyName = null) + protected virtual bool OnPropertyChanged(ref T propertyRef, T value, [CallerMemberName] string? propertyName = null) { return OnPropertyChanged(ref propertyRef, value, suppressInvalidation: false, propertyName: propertyName); } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/WatermarkTextBox.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/WatermarkTextBox.cs index d80a632364a..7ba41fa5b3a 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/WatermarkTextBox.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/WatermarkTextBox.cs @@ -54,7 +54,7 @@ public VerticalAlignment WatermarkVerticalAlignment [Localizability(LocalizationCategory.Label, Modifiability = Modifiability.Modifiable, Readability = Readability.Readable)] public string Watermark { - get { return GetValue(WatermarkProperty) as string; } + get { return (string)GetValue(WatermarkProperty); } set { SetValue(WatermarkProperty, value); } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/WpfBasedPropertyPage.Designer.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/WpfBasedPropertyPage.Designer.cs index 61ff15caa3e..a8d6e506039 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/WpfBasedPropertyPage.Designer.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/WpfBasedPropertyPage.Designer.cs @@ -5,7 +5,7 @@ partial class WpfBasedPropertyPage /// /// Required designer variable. /// - private System.ComponentModel.IContainer _components = null; + private System.ComponentModel.IContainer? _components = null; /// /// Clean up any resources being used. @@ -57,4 +57,4 @@ private void InitializeComponent() private System.Windows.Forms.Panel wpfHostPanel; } -} \ No newline at end of file +} diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/References/DesignTimeAssemblyResolution.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/References/DesignTimeAssemblyResolution.cs index de66b8c2b2b..047505c3238 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/References/DesignTimeAssemblyResolution.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/References/DesignTimeAssemblyResolution.cs @@ -39,7 +39,7 @@ internal partial class DesignTimeAssemblyResolution : IVsDesignTimeAssemblyResol // Ideally this would sit on a simple wrapper over the top of project subscription service, however, CPS's internal ReferencesHostBridge, which populates VSLangProj.References, // already does the work to listen to the project subscription for reference adds/removes/changes and makes sure to publish the results in sync with the solution tree. // We just use its results. - private IUnconfiguredProjectVsServices _projectVsServices; + private IUnconfiguredProjectVsServices? _projectVsServices; [ImportingConstructor] public DesignTimeAssemblyResolution(IUnconfiguredProjectVsServices projectVsServices) @@ -49,7 +49,7 @@ public DesignTimeAssemblyResolution(IUnconfiguredProjectVsServices projectVsServ _projectVsServices = projectVsServices; } - public int GetTargetFramework(out string ppTargetFramework) + public int GetTargetFramework(out string? ppTargetFramework) { if (_projectVsServices == null) { @@ -93,7 +93,7 @@ private uint ResolveReferences(string[] originalNames, AssemblyName[] assemblyNa for (int i = 0; i < assemblyName.Length; i++) { - string resolvedPath = FindResolvedAssemblyPath(references, assemblyName[i]); + string? resolvedPath = FindResolvedAssemblyPath(references, assemblyName[i]); if (resolvedPath != null) { assemblyPaths[resolvedReferencesCount] = new VsResolvedAssemblyPath() @@ -109,7 +109,7 @@ private uint ResolveReferences(string[] originalNames, AssemblyName[] assemblyNa return resolvedReferencesCount; } - private static string FindResolvedAssemblyPath(IDictionary references, AssemblyName assemblyName) + private static string? FindResolvedAssemblyPath(IDictionary references, AssemblyName assemblyName) { // NOTE: We mimic the behavior of the legacy project system when in "DTARUseReferencesFromProject" mode, it matches // only on version, and only against currently referenced assemblies, nothing more. @@ -135,7 +135,7 @@ private IDictionary GetAllResolvedReferences() { var resolvedReferences = new Dictionary(StringComparer.Ordinal); - VSProject project = GetVSProject(); + VSProject? project = GetVSProject(); if (project != null) { foreach (Reference3 reference in project.References.OfType()) @@ -151,8 +151,11 @@ private IDictionary GetAllResolvedReferences() return resolvedReferences; } - private VSProject GetVSProject() + private VSProject? GetVSProject() { + if (_projectVsServices == null) + throw new ObjectDisposedException(nameof(DesignTimeAssemblyResolution)); + Project project = _projectVsServices.VsHierarchy.GetProperty(VsHierarchyPropID.ExtObject); if (project == null) return null; @@ -184,7 +187,7 @@ private static bool TryParseAssemblyNames(string[] assemblyNames, out AssemblyNa return true; } - private static Version TryParseVersionOrNull(string version) + private static Version? TryParseVersionOrNull(string? version) { if (Version.TryParse(version, out Version result)) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Rename/SimpleRenameStrategy.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Rename/SimpleRenameStrategy.cs index eebaf8d43b5..e136d2ea19b 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Rename/SimpleRenameStrategy.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Rename/SimpleRenameStrategy.cs @@ -32,7 +32,7 @@ public override bool CanHandleRename(string oldFileName, string newFileName, boo public override async Task RenameAsync(Project myNewProject, string oldFileName, string newFileName, bool isCaseSensitive) { string oldNameBase = Path.GetFileNameWithoutExtension(oldFileName); - Solution renamedSolution = await GetRenamedSolutionAsync(myNewProject, oldNameBase, newFileName, isCaseSensitive); + Solution? renamedSolution = await GetRenamedSolutionAsync(myNewProject, oldNameBase, newFileName, isCaseSensitive); if (renamedSolution == null) return; @@ -47,10 +47,10 @@ public override async Task RenameAsync(Project myNewProject, string oldFileName, } } - private async Task GetRenamedSolutionAsync(Project myNewProject, string oldNameBase, string newFileName, bool isCaseSensitive) + private async Task GetRenamedSolutionAsync(Project myNewProject, string oldNameBase, string newFileName, bool isCaseSensitive) { Project project = myNewProject; - Solution renamedSolution = null; + Solution? renamedSolution = null; while (project != null) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/SpecialFilesProviders/VsProjectSpecialFilesManager.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/SpecialFilesProviders/VsProjectSpecialFilesManager.cs index 81d00428a87..a149e15b315 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/SpecialFilesProviders/VsProjectSpecialFilesManager.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/SpecialFilesProviders/VsProjectSpecialFilesManager.cs @@ -22,7 +22,7 @@ public VsProjectSpecialFilesManager(IUnconfiguredProjectVsServices projectVsServ _projectVsServices = projectVsServices; } - public async Task GetFileAsync(SpecialFiles fileId, SpecialFileFlags flags) + public async Task GetFileAsync(SpecialFiles fileId, SpecialFileFlags flags) { await _projectVsServices.ThreadingService.SwitchToUIThread(); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/CrossTarget/AggregateCrossTargetProjectContext.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/CrossTarget/AggregateCrossTargetProjectContext.cs index 0778e61eb0c..d0aacf4c3e9 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/CrossTarget/AggregateCrossTargetProjectContext.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/CrossTarget/AggregateCrossTargetProjectContext.cs @@ -36,7 +36,7 @@ public AggregateCrossTargetProjectContext( public IEnumerable InnerConfiguredProjects => _configuredProjectByTargetFramework.Values; - public ITargetFramework GetProjectFramework(ProjectConfiguration projectConfiguration) + public ITargetFramework? GetProjectFramework(ProjectConfiguration projectConfiguration) { if (projectConfiguration.Dimensions.TryGetValue(ConfigurationGeneral.TargetFrameworkProperty, out string targetFrameworkMoniker)) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/CrossTarget/ICrossTargetSubscriptionsHost.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/CrossTarget/ICrossTargetSubscriptionsHost.cs index f1216a3c8a9..6bed9ee7811 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/CrossTarget/ICrossTargetSubscriptionsHost.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/CrossTarget/ICrossTargetSubscriptionsHost.cs @@ -6,7 +6,7 @@ namespace Microsoft.VisualStudio.ProjectSystem.VS.Tree.Dependencies.CrossTarget { internal interface ICrossTargetSubscriptionsHost { - Task GetCurrentAggregateProjectContext(); + Task GetCurrentAggregateProjectContext(); Task GetConfiguredProject(ITargetFramework target); } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/CrossTarget/ITargetFrameworkProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/CrossTarget/ITargetFrameworkProvider.cs index 1bcbc7e7741..24aa22c5ada 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/CrossTarget/ITargetFrameworkProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/CrossTarget/ITargetFrameworkProvider.cs @@ -10,12 +10,12 @@ internal interface ITargetFrameworkProvider /// Parses full tfm or short framework name and returns a corresponding /// instance, or if the framework name has an invalid format. /// - ITargetFramework GetTargetFramework(string shortOrFullName); + ITargetFramework? GetTargetFramework(string shortOrFullName); /// /// Returns the item in that is most compatible/closest to /// , or if none are compatible. /// - ITargetFramework GetNearestFramework(ITargetFramework targetFramework, IEnumerable otherFrameworks); + ITargetFramework? GetNearestFramework(ITargetFramework targetFramework, IEnumerable otherFrameworks); } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/CrossTarget/TargetFramework.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/CrossTarget/TargetFramework.cs index 87519ab180a..2a30194097c 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/CrossTarget/TargetFramework.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/CrossTarget/TargetFramework.cs @@ -14,7 +14,7 @@ internal class TargetFramework : ITargetFramework /// public static readonly ITargetFramework Any = new TargetFramework("any"); - public TargetFramework(FrameworkName frameworkName, string shortName = null) + public TargetFramework(FrameworkName frameworkName, string? shortName = null) { Requires.NotNull(frameworkName, nameof(frameworkName)); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/CrossTarget/TargetFrameworkProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/CrossTarget/TargetFrameworkProvider.cs index 62a90585ee7..190802c5c65 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/CrossTarget/TargetFrameworkProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/CrossTarget/TargetFrameworkProvider.cs @@ -32,7 +32,7 @@ public TargetFrameworkProvider( _nuGetFrameworkParser = nugetFrameworkParser; } - public ITargetFramework GetTargetFramework(string shortOrFullName) + public ITargetFramework? GetTargetFramework(string shortOrFullName) { if (string.IsNullOrEmpty(shortOrFullName)) { @@ -87,7 +87,7 @@ public ITargetFramework GetTargetFramework(string shortOrFullName) } } - public ITargetFramework GetNearestFramework(ITargetFramework targetFramework, + public ITargetFramework? GetNearestFramework(ITargetFramework targetFramework, IEnumerable otherFrameworks) { if (targetFramework?.FrameworkName == null || otherFrameworks == null) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/DependenciesProjectTreeProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/DependenciesProjectTreeProvider.cs index e7bd31833c8..3cf9c9b2e20 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/DependenciesProjectTreeProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/DependenciesProjectTreeProvider.cs @@ -162,7 +162,7 @@ public override bool CanRemove(IImmutableSet nodes, continue; } - IDependency dependency = snapshot.FindDependency(filePath, topLevel: true); + IDependency? dependency = snapshot.FindDependency(filePath, topLevel: true); if (dependency == null || dependency.Implicit) { return false; @@ -248,7 +248,7 @@ await _projectAccessor.OpenProjectForWriteAsync(ActiveConfiguredProject, project continue; } - IDependency sharedProjectDependency = snapshot.FindDependency(sharedFilePath, topLevel: true); + IDependency? sharedProjectDependency = snapshot.FindDependency(sharedFilePath, topLevel: true); if (sharedProjectDependency != null) { sharedFilePath = sharedProjectDependency.Path; @@ -283,7 +283,7 @@ await _projectAccessor.OpenProjectForWriteAsync(ActiveConfiguredProject, project /// (deeper levels will be graph nodes with additional info, not direct dependencies /// specified in the project file) /// - public override IProjectTree FindByPath(IProjectTree root, string path) + public override IProjectTree? FindByPath(IProjectTree root, string path) { return _viewProviders.FirstOrDefault()?.Value.FindByPath(root, path); } @@ -446,10 +446,10 @@ protected override ConfiguredProjectExports GetActiveConfiguredProjectExports(Co public IProjectTree CreateTree( string caption, IProjectPropertiesContext itemContext, - IPropertySheet propertySheet = null, - IRule browseObjectProperties = null, - ProjectImageMoniker icon = null, - ProjectImageMoniker expandedIcon = null, + IPropertySheet? propertySheet = null, + IRule? browseObjectProperties = null, + ProjectImageMoniker? icon = null, + ProjectImageMoniker? expandedIcon = null, bool visible = true, ProjectTreeFlags? flags = default) { @@ -472,9 +472,9 @@ public IProjectTree CreateTree( public IProjectTree CreateTree( string caption, string filePath, - IRule browseObjectProperties = null, - ProjectImageMoniker icon = null, - ProjectImageMoniker expandedIcon = null, + IRule? browseObjectProperties = null, + ProjectImageMoniker? icon = null, + ProjectImageMoniker? expandedIcon = null, bool visible = true, ProjectTreeFlags? flags = default) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/DependencyIconSet.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/DependencyIconSet.cs index 5d4c088b792..77feee1110e 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/DependencyIconSet.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/DependencyIconSet.cs @@ -11,7 +11,7 @@ namespace Microsoft.VisualStudio.ProjectSystem.VS.Tree.Dependencies /// sets; we can save considerable amounts of memory by giving the sets their /// own type and sharing instances. /// - internal sealed class DependencyIconSet : IEquatable + internal sealed class DependencyIconSet : IEquatable { public DependencyIconSet(ImageMoniker icon, ImageMoniker expandedIcon, ImageMoniker unresolvedIcon, ImageMoniker unresolvedExpandedIcon) { @@ -26,12 +26,12 @@ public DependencyIconSet(ImageMoniker icon, ImageMoniker expandedIcon, ImageMoni public ImageMoniker UnresolvedIcon { get; } public ImageMoniker UnresolvedExpandedIcon { get; } - public override bool Equals(object obj) + public override bool Equals(object? obj) { return Equals(obj as DependencyIconSet); } - public bool Equals(DependencyIconSet other) + public bool Equals(DependencyIconSet? other) { return other != null && Icon.Id == other.Icon.Id diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/Actions/CheckChildrenGraphActionHandler.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/Actions/CheckChildrenGraphActionHandler.cs index d9519582084..9a61f45b9a5 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/Actions/CheckChildrenGraphActionHandler.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/Actions/CheckChildrenGraphActionHandler.cs @@ -57,7 +57,7 @@ public override bool HandleRequest(IGraphContext graphContext) continue; } - IDependenciesGraphViewProvider viewProvider = ViewProviders + IDependenciesGraphViewProvider? viewProvider = ViewProviders .FirstOrDefaultValue((x, d) => x.SupportsDependency(d), dependency); if (viewProvider == null) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/Actions/GetChildrenGraphActionHandler.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/Actions/GetChildrenGraphActionHandler.cs index 84f783c02aa..ffee112ed19 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/Actions/GetChildrenGraphActionHandler.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/Actions/GetChildrenGraphActionHandler.cs @@ -1,7 +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.ComponentModel.Composition; -using System.Linq; using Microsoft.VisualStudio.Composition; using Microsoft.VisualStudio.GraphModel; @@ -57,7 +56,7 @@ public override bool HandleRequest(IGraphContext graphContext) continue; } - IDependenciesGraphViewProvider viewProvider = ViewProviders + IDependenciesGraphViewProvider? viewProvider = ViewProviders .FirstOrDefaultValue((x, d) => x.SupportsDependency(d), dependency); if (viewProvider == null) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/Actions/GraphActionHandlerBase.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/Actions/GraphActionHandlerBase.cs index 70c137873f6..276d779fdda 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/Actions/GraphActionHandlerBase.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/Actions/GraphActionHandlerBase.cs @@ -48,11 +48,11 @@ public virtual bool HandleChanges(IGraphContext graphContext, SnapshotChangedEve return false; } - protected IDependency GetDependency(GraphNode inputGraphNode, out IDependenciesSnapshot snapshot) + protected IDependency? GetDependency(GraphNode inputGraphNode, out IDependenciesSnapshot? snapshot) { snapshot = null; - string projectPath = inputGraphNode.Id.GetValue(CodeGraphNodeIdName.Assembly); + string? projectPath = inputGraphNode.Id.GetValue(CodeGraphNodeIdName.Assembly); if (string.IsNullOrWhiteSpace(projectPath)) { return null; @@ -64,7 +64,7 @@ protected IDependency GetDependency(GraphNode inputGraphNode, out IDependenciesS return null; } - string id = inputGraphNode.GetValue(DependenciesGraphSchema.DependencyIdProperty); + string? id = inputGraphNode.GetValue(DependenciesGraphSchema.DependencyIdProperty); if (id == null) { // this is top level node and it contains full path @@ -96,7 +96,7 @@ protected IDependency GetDependency(GraphNode inputGraphNode, out IDependenciesS } } - protected IDependency GetDependency( + protected IDependency? GetDependency( string projectPath, string dependencyId, out IDependenciesSnapshot snapshot) @@ -105,7 +105,7 @@ protected IDependency GetDependency( return snapshot?.FindDependency(dependencyId); } - protected IDependency GetTopLevelDependency( + protected IDependency? GetTopLevelDependency( string projectPath, string dependencyId, out IDependenciesSnapshot snapshot) 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 4cdd8c4b143..7cdd94d9a8b 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 @@ -96,7 +96,7 @@ private void Search(IGraphContext graphContext) if (!cachedDependencyToMatchingResultsMap .TryGetValue(topLevelDependency.Id, out HashSet topLevelDependencyMatches)) { - IDependenciesGraphViewProvider viewProvider = ViewProviders + IDependenciesGraphViewProvider? viewProvider = ViewProviders .FirstOrDefaultValue((x, d) => x.SupportsDependency(d), topLevelDependency); if (viewProvider == null) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/Actions/TrackChangesGraphActionHandler.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/Actions/TrackChangesGraphActionHandler.cs index 70d35941c9f..c89f44131bb 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/Actions/TrackChangesGraphActionHandler.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/Actions/TrackChangesGraphActionHandler.cs @@ -59,7 +59,7 @@ public override bool HandleChanges(IGraphContext graphContext, SnapshotChangedEv continue; } - IDependenciesGraphViewProvider viewProvider = ViewProviders + IDependenciesGraphViewProvider? viewProvider = ViewProviders .FirstOrDefaultValue((x, d) => x.SupportsDependency(d), updatedDependency); if (viewProvider == null) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/DependenciesGraphProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/DependenciesGraphProvider.cs index 60ee7ef2320..4f1d15a7d33 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/DependenciesGraphProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/DependenciesGraphProvider.cs @@ -110,7 +110,7 @@ public IEnumerable GetCommands(IEnumerable nodes) /// /// IGraphProvider.GetExtension /// - public T GetExtension(GraphObject graphObject, T previous) where T : class + public T? GetExtension(GraphObject graphObject, T previous) where T : class { return null; } @@ -118,7 +118,7 @@ public T GetExtension(GraphObject graphObject, T previous) where T : class /// /// IGraphProvider.Schema /// - public Graph Schema => null; + public Graph? Schema => null; internal async Task BeginGetGraphDataAsync(IGraphContext context) { @@ -250,7 +250,7 @@ private GraphNode DoAddGraphNode( GraphNodeId graphNodeId, IGraphContext graphContext, string projectPath, - GraphNode parentNode, + GraphNode? parentNode, IDependencyViewModel viewModel) { _iconCache.Register(viewModel.Icon); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/GraphNodeIdExtensions.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/GraphNodeIdExtensions.cs index 14187211102..85687d7d69d 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/GraphNodeIdExtensions.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/GraphNodeIdExtensions.cs @@ -12,7 +12,7 @@ internal static class IProjectTreeExtensions1 /// /// Finds a tree node by it's flags. If there many nodes that satisfy flags, returns first. /// - internal static IProjectTree GetSubTreeNode(this IProjectTree self, ProjectTreeFlags flags) + internal static IProjectTree? GetSubTreeNode(this IProjectTree self, ProjectTreeFlags flags) { foreach (IProjectTree child in self.Children) { @@ -25,7 +25,7 @@ internal static IProjectTree GetSubTreeNode(this IProjectTree self, ProjectTreeF return null; } - internal static string GetValue(this GraphNodeId id, GraphNodeIdName idPartName) + internal static string? GetValue(this GraphNodeId id, GraphNodeIdName idPartName) { if (idPartName == CodeGraphNodeIdName.Assembly || idPartName == CodeGraphNodeIdName.File) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/ViewProviders/GraphViewProviderBase.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/ViewProviders/GraphViewProviderBase.cs index e8a74b501a1..278767c90ed 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/ViewProviders/GraphViewProviderBase.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/ViewProviders/GraphViewProviderBase.cs @@ -93,7 +93,7 @@ public virtual bool MatchSearchResults( string projectPath, IDependency topLevelDependency, Dictionary> searchResultsPerContext, - out HashSet topLevelDependencyMatches) + out HashSet? topLevelDependencyMatches) { topLevelDependencyMatches = null; return false; diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/ViewProviders/ProjectGraphViewProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/ViewProviders/ProjectGraphViewProvider.cs index b8d2d10cc0c..d50b430951a 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/ViewProviders/ProjectGraphViewProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/ViewProviders/ProjectGraphViewProvider.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.ComponentModel.Composition; using System.Linq; - +using System.Runtime.CompilerServices; using Microsoft.VisualStudio.GraphModel; using Microsoft.VisualStudio.ProjectSystem.VS.Tree.Dependencies.CrossTarget; using Microsoft.VisualStudio.ProjectSystem.VS.Tree.Dependencies.Snapshot; @@ -38,7 +38,7 @@ public override bool SupportsDependency(IDependency dependency) public override bool HasChildren(string projectPath, IDependency dependency) { - ITargetedDependenciesSnapshot targetedSnapshot = GetSnapshot(dependency); + ITargetedDependenciesSnapshot? targetedSnapshot = GetSnapshot(dependency); return targetedSnapshot?.TopLevelDependencies.Length != 0; } @@ -54,7 +54,7 @@ public override void BuildGraph( dependencyGraphNode.SetValue(DependenciesGraphSchema.DependencyIdProperty, dependency.Id); dependencyGraphNode.SetValue(DependenciesGraphSchema.ResolvedProperty, dependency.Resolved); - ITargetedDependenciesSnapshot otherProjectTargetedSnapshot = GetSnapshot(dependency); + ITargetedDependenciesSnapshot? otherProjectTargetedSnapshot = GetSnapshot(dependency); if (otherProjectTargetedSnapshot == null) { return; @@ -75,7 +75,7 @@ public override void BuildGraph( } } - private ITargetedDependenciesSnapshot GetSnapshot(IDependency dependency) + private ITargetedDependenciesSnapshot? GetSnapshot(IDependency dependency) { IDependenciesSnapshot snapshot = AggregateSnapshotProvider.GetSnapshotProvider(dependency.FullPath)?.CurrentSnapshot; @@ -85,7 +85,7 @@ private ITargetedDependenciesSnapshot GetSnapshot(IDependency dependency) return null; } - ITargetFramework targetFramework = TargetFrameworkProvider.GetNearestFramework( + ITargetFramework? targetFramework = TargetFrameworkProvider.GetNearestFramework( dependency.TargetFramework, snapshot.Targets.Keys); if (targetFramework == null) @@ -112,10 +112,10 @@ public override bool TrackChanges( { if (!AnyChanges(updatedDependency, dependencyGraphNode, - out IReadOnlyList nodesToAdd, - out IReadOnlyList nodesToRemove, - out System.Collections.Generic.IReadOnlyCollection updatedChildren, - out string dependencyProjectPath)) + out IReadOnlyList? nodesToAdd, + out IReadOnlyList? nodesToRemove, + out System.Collections.Generic.IReadOnlyCollection? updatedChildren, + out string? dependencyProjectPath)) { return false; } @@ -172,7 +172,7 @@ public override bool MatchSearchResults( return true; } - ITargetFramework nearestTargetFramework = TargetFrameworkProvider.GetNearestFramework( + ITargetFramework? nearestTargetFramework = TargetFrameworkProvider.GetNearestFramework( topLevelDependency.TargetFramework, contextResults.Select(x => x.TargetFramework)); if (nearestTargetFramework == null) @@ -190,12 +190,12 @@ public override bool MatchSearchResults( private bool AnyChanges( IDependency updatedDependency, GraphNode dependencyGraphNode, - out IReadOnlyList nodesToAdd, - out IReadOnlyList nodesToRemove, - out System.Collections.Generic.IReadOnlyCollection updatedChildren, - out string dependencyProjectPath) + [NotNullWhenTrue]out IReadOnlyList? nodesToAdd, + [NotNullWhenTrue]out IReadOnlyList? nodesToRemove, + [NotNullWhenTrue]out System.Collections.Generic.IReadOnlyCollection? updatedChildren, + [NotNullWhenTrue]out string? dependencyProjectPath) { - ITargetedDependenciesSnapshot snapshot = GetSnapshot(updatedDependency); + ITargetedDependenciesSnapshot? snapshot = GetSnapshot(updatedDependency); if (snapshot == null) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GroupedByTargetTreeViewProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GroupedByTargetTreeViewProvider.cs index 994da9518fa..cfbe0357cae 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GroupedByTargetTreeViewProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GroupedByTargetTreeViewProvider.cs @@ -128,14 +128,14 @@ IProjectTree RememberNewNodes(IProjectTree rootNode, IEnumerable c return dependenciesTree.SetProperties(icon: rootIcon, expandedIcon: rootIcon); } - public override IProjectTree FindByPath(IProjectTree root, string path) + public override IProjectTree? FindByPath(IProjectTree root, string path) { if (root == null) { return null; } - IProjectTree dependenciesNode = root.Flags.Contains(DependencyTreeFlags.DependenciesRootNodeFlags) + IProjectTree? dependenciesNode = root.Flags.Contains(DependencyTreeFlags.DependenciesRootNodeFlags) ? root : root.GetSubTreeNode(DependencyTreeFlags.DependenciesRootNodeFlags); @@ -226,13 +226,13 @@ private async Task BuildSubTreeAsync( bool isActiveTarget, bool shouldCleanup) { - List currentNodes = shouldCleanup + List? currentNodes = shouldCleanup ? new List(capacity: dependencies.Count) : null; foreach (IDependency dependency in dependencies) { - IProjectTree dependencyNode = rootNode.FindChildWithCaption(dependency.Caption); + IProjectTree? dependencyNode = rootNode.FindChildWithCaption(dependency.Caption); bool isNewDependencyNode = dependencyNode == null; if (!isNewDependencyNode @@ -258,7 +258,7 @@ private async Task BuildSubTreeAsync( : dependencyNode.Parent; } - return shouldCleanup + return currentNodes != null ? CleanupOldNodes(rootNode, currentNodes) : rootNode; } @@ -277,14 +277,14 @@ private static IProjectTree CleanupOldNodes(IProjectTree rootNode, IEnumerable CreateOrUpdateNodeAsync( - IProjectTree node, + IProjectTree? node, IDependency dependency, ITargetedDependenciesSnapshot targetedSnapshot, bool isProjectItem, ProjectTreeFlags? additionalFlags = null, ProjectTreeFlags? excludedFlags = null) { - IRule rule = null; + IRule? rule = null; if (dependency.Flags.Contains(DependencyTreeFlags.SupportsRuleProperties)) { rule = await TreeServices.GetRuleAsync(dependency, targetedSnapshot.Catalogs); @@ -300,9 +300,9 @@ private async Task CreateOrUpdateNodeAsync( } private IProjectTree CreateOrUpdateNode( - IProjectTree node, + IProjectTree? node, IDependencyViewModel viewModel, - IRule rule, + IRule? rule, bool isProjectItem, ProjectTreeFlags? additionalFlags = null, ProjectTreeFlags? excludedFlags = null) @@ -319,7 +319,7 @@ private IProjectTree CreateOrUpdateNode( private IProjectTree CreateProjectTreeNode( IDependencyViewModel viewModel, - IRule rule, + IRule? rule, ProjectTreeFlags? additionalFlags = null, ProjectTreeFlags? excludedFlags = null) { @@ -329,7 +329,7 @@ private IProjectTree CreateProjectTreeNode( ProjectTreeFlags flags = FilterFlags(viewModel.Flags.Except(DependencyTreeFlags.BaseReferenceFlags), additionalFlags, excludedFlags); - string filePath = (viewModel.OriginalModel != null && viewModel.OriginalModel.TopLevel && + string? filePath = (viewModel.OriginalModel != null && viewModel.OriginalModel.TopLevel && viewModel.OriginalModel.Resolved) ? viewModel.OriginalModel.GetTopLevelId() : viewModel.FilePath; @@ -346,12 +346,12 @@ private IProjectTree CreateProjectTreeNode( private IProjectTree CreateProjectItemTreeNode( IDependencyViewModel viewModel, - IRule rule, + IRule? rule, ProjectTreeFlags? additionalFlags = null, ProjectTreeFlags? excludedFlags = null) { ProjectTreeFlags flags = FilterFlags(viewModel.Flags, additionalFlags, excludedFlags); - string filePath = (viewModel.OriginalModel != null && viewModel.OriginalModel.TopLevel && + string? filePath = (viewModel.OriginalModel != null && viewModel.OriginalModel.TopLevel && viewModel.OriginalModel.Resolved) ? viewModel.OriginalModel.GetTopLevelId() : viewModel.FilePath; @@ -376,7 +376,7 @@ private IProjectTree CreateProjectItemTreeNode( private IProjectTree UpdateTreeNode( IProjectTree node, IDependencyViewModel viewModel, - IRule rule) + IRule? rule) { ProjectTreeCustomizablePropertyContext updatedNodeParentContext = GetCustomPropertyContext(node.Parent); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/IDependenciesTreeServices.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/IDependenciesTreeServices.cs index 0e2ace646d8..36e5c68c525 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/IDependenciesTreeServices.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/IDependenciesTreeServices.cs @@ -27,10 +27,10 @@ internal interface IDependenciesTreeServices IProjectTree CreateTree( string caption, IProjectPropertiesContext itemContext, - IPropertySheet propertySheet = null, - IRule browseObjectProperties = null, - ProjectImageMoniker icon = null, - ProjectImageMoniker expandedIcon = null, + IPropertySheet? propertySheet = null, + IRule? browseObjectProperties = null, + ProjectImageMoniker? icon = null, + ProjectImageMoniker? expandedIcon = null, bool visible = true, ProjectTreeFlags? flags = default); @@ -47,10 +47,10 @@ IProjectTree CreateTree( /// IProjectTree CreateTree( string caption, - string filePath, - IRule browseObjectProperties = null, - ProjectImageMoniker icon = null, - ProjectImageMoniker expandedIcon = null, + string? filePath, + IRule? browseObjectProperties = null, + ProjectImageMoniker? icon = null, + ProjectImageMoniker? expandedIcon = null, bool visible = true, ProjectTreeFlags? flags = default); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/IDependenciesTreeViewProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/IDependenciesTreeViewProvider.cs index 096a98018c9..6ab5dfbe955 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/IDependenciesTreeViewProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/IDependenciesTreeViewProvider.cs @@ -33,6 +33,6 @@ Task BuildTreeAsync( /// Node where we start searching /// Path to find /// - IProjectTree FindByPath(IProjectTree root, string path); + IProjectTree? FindByPath(IProjectTree root, string path); } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/IDependencyModel.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/IDependencyModel.cs index f920bead347..a7df4219b67 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/IDependencyModel.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/IDependencyModel.cs @@ -48,14 +48,14 @@ public interface IDependencyModel /// string Caption { get; } - string SchemaName { get; } + string? SchemaName { get; } - string SchemaItemType { get; } + string? SchemaItemType { get; } /// /// Version of the dependency /// - string Version { get; } + string? Version { get; } /// /// Specifies if dependency is resolved or not diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/DependencyModel.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/DependencyModel.cs index 4b85a833b63..64fa19a2198 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/DependencyModel.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/DependencyModel.cs @@ -62,7 +62,7 @@ protected DependencyModel( ProjectTreeFlags flags, bool isResolved, bool isImplicit, - IImmutableDictionary properties, + IImmutableDictionary? properties, bool isTopLevel = true, bool isVisible = true) { @@ -96,12 +96,12 @@ protected DependencyModel( public abstract string ProviderType { get; } public virtual string Name => Path; - public string Caption { get; protected set; } + public string? Caption { get; protected set; } public string OriginalItemSpec { get; } public string Path { get; } - public virtual string SchemaName => null; - public virtual string SchemaItemType => null; - public virtual string Version => null; + public virtual string? SchemaName => null; + public virtual string? SchemaItemType => null; + public virtual string? Version => null; public bool Resolved => (_flags & DependencyFlags.Resolved) != 0; public bool TopLevel => (_flags & DependencyFlags.TopLevel) != 0; public bool Implicit => (_flags & DependencyFlags.Implicit) != 0; diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/IDependencyViewModel.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/IDependencyViewModel.cs index 43214e60182..c824391775a 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/IDependencyViewModel.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/IDependencyViewModel.cs @@ -10,14 +10,14 @@ namespace Microsoft.VisualStudio.ProjectSystem.VS.Tree.Dependencies.Models internal interface IDependencyViewModel { string Caption { get; } - string FilePath { get; } - string SchemaName { get; } - string SchemaItemType { get; } + string? FilePath { get; } + string? SchemaName { get; } + string? SchemaItemType { get; } int Priority { get; } ImageMoniker Icon { get; } ImageMoniker ExpandedIcon { get; } - IImmutableDictionary Properties { get; } + IImmutableDictionary? Properties { get; } ProjectTreeFlags Flags { get; } - IDependency OriginalModel { get; } + IDependency? OriginalModel { get; } } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/PackageFrameworkAssembliesViewModel.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/PackageFrameworkAssembliesViewModel.cs index 82113b2435c..22ab68fd79f 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/PackageFrameworkAssembliesViewModel.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/PackageFrameworkAssembliesViewModel.cs @@ -14,14 +14,14 @@ internal sealed class PackageFrameworkAssembliesViewModel : IDependencyViewModel public static readonly ImageMoniker RegularIcon = KnownMonikers.Library; public string Caption => VSResources.FrameworkAssembliesNodeName; - public string FilePath => null; - public string SchemaName => null; - public string SchemaItemType => null; + public string? FilePath => null; + public string? SchemaName => null; + public string? SchemaItemType => null; public int Priority => Dependency.FrameworkAssemblyNodePriority; public ImageMoniker Icon => RegularIcon; public ImageMoniker ExpandedIcon => RegularIcon; - public IImmutableDictionary Properties => null; + public IImmutableDictionary? Properties => null; public ProjectTreeFlags Flags => DependencyTreeFlags.FrameworkAssembliesNodeFlags; - public IDependency OriginalModel => null; + public IDependency? OriginalModel => null; } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/SdkDependencyModel.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/SdkDependencyModel.cs index d5ad45ed09b..6958a22f053 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/SdkDependencyModel.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/SdkDependencyModel.cs @@ -34,11 +34,11 @@ internal class SdkDependencyModel : DependencyModel public override string ProviderType => SdkRuleHandler.ProviderTypeString; - public override string SchemaItemType => SdkReference.PrimaryDataSourceItemType; + public override string? SchemaItemType => SdkReference.PrimaryDataSourceItemType; - public override string SchemaName => Resolved ? ResolvedSdkReference.SchemaName : SdkReference.SchemaName; + public override string? SchemaName => Resolved ? ResolvedSdkReference.SchemaName : SdkReference.SchemaName; - public override string Version { get; } + public override string? Version { get; } public SdkDependencyModel( string path, @@ -55,7 +55,7 @@ public SdkDependencyModel( properties) { Version = properties.GetStringProperty(ProjectItemMetadata.Version) ?? string.Empty; - string baseCaption = new LazyStringSplit(path, ',').FirstOrDefault(); + string? baseCaption = new LazyStringSplit(path, ',').FirstOrDefault(); Caption = string.IsNullOrEmpty(Version) ? baseCaption : $"{baseCaption} ({Version})"; } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/TargetDependencyViewModel.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/TargetDependencyViewModel.cs index 7acbbc42158..9d4b87d5106 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/TargetDependencyViewModel.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/TargetDependencyViewModel.cs @@ -20,14 +20,14 @@ public TargetDependencyViewModel(ITargetedDependenciesSnapshot snapshot) } public string Caption { get; } - public string FilePath => null; - public string SchemaName => null; - public string SchemaItemType => null; + public string? FilePath => null; + public string? SchemaName => null; + public string? SchemaItemType => null; public int Priority => Dependency.FrameworkAssemblyNodePriority; public ImageMoniker Icon => _hasUnresolvedDependency ? ManagedImageMonikers.LibraryWarning : KnownMonikers.Library; public ImageMoniker ExpandedIcon => _hasUnresolvedDependency ? ManagedImageMonikers.LibraryWarning : KnownMonikers.Library; - public IImmutableDictionary Properties => null; + public IImmutableDictionary? Properties => null; public ProjectTreeFlags Flags { get; } - public IDependency OriginalModel => null; + public IDependency? OriginalModel => null; } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/SDKVersionTelemetryServiceComponent.SDKVersionTelemetryServiceInstance.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/SDKVersionTelemetryServiceComponent.SDKVersionTelemetryServiceInstance.cs index 59b63550ab9..3093413ad67 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/SDKVersionTelemetryServiceComponent.SDKVersionTelemetryServiceInstance.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/SDKVersionTelemetryServiceComponent.SDKVersionTelemetryServiceInstance.cs @@ -44,7 +44,7 @@ await _unconfiguredProjectTasksService.LoadedProjectAsync(async () => ConfigurationGeneral projectProperties = await _projectVsServices.ActiveConfiguredProjectProperties.GetConfigurationGeneralPropertiesAsync(); Task task = projectProperties?.NETCoreSdkVersion?.GetValueAsync(); string version = task == null ? string.Empty : (string)await task; - string projectId = await GetProjectIdAsync(); + string? projectId = await GetProjectIdAsync(); if (string.IsNullOrEmpty(version) || string.IsNullOrEmpty(projectId)) { @@ -64,7 +64,7 @@ await _unconfiguredProjectTasksService.LoadedProjectAsync(async () => protected override Task DisposeCoreAsync(bool initialized) => Task.CompletedTask; - private async Task GetProjectIdAsync() + private async Task GetProjectIdAsync() { Guid projectGuid = await _projectGuidService.GetProjectGuidAsync(); return projectGuid == Guid.Empty ? null : projectGuid.ToString(); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/DependenciesSnapshot.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/DependenciesSnapshot.cs index d9bc1f5da38..d536c3b32f3 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/DependenciesSnapshot.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/DependenciesSnapshot.cs @@ -38,11 +38,11 @@ public static DependenciesSnapshot FromChanges( string projectPath, DependenciesSnapshot previousSnapshot, ImmutableDictionary changes, - IProjectCatalogSnapshot catalogs, - ITargetFramework activeTargetFramework, + IProjectCatalogSnapshot? catalogs, + ITargetFramework? activeTargetFramework, ImmutableArray snapshotFilters, IReadOnlyDictionary subTreeProviderByProviderType, - IImmutableSet projectItemSpecs) + IImmutableSet? projectItemSpecs) { Requires.NotNullOrWhiteSpace(projectPath, nameof(projectPath)); Requires.NotNull(previousSnapshot, nameof(previousSnapshot)); @@ -110,7 +110,7 @@ bool RemoveTargetFrameworksWithNoDependencies() { // This is a long-winded way of doing this that minimises allocations - List emptyFrameworks = null; + List? emptyFrameworks = null; bool anythingRemoved = false; foreach ((ITargetFramework targetFramework, ITargetedDependenciesSnapshot targetedSnapshot) in builder) @@ -178,7 +178,7 @@ private DependenciesSnapshot( public bool HasUnresolvedDependency => Targets.Any(x => x.Value.HasUnresolvedDependency); /// - public IDependency FindDependency(string dependencyId, bool topLevel = false) + public IDependency? FindDependency(string dependencyId, bool topLevel = false) { if (string.IsNullOrEmpty(dependencyId)) { @@ -191,7 +191,7 @@ public IDependency FindDependency(string dependencyId, bool topLevel = false) // if found - return, if not - try regular Id in the DependenciesWorld foreach ((ITargetFramework _, ITargetedDependenciesSnapshot targetedDependencies) in Targets) { - IDependency dependency = targetedDependencies.TopLevelDependencies + IDependency? dependency = targetedDependencies.TopLevelDependencies .FirstOrDefault((x, id) => x.TopLevelIdEquals(id), dependencyId); if (dependency != null) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Dependency.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Dependency.cs index 0ff87a5adf5..d31587259c3 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Dependency.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Dependency.cs @@ -102,12 +102,12 @@ public Dependency(IDependencyModel dependencyModel, ITargetFramework targetFrame /// private Dependency( Dependency dependency, - string caption, + string? caption, bool? resolved, ProjectTreeFlags? flags, - string schemaName, - IImmutableList dependencyIDs, - DependencyIconSet iconSet, + string? schemaName, + IImmutableList? dependencyIDs, + DependencyIconSet? iconSet, bool? isImplicit) { // Copy values as necessary to create a clone with any properties overridden @@ -242,12 +242,12 @@ public string Alias } public IDependency SetProperties( - string caption = null, + string? caption = null, bool? resolved = null, ProjectTreeFlags? flags = null, - string schemaName = null, - IImmutableList dependencyIDs = null, - DependencyIconSet iconSet = null, + string? schemaName = null, + IImmutableList? dependencyIDs = null, + DependencyIconSet? iconSet = null, bool? isImplicit = null) { return new Dependency(this, caption, resolved, flags, schemaName, dependencyIDs, iconSet, isImplicit); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/AddDependencyContext.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/AddDependencyContext.cs index f99a536b8f1..ecbe12348d7 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/AddDependencyContext.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/AddDependencyContext.cs @@ -10,7 +10,7 @@ internal sealed class AddDependencyContext : IAddDependencyContext private readonly ImmutableDictionary.Builder _worldBuilder; private bool _acceptedOrRejected; - private IDependency _acceptedDependency; + private IDependency? _acceptedDependency; public bool Changed { get; private set; } @@ -26,7 +26,7 @@ public void Reset() _acceptedDependency = null; } - public IDependency GetResult(IDependenciesSnapshotFilter filter) + public IDependency? GetResult(IDependenciesSnapshotFilter filter) { if (!_acceptedOrRejected) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/DuplicatedDependenciesSnapshotFilter.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/DuplicatedDependenciesSnapshotFilter.cs index 7974ea758e9..f1084b56d28 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/DuplicatedDependenciesSnapshotFilter.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/DuplicatedDependenciesSnapshotFilter.cs @@ -29,7 +29,7 @@ public override void BeforeAddOrUpdate( IImmutableSet projectItemSpecs, IAddDependencyContext context) { - IDependency matchingDependency = null; + IDependency? matchingDependency = null; bool shouldApplyAlias = false; foreach ((string _, IDependency other) in context) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/RemoveDependencyContext.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/RemoveDependencyContext.cs index 609cd1c3ae9..322add2a2f1 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/RemoveDependencyContext.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/RemoveDependencyContext.cs @@ -10,7 +10,7 @@ internal sealed class RemoveDependencyContext : IRemoveDependencyContext private readonly ImmutableDictionary.Builder _worldBuilder; private bool? _acceptedOrRejected; - private IDependency _acceptedDependency; + private IDependency? _acceptedDependency; public bool Changed { get; private set; } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/UnsupportedProjectsSnapshotFilter.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/UnsupportedProjectsSnapshotFilter.cs index 7a57ce66a66..077ff1c36fc 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/UnsupportedProjectsSnapshotFilter.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/UnsupportedProjectsSnapshotFilter.cs @@ -45,7 +45,7 @@ public override void BeforeAddOrUpdate( && dependency.Flags.Contains(DependencyTreeFlags.ProjectNodeFlags) && !dependency.Flags.Contains(DependencyTreeFlags.SharedProjectFlags)) { - ITargetedDependenciesSnapshot snapshot = GetSnapshot(dependency); + ITargetedDependenciesSnapshot? snapshot = GetSnapshot(dependency); if (snapshot != null && snapshot.HasUnresolvedDependency) { context.Accept(dependency.ToUnresolved(ProjectReference.SchemaName)); @@ -56,7 +56,7 @@ public override void BeforeAddOrUpdate( context.Accept(dependency); } - private ITargetedDependenciesSnapshot GetSnapshot(IDependency dependency) + private ITargetedDependenciesSnapshot? GetSnapshot(IDependency dependency) { IDependenciesSnapshot snapshot = AggregateSnapshotProvider.GetSnapshotProvider(dependency.FullPath)?.CurrentSnapshot; @@ -66,7 +66,7 @@ private ITargetedDependenciesSnapshot GetSnapshot(IDependency dependency) return null; } - ITargetFramework targetFramework = TargetFrameworkProvider.GetNearestFramework( + ITargetFramework? targetFramework = TargetFrameworkProvider.GetNearestFramework( dependency.TargetFramework, snapshot.Targets.Keys); if (targetFramework == null) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/IDependenciesSnapshot.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/IDependenciesSnapshot.cs index 973b02d51d2..fcaf4905839 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/IDependenciesSnapshot.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/IDependenciesSnapshot.cs @@ -40,6 +40,6 @@ internal interface IDependenciesSnapshot : IEquatable /// If , search is first performed on top level /// dependencies before searching all dependencies. /// The if found, otherwise . - IDependency FindDependency(string dependencyId, bool topLevel = false); + IDependency? FindDependency(string dependencyId, bool topLevel = false); } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/IDependency.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/IDependency.cs index fcfe8a68cf2..539b658fd11 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/IDependency.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/IDependency.cs @@ -37,12 +37,12 @@ internal interface IDependency : IEquatable, IDependencyModel /// of IDependency with new properties set. /// IDependency SetProperties( - string caption = null, + string? caption = null, bool? resolved = null, ProjectTreeFlags? flags = null, - string schemaName = null, - IImmutableList dependencyIDs = null, - DependencyIconSet iconSet = null, + string? schemaName = null, + IImmutableList? dependencyIDs = null, + DependencyIconSet? iconSet = null, bool? isImplicit = null); } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/IDependencyExtensions.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/IDependencyExtensions.cs index 2a95d1fd076..758b8c50801 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/IDependencyExtensions.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/IDependencyExtensions.cs @@ -96,8 +96,8 @@ public static bool HasSameTarget(this IDependency self, IDependency other) public static IDependency ToResolved( this IDependency dependency, - string schemaName = null, - IImmutableList dependencyIDs = null) + string? schemaName = null, + IImmutableList? dependencyIDs = null) { return dependency.SetProperties( resolved: true, @@ -108,8 +108,8 @@ public static IDependency ToResolved( public static IDependency ToUnresolved( this IDependency dependency, - string schemaName = null, - IImmutableList dependencyIDs = null) + string? schemaName = null, + IImmutableList? dependencyIDs = null) { return dependency.SetProperties( resolved: false, diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/TargetedDependenciesSnapshot.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/TargetedDependenciesSnapshot.cs index 778eb9742e2..fc7f98f71e5 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/TargetedDependenciesSnapshot.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/TargetedDependenciesSnapshot.cs @@ -14,7 +14,7 @@ internal sealed class TargetedDependenciesSnapshot : ITargetedDependenciesSnapsh { #region Factories and internal constructor - public static ITargetedDependenciesSnapshot CreateEmpty(string projectPath, ITargetFramework targetFramework, IProjectCatalogSnapshot catalogs) + public static ITargetedDependenciesSnapshot CreateEmpty(string projectPath, ITargetFramework targetFramework, IProjectCatalogSnapshot? catalogs) { return new TargetedDependenciesSnapshot( projectPath, @@ -32,10 +32,10 @@ public static ITargetedDependenciesSnapshot FromChanges( string projectPath, ITargetedDependenciesSnapshot previousSnapshot, IDependenciesChanges changes, - IProjectCatalogSnapshot catalogs, + IProjectCatalogSnapshot? catalogs, ImmutableArray snapshotFilters, IReadOnlyDictionary subTreeProviderByProviderType, - IImmutableSet projectItemSpecs) + IImmutableSet? projectItemSpecs) { Requires.NotNullOrWhiteSpace(projectPath, nameof(projectPath)); Requires.NotNull(previousSnapshot, nameof(previousSnapshot)); @@ -167,7 +167,7 @@ void Add(AddDependencyContext context, IDependencyModel dependencyModel) internal TargetedDependenciesSnapshot( string projectPath, ITargetFramework targetFramework, - IProjectCatalogSnapshot catalogs, + IProjectCatalogSnapshot? catalogs, ImmutableDictionary dependenciesWorld) { Requires.NotNullOrEmpty(projectPath, nameof(projectPath)); @@ -220,7 +220,7 @@ internal TargetedDependenciesSnapshot( public ITargetFramework TargetFramework { get; } /// - public IProjectCatalogSnapshot Catalogs { get; } + public IProjectCatalogSnapshot? Catalogs { get; } /// public ImmutableArray TopLevelDependencies { get; } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Subscriptions/DependencyRulesSubscriber.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Subscriptions/DependencyRulesSubscriber.cs index 306bfaf1e1f..1923678d26d 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Subscriptions/DependencyRulesSubscriber.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Subscriptions/DependencyRulesSubscriber.cs @@ -22,13 +22,13 @@ internal sealed class DependencyRulesSubscriber : OnceInitializedOnceDisposed, I public const string DependencyRulesSubscriberContract = "DependencyRulesSubscriberContract"; #pragma warning disable CA2213 // OnceInitializedOnceDisposedAsync are not tracked correctly by the IDisposeable analyzer - private DisposableBag _subscriptions; + private DisposableBag? _subscriptions; #pragma warning restore CA2213 private readonly IUnconfiguredProjectCommonServices _commonServices; private readonly IProjectAsynchronousTasksService _tasksService; private readonly IDependencyTreeTelemetryService _treeTelemetryService; private ICrossTargetSubscriptionsHost _host; - private AggregateCrossTargetProjectContext _currentProjectContext; + private AggregateCrossTargetProjectContext? _currentProjectContext; [ImportMany(DependencyRulesSubscriberContract)] private readonly OrderPrecedenceImportCollection _handlers; @@ -204,14 +204,14 @@ private async Task HandleAsync( IProjectCatalogSnapshot catalogSnapshot, RuleHandlerType handlerType) { - AggregateCrossTargetProjectContext currentAggregateContext = await _host.GetCurrentAggregateProjectContext(); + AggregateCrossTargetProjectContext? currentAggregateContext = await _host.GetCurrentAggregateProjectContext(); if (currentAggregateContext == null || _currentProjectContext != currentAggregateContext) { return; } // Get the inner workspace project context to update for this change. - ITargetFramework targetFrameworkToUpdate = currentAggregateContext.GetProjectFramework(projectUpdate.ProjectConfiguration); + ITargetFramework? targetFrameworkToUpdate = currentAggregateContext.GetProjectFramework(projectUpdate.ProjectConfiguration); if (targetFrameworkToUpdate == null) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Subscriptions/DependencySubscriptionsHost.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Subscriptions/DependencySubscriptionsHost.cs index c28f3a372e1..4529a36f28e 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Subscriptions/DependencySubscriptionsHost.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Subscriptions/DependencySubscriptionsHost.cs @@ -283,11 +283,11 @@ private void OnSubtreeProviderDependenciesChanged(object sender, DependenciesCha private void UpdateDependenciesSnapshot( ImmutableDictionary changes, - IProjectCatalogSnapshot catalogs, - ITargetFramework activeTargetFramework, + IProjectCatalogSnapshot? catalogs, + ITargetFramework? activeTargetFramework, CancellationToken token) { - IImmutableSet projectItemSpecs = GetProjectItemSpecsFromSnapshot(); + IImmutableSet? projectItemSpecs = GetProjectItemSpecsFromSnapshot(); bool anyChanges = false; @@ -322,7 +322,7 @@ private void UpdateDependenciesSnapshot( return; // Gets the set of items defined directly the project, and not included by imports. - IImmutableSet GetProjectItemSpecsFromSnapshot() + IImmutableSet? GetProjectItemSpecsFromSnapshot() { // We don't have catalog snapshot, we're likely updating because one of our project // dependencies changed. Just return 'no data' @@ -372,7 +372,7 @@ private void ScheduleDependenciesUpdate(CancellationToken token = default) }, token); } - public async Task GetCurrentAggregateProjectContext() + public async Task GetCurrentAggregateProjectContext() { if (IsDisposing || IsDisposed) { @@ -468,7 +468,7 @@ private Task UpdateProjectContextAsync() if (!previousContext.IsCrossTargeting) { - ITargetFramework newTargetFramework = _targetFrameworkProvider.GetTargetFramework((string)await projectProperties.TargetFramework.GetValueAsync()); + ITargetFramework? newTargetFramework = _targetFrameworkProvider.GetTargetFramework((string)await projectProperties.TargetFramework.GetValueAsync()); if (previousContext.ActiveTargetFramework.Equals(newTargetFramework)) { return previousContext; diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Subscriptions/RuleHandlers/PackageRuleHandler.PackageDependencyMetadata.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Subscriptions/RuleHandlers/PackageRuleHandler.PackageDependencyMetadata.cs index f6aad59e729..d47ce1a1897 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Subscriptions/RuleHandlers/PackageRuleHandler.PackageDependencyMetadata.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Subscriptions/RuleHandlers/PackageRuleHandler.PackageDependencyMetadata.cs @@ -87,7 +87,7 @@ public static bool TryGetMetadata( return false; } - ITargetFramework packageTargetFramework = targetFrameworkProvider.GetTargetFramework(target); + ITargetFramework? packageTargetFramework = targetFrameworkProvider.GetTargetFramework(target); if (packageTargetFramework?.Equals(targetFramework) != true) { @@ -118,7 +118,7 @@ public static bool TryGetMetadata( string GetTargetFromDependencyId(string dependencyId) { - string firstPart = new LazyStringSplit(dependencyId, '/').FirstOrDefault(); + string? firstPart = new LazyStringSplit(dependencyId, '/').FirstOrDefault(); if (firstPart == null) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Subscriptions/RuleHandlers/PackageRuleHandler.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Subscriptions/RuleHandlers/PackageRuleHandler.cs index 8b58d60bc62..899438a1fc7 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Subscriptions/RuleHandlers/PackageRuleHandler.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Subscriptions/RuleHandlers/PackageRuleHandler.cs @@ -86,7 +86,7 @@ private void HandleChangesForRule( CrossTargetDependenciesChangesBuilder changesBuilder, ITargetFramework targetFramework, bool resolved, - HashSet unresolvedChanges = null) + HashSet? unresolvedChanges = null) { Requires.NotNull(targetFramework, nameof(targetFramework)); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/TreeViewProviderBase.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/TreeViewProviderBase.cs index 3875c95bb00..a4d3eac999d 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/TreeViewProviderBase.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/TreeViewProviderBase.cs @@ -32,7 +32,7 @@ public abstract Task BuildTreeAsync( IDependenciesSnapshot snapshot, CancellationToken cancellationToken = default); - public abstract IProjectTree FindByPath(IProjectTree root, string path); + public abstract IProjectTree? FindByPath(IProjectTree root, string path); protected ProjectTreeCustomizablePropertyContext GetCustomPropertyContext(IProjectTree parent) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/UI/IDialogServices.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/UI/IDialogServices.cs index d68be523e01..f86f6f3aef9 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/UI/IDialogServices.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/UI/IDialogServices.cs @@ -8,6 +8,6 @@ namespace Microsoft.VisualStudio.ProjectSystem.VS.UI /// internal interface IDialogServices { - bool DontShowAgainMessageBox(string caption, string message, string checkboxText, bool initialStateOfCheckbox, string learnMoreText, string learnMoreUrl); + bool DontShowAgainMessageBox(string caption, string message, string? checkboxText, bool initialStateOfCheckbox, string learnMoreText, string learnMoreUrl); } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/UI/IVsShellUtilitiesHelper.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/UI/IVsShellUtilitiesHelper.cs index 96c44338666..5e041594cff 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/UI/IVsShellUtilitiesHelper.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/UI/IVsShellUtilitiesHelper.cs @@ -13,8 +13,8 @@ internal interface IVsShellUtilitiesHelper /// /// Returns the version of VS as defined by VSVSAPROPID_ProductSemanticVersion with the trailing sem version stripped, or null on failure. /// - Task GetVSVersionAsync(IVsService vsAppIdService); + Task GetVSVersionAsync(IVsService vsAppIdService); - Task GetLocalAppDataFolderAsync(IVsService vsShellService); + Task GetLocalAppDataFolderAsync(IVsService vsShellService); } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/UI/VsShellUtilitiesHelper.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/UI/VsShellUtilitiesHelper.cs index 157cab21a83..4d2831b2d90 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/UI/VsShellUtilitiesHelper.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/UI/VsShellUtilitiesHelper.cs @@ -26,7 +26,7 @@ public VsShellUtilitiesHelper(IProjectThreadingService threadingService) /// /// /// - public async Task GetVSVersionAsync(IVsService vsAppIdService) + public async Task GetVSVersionAsync(IVsService vsAppIdService) { await _threadingService.SwitchToUIThread(); @@ -51,7 +51,7 @@ public async Task GetVSVersionAsync(IVsService vsAppIdService return null; } - public async Task GetLocalAppDataFolderAsync(IVsService vsShellService) + public async Task GetLocalAppDataFolderAsync(IVsService vsShellService) { await _threadingService.SwitchToUIThread(); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Utilities/MetadataExtensions.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Utilities/MetadataExtensions.cs index fc9327ac61e..dc02a4e0414 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Utilities/MetadataExtensions.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Utilities/MetadataExtensions.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Immutable; - +using System.Runtime.CompilerServices; using Microsoft.VisualStudio.ProjectSystem.Properties; namespace Microsoft.VisualStudio.ProjectSystem.VS.Utilities @@ -15,7 +15,7 @@ internal static class MetadataExtensions /// Resolved reference project items snapshot to search. /// The unresolved reference item name. /// The key is item name and the value is the metadata dictionary. - public static IImmutableDictionary GetProjectItemProperties(this IProjectRuleSnapshot projectRuleSnapshot, string itemSpec) + public static IImmutableDictionary? GetProjectItemProperties(this IProjectRuleSnapshot projectRuleSnapshot, string itemSpec) { Requires.NotNull(projectRuleSnapshot, nameof(projectRuleSnapshot)); Requires.NotNullOrEmpty(itemSpec, nameof(itemSpec)); @@ -35,7 +35,7 @@ public static IImmutableDictionary GetProjectItemProperties(this /// The key that identifies the property to look up. /// The value of the string if found and non-empty, otherwise . /// if the property was found with a non-empty value, otherwise . - public static bool TryGetStringProperty(this IImmutableDictionary properties, string key, out string stringValue) + public static bool TryGetStringProperty(this IImmutableDictionary properties, string key, [NotNullWhenTrue]out string? stringValue) { if (properties != null && properties.TryGetValue(key, out stringValue) && @@ -54,9 +54,9 @@ public static bool TryGetStringProperty(this IImmutableDictionaryThe property dictionary to query. /// The key that identifies the property to look up. /// The string value if found and non-empty, otherwise . - public static string GetStringProperty(this IImmutableDictionary properties, string key) + public static string? GetStringProperty(this IImmutableDictionary properties, string key) { - return properties.TryGetStringProperty(key, out string value) && !string.IsNullOrEmpty(value) ? value : null; + return properties.TryGetStringProperty(key, out string? value) && !string.IsNullOrEmpty(value) ? value : null; } /// @@ -68,7 +68,7 @@ public static string GetStringProperty(this IImmutableDictionary /// if the property was found with successfully parsed as a boolean, otherwise . public static bool TryGetBoolProperty(this IImmutableDictionary properties, string key, out bool boolValue) { - if (properties.TryGetStringProperty(key, out string valueString) && + if (properties.TryGetStringProperty(key, out string? valueString) && bool.TryParse(valueString, out boolValue)) { return true; @@ -99,7 +99,7 @@ public static bool TryGetBoolProperty(this IImmutableDictionary /// The enum type. public static bool TryGetEnumProperty(this IImmutableDictionary properties, string key, out T enumValue) where T : struct, Enum { - if (properties.TryGetStringProperty(key, out string valueString) && + if (properties.TryGetStringProperty(key, out string? valueString) && Enum.TryParse(valueString, ignoreCase: true, out enumValue)) { return true; diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Utilities/NameValuePair.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Utilities/NameValuePair.cs index f0a10c1ae1a..992af424969 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Utilities/NameValuePair.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Utilities/NameValuePair.cs @@ -11,19 +11,19 @@ namespace Microsoft.VisualStudio.ProjectSystem.VS.Utilities internal class NameValuePair : INotifyPropertyChanged, IDataErrorInfo { - public ObservableList ParentCollection; + public ObservableList? ParentCollection; public bool HasValidationError { get; set; } - public NameValuePair(ObservableList parentCollection = null) { ParentCollection = parentCollection; } + public NameValuePair(ObservableList? parentCollection = null) { ParentCollection = parentCollection; } - public NameValuePair(string name, string value, ObservableList parentCollection = null) + public NameValuePair(string name, string value, ObservableList? parentCollection = null) { ParentCollection = parentCollection; Name = name; Value = value; } - public NameValuePair(NameValuePair nvPair, ObservableList parentCollection = null) + public NameValuePair(NameValuePair nvPair, ObservableList? parentCollection = null) { ParentCollection = parentCollection; Name = nvPair.Name; @@ -46,7 +46,7 @@ public string Value public event PropertyChangedEventHandler PropertyChanged; - public bool NotifyPropertyChanged(ref T refProperty, T value, [CallerMemberName] string propertyName = null) + public bool NotifyPropertyChanged(ref T refProperty, T value, [CallerMemberName] string? propertyName = null) { if (!Equals(refProperty, value)) { @@ -58,7 +58,7 @@ public bool NotifyPropertyChanged(ref T refProperty, T value, [CallerMemberNa return false; } - public void NotifyPropertyChanged(string propertyName) + public void NotifyPropertyChanged(string? propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } @@ -74,12 +74,12 @@ public string Error } } - public string this[string propertyName] + public string? this[string propertyName] { get { //Reset error condition - string error = null; + string? error = null; HasValidationError = false; if (propertyName.Equals("Name", StringComparison.OrdinalIgnoreCase)) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Utilities/ObservableList.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Utilities/ObservableList.cs index b777778d7d0..ea338c64d6f 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Utilities/ObservableList.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Utilities/ObservableList.cs @@ -9,7 +9,7 @@ namespace Microsoft.VisualStudio.ProjectSystem.VS.Utilities { internal class ObservableList : ObservableCollection { - public event EventHandler ValidationStatusChanged; + public event EventHandler ValidationStatusChanged; public ObservableList() { @@ -24,7 +24,9 @@ public ObservableList(List list) } foreach (INotifyPropertyChanged item in list) +#pragma warning disable CS8602 // Workaround https://github.com/dotnet/roslyn/issues/31891 item.PropertyChanged += OnItemPropertyChanged; +#pragma warning restore CS8602 } private void OnItemPropertyChanged(object sender, PropertyChangedEventArgs e) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Utilities/Web/RemoteCacheFile.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Utilities/Web/RemoteCacheFile.cs index 40d6064796d..3db19e7fee8 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Utilities/Web/RemoteCacheFile.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Utilities/Web/RemoteCacheFile.cs @@ -34,7 +34,7 @@ public bool CacheFileIsStale() /// /// If the cached file exists reads the data and returns it as a string /// - public string ReadCacheFile() + public string? ReadCacheFile() { try { @@ -54,7 +54,7 @@ public string ReadCacheFile() /// /// Downloads from the downloadUri to the cached file. /// - public async Task TryToUpdateCacheFileAsync(Action callBackOnSuccess = null) + public async Task TryToUpdateCacheFileAsync(Action? callBackOnSuccess = null) { try { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Utilities/WpfHelper.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Utilities/WpfHelper.cs index 04c8f48d093..1dd8df363b9 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Utilities/WpfHelper.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Utilities/WpfHelper.cs @@ -7,21 +7,21 @@ namespace Microsoft.VisualStudio.ProjectSystem.VS.Utilities [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] internal static class WpfHelper { - public static DataGridCell GetCell(DataGrid dataGrid, int row, int column) + public static DataGridCell? GetCell(DataGrid dataGrid, int row, int column) { DataGridRow rowContainer = GetRow(dataGrid, row); if (rowContainer != null) { - DataGridCellsPresenter presenter = GetVisualChild(rowContainer); + DataGridCellsPresenter? presenter = GetVisualChild(rowContainer); // try to get the cell but it may possibly be virtualized - var cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column); + var cell = (DataGridCell?)presenter?.ItemContainerGenerator.ContainerFromIndex(column); if (cell == null) { // now try to bring into view and retrieve the cell dataGrid.ScrollIntoView(rowContainer, dataGrid.Columns[column]); - cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column); + cell = (DataGridCell?)presenter?.ItemContainerGenerator.ContainerFromIndex(column); } return cell; } @@ -40,7 +40,7 @@ public static DataGridRow GetRow(DataGrid dataGrid, int index) return row; } - public static T GetVisualChild(Visual parent) where T : Visual + public static T? GetVisualChild(Visual parent) where T : Visual { var child = default(T); int numVisuals = VisualTreeHelper.GetChildrenCount(parent); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/VsSolutionEventListener.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/VsSolutionEventListener.cs index 5bf4ab28faf..dc36eee6bfe 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/VsSolutionEventListener.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/VsSolutionEventListener.cs @@ -62,7 +62,7 @@ protected override async Task DisposeCoreAsync(bool initialized) public int OnAfterOpenProject(IVsHierarchy pHierarchy, int fAdded) { - UnconfiguredProjectTasksService tasksService = GetUnconfiguredProjectTasksServiceIfApplicable(pHierarchy); + UnconfiguredProjectTasksService? tasksService = GetUnconfiguredProjectTasksServiceIfApplicable(pHierarchy); tasksService?.OnProjectLoadedInHost(); return HResult.OK; @@ -70,13 +70,13 @@ public int OnAfterOpenProject(IVsHierarchy pHierarchy, int fAdded) public int PrioritizedOnAfterOpenProject(IVsHierarchy pHierarchy, int fAdded) { - UnconfiguredProjectTasksService tasksService = GetUnconfiguredProjectTasksServiceIfApplicable(pHierarchy); + UnconfiguredProjectTasksService? tasksService = GetUnconfiguredProjectTasksServiceIfApplicable(pHierarchy); tasksService?.OnPrioritizedProjectLoadedInHost(); return HResult.OK; } - private static UnconfiguredProjectTasksService GetUnconfiguredProjectTasksServiceIfApplicable(IVsHierarchy hierarchy) + private static UnconfiguredProjectTasksService? GetUnconfiguredProjectTasksServiceIfApplicable(IVsHierarchy hierarchy) { if (hierarchy is IVsBrowseObjectContext context) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/Shell/Interop/VsHierarchyExtensions.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/Shell/Interop/VsHierarchyExtensions.cs index e12d1f54bed..9aca31c4fb1 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/Shell/Interop/VsHierarchyExtensions.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/Shell/Interop/VsHierarchyExtensions.cs @@ -86,14 +86,14 @@ public static int GetProperty(this IVsHierarchy hierarchy, HierarchyId item, /// /// Convenient way to get to the UnconfiguredProject from the hierarchy /// - public static UnconfiguredProject GetUnconfiguredProject(this IVsHierarchy hierarchy) + public static UnconfiguredProject? GetUnconfiguredProject(this IVsHierarchy hierarchy) { UIThreadHelper.VerifyOnUIThread(); var context = hierarchy as IVsBrowseObjectContext; if (context == null) { - EnvDTE.Project dteProject = hierarchy.GetDTEProject(); + EnvDTE.Project? dteProject = hierarchy.GetDTEProject(); if (dteProject != null) { context = dteProject.Object as IVsBrowseObjectContext; @@ -106,7 +106,7 @@ public static UnconfiguredProject GetUnconfiguredProject(this IVsHierarchy hiera /// /// Returns EnvDTE.Project object for the hierarchy /// - public static EnvDTE.Project GetDTEProject(this IVsHierarchy hierarchy) + public static EnvDTE.Project? GetDTEProject(this IVsHierarchy hierarchy) { UIThreadHelper.VerifyOnUIThread(); if (ErrorHandler.Succeeded(hierarchy.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out object extObject))) @@ -120,7 +120,7 @@ public static EnvDTE.Project GetDTEProject(this IVsHierarchy hierarchy) /// /// Returns the path to the project file. Assumes the hierarchy implements IVsProject. Returns null on failure /// - public static string GetProjectFilePath(this IVsHierarchy hierarchy) + public static string? GetProjectFilePath(this IVsHierarchy hierarchy) { if (ErrorHandler.Succeeded(((IVsProject)hierarchy).GetMkDocument(VSConstants.VSITEMID_ROOT, out string projectPath))) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/Shell/ServiceProviderToOleServiceProviderAdapter.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/Shell/ServiceProviderToOleServiceProviderAdapter.cs index ee716dc5e24..026b2be7a02 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/Shell/ServiceProviderToOleServiceProviderAdapter.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/Shell/ServiceProviderToOleServiceProviderAdapter.cs @@ -1,6 +1,7 @@ // 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.Runtime.CompilerServices; using System.Runtime.InteropServices; using Microsoft.VisualStudio.ProjectSystem.VS; @@ -27,7 +28,7 @@ public int QueryService(ref Guid guidService, ref Guid riid, out IntPtr ppvObjec { ppvObject = IntPtr.Zero; - if (!TryGetService(guidService, out object service)) + if (!TryGetService(guidService, out object? service)) { return HResult.NoInterface; } @@ -35,7 +36,7 @@ public int QueryService(ref Guid guidService, ref Guid riid, out IntPtr ppvObjec return GetComInterfaceForObject(service, riid, out ppvObject); } - private bool TryGetService(Guid riid, out object service) + private bool TryGetService(Guid riid, [NotNullWhenTrue]out object? service) { var serviceType = Type.GetTypeFromCLSID(riid, throwOnError: true); // Should only throw on OOM according to MSDN diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/ILaunchSettingsUIProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/ILaunchSettingsUIProvider.cs index 6094ffd57cc..aa934e77eeb 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/ILaunchSettingsUIProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/ILaunchSettingsUIProvider.cs @@ -45,7 +45,7 @@ public interface ILaunchSettingsUIProvider /// null if there are no custom controls but still want to add a new command to the list. Example is the Executable and Project /// commands. Neither provide custom controls (though arguable executable should). /// - UserControl CustomUI { get; } + UserControl? CustomUI { get; } /// /// Called when the selected profile changes to a profile which matches this command. curSettings will contain diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ICreateFileFromTemplateService.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ICreateFileFromTemplateService.cs index aee12265a0b..2559b351d9a 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ICreateFileFromTemplateService.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ICreateFileFromTemplateService.cs @@ -16,6 +16,6 @@ internal interface ICreateFileFromTemplateService /// The path to the node to which the new file will be added. /// The name of the file to be created. /// true if file is added successfully. - Task CreateFileAsync(string templateFile, string? parentDocumentMoniker, string fileName); + Task CreateFileAsync(string templateFile, string parentDocumentMoniker, string fileName); } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/AssemblyAttributeProperties/AbstractProjectFileOrAssemblyInfoPropertiesProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/AssemblyAttributeProperties/AbstractProjectFileOrAssemblyInfoPropertiesProvider.cs index 5f129d71bf6..6a8463fe6bd 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/AssemblyAttributeProperties/AbstractProjectFileOrAssemblyInfoPropertiesProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/AssemblyAttributeProperties/AbstractProjectFileOrAssemblyInfoPropertiesProvider.cs @@ -14,7 +14,7 @@ namespace Microsoft.VisualStudio.ProjectSystem.Properties internal abstract class AbstractProjectFileOrAssemblyInfoPropertiesProvider : DelegatedProjectPropertiesProviderBase { private readonly ImmutableArray> _interceptingValueProviders; - private readonly Func _getActiveProjectId; + private readonly Func _getActiveProjectId; private readonly Workspace _workspace; private readonly IProjectThreadingService _threadingService; @@ -23,7 +23,7 @@ protected AbstractProjectFileOrAssemblyInfoPropertiesProvider( IProjectInstancePropertiesProvider instanceProvider, IEnumerable> interceptingValueProviders, UnconfiguredProject project, - Func getActiveProjectId, + Func getActiveProjectId, Workspace workspace, IProjectThreadingService threadingService) : base(delegatedProvider, instanceProvider, project) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/AssemblyAttributeProperties/AssemblyInfoProperties.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/AssemblyAttributeProperties/AssemblyInfoProperties.cs index 32424010e22..0a5e1d8a336 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/AssemblyAttributeProperties/AssemblyInfoProperties.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/AssemblyAttributeProperties/AssemblyInfoProperties.cs @@ -32,7 +32,7 @@ internal class AssemblyInfoProperties : DelegatedProjectPropertiesBase public AssemblyInfoProperties( IProjectProperties delegatedProjectProperties, - Func getActiveProjectId, + Func getActiveProjectId, Workspace workspace, IProjectThreadingService threadingService) : base(delegatedProjectProperties) @@ -41,7 +41,7 @@ public AssemblyInfoProperties( } private static ImmutableDictionary CreateAttributeValueProviderMap( - Func getActiveProjectId, + Func getActiveProjectId, Workspace workspace, IProjectThreadingService threadingService) { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/AssemblyAttributeProperties/SourceAssemblyAttributePropertyValueProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/AssemblyAttributeProperties/SourceAssemblyAttributePropertyValueProvider.cs index e3aeef539b5..82279268407 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/AssemblyAttributeProperties/SourceAssemblyAttributePropertyValueProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Properties/AssemblyAttributeProperties/SourceAssemblyAttributePropertyValueProvider.cs @@ -17,13 +17,13 @@ namespace Microsoft.VisualStudio.ProjectSystem.Properties internal class SourceAssemblyAttributePropertyValueProvider { private readonly string _assemblyAttributeFullName; - private readonly Func _getActiveProjectId; + private readonly Func _getActiveProjectId; private readonly Workspace _workspace; private readonly IProjectThreadingService _threadingService; public SourceAssemblyAttributePropertyValueProvider( string assemblyAttributeFullName, - Func getActiveProjectId, + Func getActiveProjectId, Workspace workspace, IProjectThreadingService threadingService) { @@ -35,7 +35,7 @@ public SourceAssemblyAttributePropertyValueProvider( private Project? GetActiveProject() { - ProjectId activeProjectId = _getActiveProjectId(); + ProjectId? activeProjectId = _getActiveProjectId(); if (activeProjectId == null) { return null; diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/SpecialFileProviders/ISpecialFilesManager.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/SpecialFileProviders/ISpecialFilesManager.cs index 91453495558..f6349a1e778 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/SpecialFileProviders/ISpecialFilesManager.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/SpecialFileProviders/ISpecialFilesManager.cs @@ -23,6 +23,6 @@ internal interface ISpecialFilesManager /// The file name of the special file, or if special file is not /// handled by the project. /// - Task GetFileAsync(SpecialFiles fileId, SpecialFileFlags flags); + Task GetFileAsync(SpecialFiles fileId, SpecialFileFlags flags); } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/StringComparers.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/StringComparers.cs index b444a6bb805..a469c0580b1 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/StringComparers.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/StringComparers.cs @@ -13,7 +13,7 @@ namespace Microsoft.VisualStudio /// internal static class StringComparers { - public static IEqualityComparer WorkspaceProjectContextIds => StringComparer.Ordinal; + public static IEqualityComparer WorkspaceProjectContextIds => StringComparer.Ordinal; public static IEqualityComparer Paths => StringComparer.OrdinalIgnoreCase; public static IEqualityComparer PropertyNames => StringComparer.OrdinalIgnoreCase; public static IEqualityComparer PropertyValues => StringComparer.OrdinalIgnoreCase; From b20fc0125629dc9c508419f6ea58148a0dd0152d Mon Sep 17 00:00:00 2001 From: Kevin Pilch Date: Mon, 17 Dec 2018 17:43:26 -0800 Subject: [PATCH 13/20] More --- .../Dependencies/Subscriptions/DependenciesChangesBuilder.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Subscriptions/DependenciesChangesBuilder.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Subscriptions/DependenciesChangesBuilder.cs index 5cf46ca430a..53d49d546fa 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Subscriptions/DependenciesChangesBuilder.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Subscriptions/DependenciesChangesBuilder.cs @@ -9,8 +9,8 @@ namespace Microsoft.VisualStudio.ProjectSystem.VS.Tree.Dependencies.Subscription { internal sealed class DependenciesChangesBuilder { - private HashSet _added; - private HashSet _removed; + private HashSet? _added; + private HashSet? _removed; public void Added(IDependencyModel model) { From db9df886f343b69eab8bdeacf69e1a6878adddac Mon Sep 17 00:00:00 2001 From: Kevin Pilch Date: Tue, 18 Dec 2018 11:23:45 -0800 Subject: [PATCH 14/20] Explicitly test for null items in ObservableList --- .../ProjectSystem/VS/Utilities/ObservableList.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Utilities/ObservableList.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Utilities/ObservableList.cs index ea338c64d6f..6e6c83ef62a 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Utilities/ObservableList.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Utilities/ObservableList.cs @@ -24,9 +24,12 @@ public ObservableList(List list) } foreach (INotifyPropertyChanged item in list) -#pragma warning disable CS8602 // Workaround https://github.com/dotnet/roslyn/issues/31891 - item.PropertyChanged += OnItemPropertyChanged; -#pragma warning restore CS8602 + { + if (item != null) + { + item.PropertyChanged += OnItemPropertyChanged; + } + } } private void OnItemPropertyChanged(object sender, PropertyChangedEventArgs e) From 9af82b57158290040aecaf3b3034b9a0816e127b Mon Sep 17 00:00:00 2001 From: Kevin Pilch Date: Wed, 19 Dec 2018 06:52:21 -0800 Subject: [PATCH 15/20] Downgrade more warnings --- src/Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 9efc21cf592..09fd29dabab 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -26,7 +26,7 @@ 8.0 strict - $(WarningsNotAsErrors);8600;8601;8602;8603;8604;8618;8619;8620;8622;8625;8626;8629 + $(WarningsNotAsErrors);8600;8601;8602;8603;8604;8608;8610;8612;8614;8618;8619;8620;8622;8625;8626;8629 From 86fe7ed095b1b290342f981f4cda094aa8428f49 Mon Sep 17 00:00:00 2001 From: Kevin Pilch Date: Wed, 19 Dec 2018 09:05:22 -0800 Subject: [PATCH 16/20] Fix some things found in review --- .../ConfiguredProjectImplicitActivationTracking.cs | 4 +--- .../ProjectSystem/Debug/LaunchSettingsProvider.cs | 9 +++------ .../ProjectSystem/UnconfiguredProjectTasksService.cs | 8 ++++---- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ConfiguredProjectImplicitActivationTracking.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ConfiguredProjectImplicitActivationTracking.cs index 320938f0b28..be11ca33835 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ConfiguredProjectImplicitActivationTracking.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ConfiguredProjectImplicitActivationTracking.cs @@ -22,7 +22,7 @@ internal class ConfiguredProjectImplicitActivationTracking : OnceInitializedOnce private readonly IProjectAsynchronousTasksService _tasksService; private readonly IActiveConfigurationGroupService _activeConfigurationGroupService; private readonly ITargetBlock>> _targetBlock; - private TaskCompletionSource _isImplicitlyActiveSource = new TaskCompletionSource(); + private TaskCompletionSource _isImplicitlyActiveSource = new TaskCompletionSource(); private IDisposable? _subscription; [ImportingConstructor] @@ -121,9 +121,7 @@ private Task OnActiveConfigurationsChanged(IProjectVersionedValue tasks = ImplicitlyActiveServices.Select(c => c.Value.ActivateAsync()); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/LaunchSettingsProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/LaunchSettingsProvider.cs index 4f8913ccaff..ae83abe4e01 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/LaunchSettingsProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/LaunchSettingsProvider.cs @@ -318,13 +318,10 @@ protected static void MergeExistingInMemoryProfiles(LaunchSettingsData newSnapsh // Does it already have one with this name? if (newSnapshot.Profiles.FirstOrDefault(p => LaunchProfile.IsSameProfileName(p.Name, profile.Name)) == null) { + System.Diagnostics.Debug.Assert(newSnapshot.Profiles != null, $"{nameof(Enumerable.FirstOrDefault)} should have thrown"); + // Create a new one from the existing in-memory profile and insert it in the same location, or the end if it // is beyond the end of the list - if (newSnapshot.Profiles == null) - { - newSnapshot.Profiles = new List(1); - } - if (i > newSnapshot.Profiles.Count) { newSnapshot.Profiles.Add(LaunchProfileData.FromILaunchProfile(profile)); @@ -638,7 +635,7 @@ private void LaunchSettingsFile_Changed(object sender, FileSystemEventArgs e) } // Updates need to be sequenced - return sequentialTaskQueue.ExecuteTask((() => UpdateProfilesAsync(null))); + return sequentialTaskQueue.ExecuteTask(() => UpdateProfilesAsync(null)); }).Task; } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/UnconfiguredProjectTasksService.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/UnconfiguredProjectTasksService.cs index 42583369b1e..9613271f393 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/UnconfiguredProjectTasksService.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/UnconfiguredProjectTasksService.cs @@ -18,8 +18,8 @@ internal class UnconfiguredProjectTasksService : IUnconfiguredProjectTasksServic private readonly IProjectAsynchronousTasksService _tasksService; private readonly IProjectThreadingService _threadingService; private readonly ILoadedInHostListener _loadedInHostListener; - private readonly TaskCompletionSource _projectLoadedInHost = new TaskCompletionSource(); - private readonly TaskCompletionSource _prioritizedProjectLoadedInHost = new TaskCompletionSource(); + private readonly TaskCompletionSource _projectLoadedInHost = new TaskCompletionSource(); + private readonly TaskCompletionSource _prioritizedProjectLoadedInHost = new TaskCompletionSource(); private readonly JoinableTaskQueue _prioritizedTaskQueue; [ImportingConstructor] @@ -95,12 +95,12 @@ public Task PrioritizedProjectLoadedInHostAsync(Func action) public void OnProjectLoadedInHost() { - _projectLoadedInHost.SetResult(null!); + _projectLoadedInHost.SetResult(null); } public void OnPrioritizedProjectLoadedInHost() { - _prioritizedProjectLoadedInHost.SetResult(null!); + _prioritizedProjectLoadedInHost.SetResult(null); _threadingService.ExecuteSynchronously(() => _prioritizedTaskQueue.DrainAsync()); } From e69665dbb70ebb8a91884374b6c7ad9da6bd8c20 Mon Sep 17 00:00:00 2001 From: Kevin Pilch Date: Thu, 3 Jan 2019 13:06:51 -0800 Subject: [PATCH 17/20] Clean up places where I incorrectly supressed CS8625 --- .../PooledObjects/ObjectPool.cs | 6 ++--- .../PooledObjects/PooledArray.cs | 23 ------------------- .../AbstractMultiLifetimeComponent.cs | 8 +++---- ...itlyActiveConfiguredProjectReadyToBuild.cs | 8 +++---- .../Threading/Tasks/CancellationSeries.cs | 8 +++---- 5 files changed, 11 insertions(+), 42 deletions(-) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/ObjectPool.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/ObjectPool.cs index 3211bc4678f..b9080d7b125 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/ObjectPool.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/ObjectPool.cs @@ -28,7 +28,7 @@ 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 @@ -90,12 +90,10 @@ 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) { -#pragma warning disable CS8625 // Workaround https://github.com/dotnet/roslyn/issues/31865 if (inst == Interlocked.CompareExchange(ref items[i].Value, null, inst)) -#pragma warning restore CS8625 { return inst; } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledArray.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledArray.cs index ab00f4088c1..8d3a6695bd0 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledArray.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledArray.cs @@ -63,29 +63,6 @@ public T this[int index] } } - /// - /// Write to slot . - /// Fills in unallocated slots preceding the , if any. - /// - public void SetItem(int index, T value) - { - while (index > _builder.Count) - { -#pragma warning disable CS8625 // Workaround https://github.com/dotnet/roslyn/issues/31865 - _builder.Add(default); -#pragma warning restore CS8625 - } - - if (index == _builder.Count) - { - _builder.Add(value); - } - else - { - _builder[index] = value; - } - } - public void Add(T item) => _builder.Add(item); public void Insert(int index, T item) => _builder.Insert(index, item); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/AbstractMultiLifetimeComponent.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/AbstractMultiLifetimeComponent.cs index acfe814c3b9..fce50c96141 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/AbstractMultiLifetimeComponent.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/AbstractMultiLifetimeComponent.cs @@ -14,7 +14,7 @@ namespace Microsoft.VisualStudio.ProjectSystem internal abstract class AbstractMultiLifetimeComponent : OnceInitializedOnceDisposedAsync { private readonly object _lock = new object(); - private TaskCompletionSource _loadedSource = new TaskCompletionSource(); + private TaskCompletionSource _loadedSource = new TaskCompletionSource(); private IMultiLifetimeInstance? _instance; protected AbstractMultiLifetimeComponent(JoinableTaskContextNode joinableTaskContextNode) @@ -49,7 +49,7 @@ public async Task LoadAsync() private async Task LoadCoreAsync() { - TaskCompletionSource? loadedSource = null; + TaskCompletionSource? loadedSource = null; IMultiLifetimeInstance instance; lock (_lock) { @@ -65,9 +65,7 @@ private async Task LoadCoreAsync() // While all callers should wait on InitializeAsync, // only one should complete the completion source await instance.InitializeAsync(); -#pragma warning disable CS8625 // Workaround for https://github.com/dotnet/roslyn/issues/31865 loadedSource?.SetResult(null); -#pragma warning restore CS8625 } public Task UnloadAsync() @@ -80,7 +78,7 @@ public Task UnloadAsync() { instance = _instance; _instance = null; - _loadedSource = new TaskCompletionSource(); + _loadedSource = new TaskCompletionSource(); } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/ImplicitlyActiveConfiguredProjectReadyToBuild.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/ImplicitlyActiveConfiguredProjectReadyToBuild.cs index 60bad173572..a309fff1464 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/ImplicitlyActiveConfiguredProjectReadyToBuild.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/ImplicitlyActiveConfiguredProjectReadyToBuild.cs @@ -14,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( @@ -23,7 +23,7 @@ public ImplicitlyActiveConfiguredProjectReadyToBuild( { _configuredProject = configuredProject; _activeConfiguredProjectProvider = activeConfiguredProjectProvider; - _activationTask = new TaskCompletionSource(); + _activationTask = new TaskCompletionSource(); _activeConfiguredProjectProvider.Changed += ActiveConfiguredProject_Changed; } @@ -43,14 +43,12 @@ private Task GetLatestActivationTask() { if (!nowActive) { - _activationTask = new TaskCompletionSource(); + _activationTask = new TaskCompletionSource(); } } else if (nowActive) { -#pragma warning disable CS8625 // Workaround https://github.com/dotnet/roslyn/issues/31865 _activationTask.TrySetResult(null); -#pragma warning restore CS8625 } return _activationTask.Task; diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Threading/Tasks/CancellationSeries.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Threading/Tasks/CancellationSeries.cs index 0a349dcf59f..29cd68658d1 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Threading/Tasks/CancellationSeries.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Threading/Tasks/CancellationSeries.cs @@ -16,7 +16,7 @@ namespace Microsoft.VisualStudio.Threading.Tasks /// public sealed class CancellationSeries : IDisposable { - private CancellationTokenSource _cts = new CancellationTokenSource(); + private CancellationTokenSource? _cts = new CancellationTokenSource(); private readonly CancellationToken _superToken; @@ -73,7 +73,7 @@ public CancellationToken CreateNext(CancellationToken token = default) // This way we would return a cancelled token, which is reasonable. CancellationToken nextToken = nextSource.Token; - CancellationTokenSource priorSource = Interlocked.Exchange(ref _cts, nextSource); + CancellationTokenSource? priorSource = Interlocked.Exchange(ref _cts, nextSource); if (priorSource == null) { @@ -103,9 +103,7 @@ public void Dispose() GC.SuppressFinalize(this); #endif -#pragma warning disable CS8625 // Workaround https://github.com/dotnet/roslyn/issues/31865 - CancellationTokenSource source = Interlocked.Exchange(ref _cts, null); -#pragma warning restore CS8625 + CancellationTokenSource? source = Interlocked.Exchange(ref _cts, null); if (source == null) { From a314b7cf6885f047055cfb1cbe762490074de503 Mon Sep 17 00:00:00 2001 From: Kevin Pilch Date: Thu, 3 Jan 2019 13:14:06 -0800 Subject: [PATCH 18/20] Remove unused and difficult to annotate method --- .../PooledObjects/PooledArray.cs | 23 ------------------- 1 file changed, 23 deletions(-) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledArray.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledArray.cs index 8d3a6695bd0..1dc46aae82a 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledArray.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/PooledObjects/PooledArray.cs @@ -142,29 +142,6 @@ public void Sort(int startIndex, IComparer comparer) public ImmutableArray ToImmutableOrNull() => Count == 0 ? default : ToImmutable(); - /// - /// Realizes the array, downcasting each element to a derived type. - /// - public ImmutableArray ToDowncastedImmutable() - where U : T - { - if (Count == 0) - { - return ImmutableArray.Empty; - } - - var tmp = PooledArray.GetInstance(Count); - foreach (T i in this) - { -#pragma warning disable CS8600,CS8604 // Workaround for https://github.com/dotnet/roslyn/issues/31866 - tmp.Add((U)i); -#pragma warning restore CS8600,CS8604 - - } - - return tmp.ToImmutableAndFree(); - } - /// /// Realizes the array and disposes the builder in one operation. /// From bd2e5456f1123e46b795ecbd6a986d07af5c5696 Mon Sep 17 00:00:00 2001 From: Kevin Pilch Date: Thu, 3 Jan 2019 14:38:01 -0800 Subject: [PATCH 19/20] More annotations and cleanup --- .../VS/NuGet/ProjectAssetFileWatcher.cs | 25 +++++++----- .../ProjectSystem/VS/NuGet/ProjectProperty.cs | 10 ++++- .../VS/NuGet/ProjectRestoreInfoBuilder.cs | 40 +++++++------------ .../ProjectSystem/VS/NuGet/ReferenceItem.cs | 10 ++++- .../VS/NuGet/ReferenceProperty.cs | 10 ++++- .../VS/NuGet/TargetFrameworkInfo.cs | 20 ++++++++-- 6 files changed, 68 insertions(+), 47 deletions(-) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/ProjectAssetFileWatcher.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/ProjectAssetFileWatcher.cs index 0a3da0d6879..12b0cee79ac 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/ProjectAssetFileWatcher.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/ProjectAssetFileWatcher.cs @@ -32,11 +32,11 @@ internal class ProjectAssetFileWatcher : OnceInitializedOnceDisposedAsync, IVsFr private readonly IActiveConfiguredProjectSubscriptionService _activeConfiguredProjectSubscriptionService; private readonly IProjectTreeProvider _fileSystemTreeProvider; - private CancellationTokenSource _watchedFileResetCancellationToken; - private ITaskDelayScheduler _taskDelayScheduler; - private IDisposable _treeWatcher; + private CancellationTokenSource? _watchedFileResetCancellationToken; + private ITaskDelayScheduler? _taskDelayScheduler; + private IDisposable? _treeWatcher; private uint _filechangeCookie; - private string _fileBeingWatched; + private string? _fileBeingWatched; private byte[]? _previousContentsHash; [ImportingConstructor] @@ -137,7 +137,7 @@ protected override async Task DisposeCoreAsync(bool initialized) if (initialized) { _taskDelayScheduler?.Dispose(); - _treeWatcher.Dispose(); + _treeWatcher?.Dispose(); await UnregisterFileWatcherIfAnyAsync(); } } @@ -167,12 +167,15 @@ protected override async Task DisposeCoreAsync(bool initialized) string? projectFilePath = projectUpdate.CurrentState.GetPropertyOrDefault(ConfigurationGeneral.SchemaName, ConfigurationGeneral.MSBuildProjectFullPathProperty, null); // First check to see if the project has a project.json. - IProjectTree? projectJsonNode = FindProjectJsonNode(newTree, projectFilePath); - if (projectJsonNode != null) + if (projectFilePath != null) { - string projectDirectory = Path.GetDirectoryName(projectFilePath); - string projectLockJsonFilePath = Path.ChangeExtension(PathHelper.Combine(projectDirectory, projectJsonNode.Caption), ".lock.json"); - return projectLockJsonFilePath; + IProjectTree? projectJsonNode = FindProjectJsonNode(newTree, projectFilePath); + if (projectJsonNode != null) + { + string projectDirectory = Path.GetDirectoryName(projectFilePath); + string projectLockJsonFilePath = Path.ChangeExtension(PathHelper.Combine(projectDirectory, projectJsonNode.Caption), ".lock.json"); + return projectLockJsonFilePath; + } } // If there is no project.json then get the patch to obj\project.assets.json file which is generated for projects @@ -206,7 +209,7 @@ protected override async Task DisposeCoreAsync(bool initialized) return null; } - private async Task RegisterFileWatcherAsync(string projectLockJsonFilePath) + private async Task RegisterFileWatcherAsync(string? projectLockJsonFilePath) { // Note file change service is free-threaded if (projectLockJsonFilePath != null) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/ProjectProperty.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/ProjectProperty.cs index 666a1d74683..c2c61d8f5e8 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/ProjectProperty.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/ProjectProperty.cs @@ -6,8 +6,14 @@ namespace Microsoft.VisualStudio.ProjectSystem.VS.NuGet { internal class ProjectProperty : IVsProjectProperty { - public string Name { get; set; } + public ProjectProperty(string name, string value) + { + Name = name; + Value = value; + } - public string Value { get; set; } + public string Name { get; } + + public string Value { get; } } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/ProjectRestoreInfoBuilder.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/ProjectRestoreInfoBuilder.cs index 979050b6728..b4b8bdd2587 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/ProjectRestoreInfoBuilder.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/ProjectRestoreInfoBuilder.cs @@ -64,13 +64,12 @@ internal static class ProjectRestoreInfoBuilder IProjectChangeDescription projectReferencesChanges = update.Value.ProjectChanges[ProjectReference.SchemaName]; IProjectChangeDescription packageReferencesChanges = update.Value.ProjectChanges[PackageReference.SchemaName]; - targetFrameworks.Add(new TargetFrameworkInfo - { - TargetFrameworkMoniker = targetFramework, - ProjectReferences = GetProjectReferences(projectReferencesChanges.After.Items, project), - PackageReferences = GetReferences(packageReferencesChanges.After.Items), - Properties = GetProperties(nugetRestoreChanges.After.Properties) - }); + targetFrameworks.Add(new TargetFrameworkInfo( + targetFramework, + GetProjectReferences(projectReferencesChanges.After.Items, project), + GetReferences(packageReferencesChanges.After.Items), + GetProperties(nugetRestoreChanges.After.Properties) + )); } IProjectChangeDescription toolReferencesChanges = update.Value.ProjectChanges[DotNetCliToolReference.SchemaName]; @@ -105,24 +104,14 @@ internal static class ProjectRestoreInfoBuilder private static IVsProjectProperties GetProperties(IImmutableDictionary items) { - return new ProjectProperties(items.Select(v => new ProjectProperty - { - Name = v.Key, - Value = v.Value - })); + return new ProjectProperties(items.Select(v => new ProjectProperty(v.Key, v.Value))); } private static IVsReferenceItem GetReferenceItem(KeyValuePair> item) { - return new ReferenceItem - { - Name = item.Key, - Properties = new ReferenceProperties(item.Value.Select(v => new ReferenceProperty - { - Name = v.Key, - Value = v.Value - })) - }; + return new ReferenceItem( + item.Key, + new ReferenceProperties(item.Value.Select(v => new ReferenceProperty(v.Key, v.Value)))); } private static IVsReferenceItems GetReferences(IImmutableDictionary> items) @@ -144,11 +133,10 @@ private static IVsReferenceItems GetProjectReferences( ? MakeRooted(definingProjectDirectory.Value, item.Name) : project.MakeRooted(item.Name); - ((ReferenceProperties)item.Properties).Add(new ReferenceProperty - { - Name = ProjectFileFullPathProperty, - Value = projectFileFullPath - }); + ((ReferenceProperties)item.Properties).Add(new ReferenceProperty( + name: ProjectFileFullPathProperty, + value: projectFileFullPath + )); } return referenceItems; diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/ReferenceItem.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/ReferenceItem.cs index 11717eac91c..6b22b61ddc9 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/ReferenceItem.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/ReferenceItem.cs @@ -6,8 +6,14 @@ namespace Microsoft.VisualStudio.ProjectSystem.VS.NuGet { internal class ReferenceItem : IVsReferenceItem { - public string Name { get; set; } + public ReferenceItem(string name, IVsReferenceProperties properties) + { + Name = name; + Properties = properties; + } - public IVsReferenceProperties Properties { get; set; } + public string Name { get; } + + public IVsReferenceProperties Properties { get; } } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/ReferenceProperty.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/ReferenceProperty.cs index 0e509c1e3f4..3c629aaa406 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/ReferenceProperty.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/ReferenceProperty.cs @@ -6,8 +6,14 @@ namespace Microsoft.VisualStudio.ProjectSystem.VS.NuGet { internal class ReferenceProperty : IVsReferenceProperty { - public string Name { get; set; } + public ReferenceProperty(string name, string value) + { + Name = name; + Value = value; + } - public string Value { get; set; } + public string Name { get; } + + public string Value { get; } } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/TargetFrameworkInfo.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/TargetFrameworkInfo.cs index cb697e49c35..cb830022e71 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/TargetFrameworkInfo.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/NuGet/TargetFrameworkInfo.cs @@ -6,12 +6,24 @@ namespace Microsoft.VisualStudio.ProjectSystem.VS.NuGet { internal class TargetFrameworkInfo : IVsTargetFrameworkInfo { - public IVsReferenceItems PackageReferences { get; set; } + public TargetFrameworkInfo( + string targetFrameworkMoniker, + IVsReferenceItems projectReferences, + IVsReferenceItems packageReferences, + IVsProjectProperties properties) + { + TargetFrameworkMoniker = targetFrameworkMoniker; + ProjectReferences = projectReferences; + PackageReferences = packageReferences; + Properties = properties; + } - public IVsReferenceItems ProjectReferences { get; set; } + public IVsReferenceItems PackageReferences { get; } - public IVsProjectProperties Properties { get; set; } + public IVsReferenceItems ProjectReferences { get; } - public string TargetFrameworkMoniker { get; set; } + public IVsProjectProperties Properties { get; } + + public string TargetFrameworkMoniker { get; } } } From 672543b2e05fcfbc2a83b990f7b1fce82e2b7665 Mon Sep 17 00:00:00 2001 From: Kevin Pilch Date: Thu, 3 Jan 2019 14:38:27 -0800 Subject: [PATCH 20/20] More --- .../ProjectSystem/VS/Debug/ProjectDebuggerProvider.cs | 11 +++++++---- .../VS/Input/Commands/StartupProjectHelper.cs | 7 +++++-- .../VS/Logging/ProjectOutputWindowProjectLogger.cs | 4 ++-- .../VS/PropertyPages/DebugPageViewModel.cs | 7 +++++-- .../DesignTimeAssemblyResolution.ResolvedReference.cs | 4 ++-- .../CrossTarget/AggregateCrossTargetProjectContext.cs | 8 ++++---- .../Dependencies/DependenciesProjectTreeProvider.cs | 2 +- .../Actions/CheckChildrenGraphActionHandler.cs | 4 ++-- .../Actions/GetChildrenGraphActionHandler.cs | 4 ++-- .../Actions/TrackChangesGraphActionHandler.cs | 4 ++-- .../GraphNodes/DependenciesGraphProviderFactory.cs | 4 ++-- .../ViewProviders/IDependenciesGraphViewProvider.cs | 2 +- .../ViewProviders/ProjectGraphViewProvider.cs | 2 +- .../Dependencies/Models/AnalyzerDependencyModel.cs | 4 ++-- .../Dependencies/Models/AssemblyDependencyModel.cs | 6 +++--- .../VS/Tree/Dependencies/Models/ComDependencyModel.cs | 4 ++-- .../Tree/Dependencies/Models/DependencyViewModel.cs | 10 +++++----- .../Dependencies/Models/PackageDependencyModel.cs | 10 +++++++--- .../Dependencies/Models/ProjectDependencyModel.cs | 4 ++-- .../Models/SharedProjectDependencyModel.cs | 4 ++-- .../VS/Tree/Dependencies/Snapshot/Dependency.cs | 8 ++++---- .../Filters/DependenciesSnapshotFilterBase.cs | 2 +- .../Filters/DuplicatedDependenciesSnapshotFilter.cs | 2 +- .../Snapshot/Filters/IDependenciesSnapshotFilter.cs | 2 +- .../ImplicitTopLevelDependenciesSnapshotFilter.cs | 2 +- .../SdkAndPackagesDependenciesSnapshotFilter.cs | 2 +- .../Filters/UnresolvedDependenciesSnapshotFilter.cs | 2 +- .../Filters/UnsupportedProjectsSnapshotFilter.cs | 2 +- .../Snapshot/ITargetedDependenciesSnapshot.cs | 2 +- .../Snapshot/TargetedDependenciesSnapshot.cs | 2 +- .../Subscriptions/DependenciesChangesBuilder.cs | 6 +++--- .../DependencySharedProjectsSubscriber.cs | 7 ++++--- .../RuleHandlers/DependenciesRuleHandlerBase.cs | 6 +++--- .../ProjectSystem/VS/UI/DialogServices.cs | 2 +- .../VS/UI/DontShowAgainMessageBox.xaml.cs | 2 +- .../ServiceProviderToOleServiceProviderAdapter.cs | 2 -- .../ConfiguredProjectImplicitActivationTracking.cs | 2 +- .../AbstractSpecialFileProvider.cs | 2 +- 38 files changed, 86 insertions(+), 74 deletions(-) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Debug/ProjectDebuggerProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Debug/ProjectDebuggerProvider.cs index d9438fb44ca..373bacc252b 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Debug/ProjectDebuggerProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Debug/ProjectDebuggerProvider.cs @@ -147,12 +147,15 @@ private async Task> QueryDebugTargetsInterna /// public IDebugProfileLaunchTargetsProvider? GetLaunchTargetsProvider(ILaunchProfile? profile) { - // We search through the imports in order to find the one which supports the profile - foreach (Lazy provider in ProfileLaunchTargetsProviders) + if (profile != null) { - if (provider.Value.SupportsProfile(profile)) + // We search through the imports in order to find the one which supports the profile + foreach (Lazy provider in ProfileLaunchTargetsProviders) { - return provider.Value; + if (provider.Value.SupportsProfile(profile)) + { + return provider.Value; + } } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Input/Commands/StartupProjectHelper.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Input/Commands/StartupProjectHelper.cs index b83626d9bd7..e645c00aee2 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Input/Commands/StartupProjectHelper.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Input/Commands/StartupProjectHelper.cs @@ -44,8 +44,11 @@ public ImmutableArray GetExportFromDotNetStartupProjects(string capability sln.GetProjectOfUniqueName(projectName, out IVsHierarchy hier); if (hier != null && hier.IsCapabilityMatch(capabilityMatch)) { - string projectPath = hier.GetProjectFilePath(); - results.Add(ProjectExportProvider.GetExport(projectPath)); + string? projectPath = hier.GetProjectFilePath(); + if (projectPath != null) + { + results.Add(ProjectExportProvider.GetExport(projectPath)); + } } } return results.ToImmutableAndFree(); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Logging/ProjectOutputWindowProjectLogger.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Logging/ProjectOutputWindowProjectLogger.cs index 80a490ea3e3..bd240ca7cf7 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Logging/ProjectOutputWindowProjectLogger.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Logging/ProjectOutputWindowProjectLogger.cs @@ -43,9 +43,9 @@ public void WriteLine(in StringFormat format) _threadingService.Fork(async () => { - IVsOutputWindowPane pane = await _outputWindowProvider.GetOutputWindowPaneAsync(); + IVsOutputWindowPane? pane = await _outputWindowProvider.GetOutputWindowPaneAsync(); - pane.OutputStringNoPump(text); + pane?.OutputStringNoPump(text); }, options: ForkOptions.HideLocks | ForkOptions.StartOnMainThread, factory: _threadingService.JoinableTaskFactory); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/DebugPageViewModel.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/DebugPageViewModel.cs index d354f674429..be176abf6fb 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/DebugPageViewModel.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/DebugPageViewModel.cs @@ -894,8 +894,11 @@ public ICommand DeleteProfileCommand IWritableLaunchProfile? profileToRemove = SelectedDebugProfile; SelectedDebugProfile = null; - CurrentLaunchSettings.Profiles.Remove(profileToRemove); - LaunchProfiles.Remove(profileToRemove); + if (profileToRemove != null) + { + CurrentLaunchSettings.Profiles.Remove(profileToRemove); + LaunchProfiles.Remove(profileToRemove); + } SelectedDebugProfile = LaunchProfiles.Count > 0 ? LaunchProfiles[0] : null; NotifyProfileCollectionChanged(); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/References/DesignTimeAssemblyResolution.ResolvedReference.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/References/DesignTimeAssemblyResolution.ResolvedReference.cs index 4845c43ccf7..2ac289d57b7 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/References/DesignTimeAssemblyResolution.ResolvedReference.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/References/DesignTimeAssemblyResolution.ResolvedReference.cs @@ -8,7 +8,7 @@ internal partial class DesignTimeAssemblyResolution { private readonly struct ResolvedReference { - public ResolvedReference(string resolvedPath, Version version) + public ResolvedReference(string resolvedPath, Version? version) { Assumes.NotNull(resolvedPath); @@ -21,7 +21,7 @@ public string ResolvedPath get; } - public Version Version + public Version? Version { get; } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/CrossTarget/AggregateCrossTargetProjectContext.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/CrossTarget/AggregateCrossTargetProjectContext.cs index d0aacf4c3e9..1d72977213d 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/CrossTarget/AggregateCrossTargetProjectContext.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/CrossTarget/AggregateCrossTargetProjectContext.cs @@ -63,8 +63,8 @@ public bool HasMatchingTargetFrameworks(ProjectConfiguration activeProjectConfig Assumes.True(activeProjectConfiguration.IsCrossTargeting()); Assumes.True(knownProjectConfigurations.All(c => c.IsCrossTargeting())); - ITargetFramework activeTargetFramework = _targetFrameworkProvider.GetTargetFramework(activeProjectConfiguration.Dimensions[ConfigurationGeneral.TargetFrameworkProperty]); - if (!ActiveTargetFramework.Equals(activeTargetFramework)) + ITargetFramework? activeTargetFramework = _targetFrameworkProvider.GetTargetFramework(activeProjectConfiguration.Dimensions[ConfigurationGeneral.TargetFrameworkProperty]); + if (activeTargetFramework == null || !ActiveTargetFramework.Equals(activeTargetFramework)) { // Active target framework is different. return false; @@ -83,9 +83,9 @@ public bool HasMatchingTargetFrameworks(ProjectConfiguration activeProjectConfig foreach (string targetFrameworkMoniker in targetFrameworkMonikers) { - ITargetFramework targetFramework = _targetFrameworkProvider.GetTargetFramework(targetFrameworkMoniker); + ITargetFramework? targetFramework = _targetFrameworkProvider.GetTargetFramework(targetFrameworkMoniker); - if (!TargetFrameworks.Contains(targetFramework)) + if (targetFramework == null || !TargetFrameworks.Contains(targetFramework)) { // Differing TargetFramework return false; diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/DependenciesProjectTreeProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/DependenciesProjectTreeProvider.cs index 3cf9c9b2e20..c66c4beebf6 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/DependenciesProjectTreeProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/DependenciesProjectTreeProvider.cs @@ -471,7 +471,7 @@ public IProjectTree CreateTree( public IProjectTree CreateTree( string caption, - string filePath, + string? filePath, IRule? browseObjectProperties = null, ProjectImageMoniker? icon = null, ProjectImageMoniker? expandedIcon = null, diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/Actions/CheckChildrenGraphActionHandler.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/Actions/CheckChildrenGraphActionHandler.cs index 9a61f45b9a5..6368e67685e 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/Actions/CheckChildrenGraphActionHandler.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/Actions/CheckChildrenGraphActionHandler.cs @@ -45,13 +45,13 @@ public override bool HandleRequest(IGraphContext graphContext) return false; } - string projectPath = inputGraphNode.Id.GetValue(CodeGraphNodeIdName.Assembly); + string? projectPath = inputGraphNode.Id.GetValue(CodeGraphNodeIdName.Assembly); if (string.IsNullOrEmpty(projectPath)) { continue; } - IDependency dependency = GetDependency(inputGraphNode, out IDependenciesSnapshot snapshot); + IDependency? dependency = GetDependency(inputGraphNode, out IDependenciesSnapshot? snapshot); if (dependency == null || snapshot == null) { continue; diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/Actions/GetChildrenGraphActionHandler.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/Actions/GetChildrenGraphActionHandler.cs index ffee112ed19..fc736c65099 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/Actions/GetChildrenGraphActionHandler.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/Actions/GetChildrenGraphActionHandler.cs @@ -44,13 +44,13 @@ public override bool HandleRequest(IGraphContext graphContext) return trackChanges; } - string projectPath = inputGraphNode.Id.GetValue(CodeGraphNodeIdName.Assembly); + string? projectPath = inputGraphNode.Id.GetValue(CodeGraphNodeIdName.Assembly); if (string.IsNullOrEmpty(projectPath)) { continue; } - IDependency dependency = GetDependency(inputGraphNode, out IDependenciesSnapshot snapshot); + IDependency? dependency = GetDependency(inputGraphNode, out IDependenciesSnapshot? snapshot); if (dependency == null || snapshot == null) { continue; diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/Actions/TrackChangesGraphActionHandler.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/Actions/TrackChangesGraphActionHandler.cs index c89f44131bb..1980c6dbd38 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/Actions/TrackChangesGraphActionHandler.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/Actions/TrackChangesGraphActionHandler.cs @@ -47,13 +47,13 @@ public override bool HandleChanges(IGraphContext graphContext, SnapshotChangedEv continue; } - string projectPath = inputGraphNode.Id.GetValue(CodeGraphNodeIdName.Assembly); + string? projectPath = inputGraphNode.Id.GetValue(CodeGraphNodeIdName.Assembly); if (string.IsNullOrEmpty(projectPath)) { continue; } - IDependency updatedDependency = GetDependency(projectPath, existingDependencyId, out IDependenciesSnapshot updatedSnapshot); + IDependency? updatedDependency = GetDependency(projectPath, existingDependencyId, out IDependenciesSnapshot? updatedSnapshot); if (updatedDependency == null) { continue; diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/DependenciesGraphProviderFactory.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/DependenciesGraphProviderFactory.cs index 2266d19c89d..851808ca347 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/DependenciesGraphProviderFactory.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/DependenciesGraphProviderFactory.cs @@ -23,12 +23,12 @@ internal DependenciesGraphProviderFactory(DependenciesGraphProvider provider) _provider = provider; } - public Graph Schema => _provider.Schema; + public Graph? Schema => _provider.Schema; public void BeginGetGraphData(IGraphContext context) => _provider.BeginGetGraphData(context); public IEnumerable GetCommands(IEnumerable nodes) => _provider.GetCommands(nodes); - public T GetExtension(GraphObject graphObject, T previous) where T : class => _provider.GetExtension(graphObject, previous); + public T? GetExtension(GraphObject graphObject, T previous) where T : class => _provider.GetExtension(graphObject, previous); } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/ViewProviders/IDependenciesGraphViewProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/ViewProviders/IDependenciesGraphViewProvider.cs index 06efa262695..d0e0cc8decf 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/ViewProviders/IDependenciesGraphViewProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/ViewProviders/IDependenciesGraphViewProvider.cs @@ -37,6 +37,6 @@ bool MatchSearchResults( string projectPath, IDependency topLevelDependency, Dictionary> searchResultsPerContext, - out HashSet topLevelDependencyMatches); + out HashSet? topLevelDependencyMatches); } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/ViewProviders/ProjectGraphViewProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/ViewProviders/ProjectGraphViewProvider.cs index d50b430951a..3be388a8a5d 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/ViewProviders/ProjectGraphViewProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/ViewProviders/ProjectGraphViewProvider.cs @@ -151,7 +151,7 @@ public override bool MatchSearchResults( string projectPath, IDependency topLevelDependency, Dictionary> searchResultsPerContext, - out HashSet topLevelDependencyMatches) + out HashSet? topLevelDependencyMatches) { topLevelDependencyMatches = new HashSet(); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/AnalyzerDependencyModel.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/AnalyzerDependencyModel.cs index b3f86ceff0f..b69543f5219 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/AnalyzerDependencyModel.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/AnalyzerDependencyModel.cs @@ -30,9 +30,9 @@ internal class AnalyzerDependencyModel : DependencyModel public override string ProviderType => AnalyzerRuleHandler.ProviderTypeString; - public override string SchemaItemType => AnalyzerReference.PrimaryDataSourceItemType; + public override string? SchemaItemType => AnalyzerReference.PrimaryDataSourceItemType; - public override string SchemaName => Resolved ? ResolvedAnalyzerReference.SchemaName : AnalyzerReference.SchemaName; + public override string? SchemaName => Resolved ? ResolvedAnalyzerReference.SchemaName : AnalyzerReference.SchemaName; public AnalyzerDependencyModel( string path, diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/AssemblyDependencyModel.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/AssemblyDependencyModel.cs index a5613528857..7ea2146b316 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/AssemblyDependencyModel.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/AssemblyDependencyModel.cs @@ -32,9 +32,9 @@ internal class AssemblyDependencyModel : DependencyModel public override int Priority => Dependency.FrameworkAssemblyNodePriority; - public override string SchemaItemType => AssemblyReference.PrimaryDataSourceItemType; + public override string? SchemaItemType => AssemblyReference.PrimaryDataSourceItemType; - public override string SchemaName => Resolved ? ResolvedAssemblyReference.SchemaName : AssemblyReference.SchemaName; + public override string? SchemaName => Resolved ? ResolvedAssemblyReference.SchemaName : AssemblyReference.SchemaName; public AssemblyDependencyModel( string path, @@ -52,7 +52,7 @@ public AssemblyDependencyModel( { if (isResolved) { - string fusionName = Properties.GetStringProperty(ResolvedAssemblyReference.FusionNameProperty); + string? fusionName = Properties.GetStringProperty(ResolvedAssemblyReference.FusionNameProperty); Caption = fusionName == null ? path : new AssemblyName(fusionName).Name; } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/ComDependencyModel.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/ComDependencyModel.cs index 3e49c81d267..5dff4df7f62 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/ComDependencyModel.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/ComDependencyModel.cs @@ -29,9 +29,9 @@ internal class ComDependencyModel : DependencyModel public override int Priority => Dependency.ComNodePriority; - public override string SchemaItemType => ComReference.PrimaryDataSourceItemType; + public override string? SchemaItemType => ComReference.PrimaryDataSourceItemType; - public override string SchemaName => Resolved ? ResolvedCOMReference.SchemaName : ComReference.SchemaName; + public override string? SchemaName => Resolved ? ResolvedCOMReference.SchemaName : ComReference.SchemaName; public ComDependencyModel( string path, diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/DependencyViewModel.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/DependencyViewModel.cs index 4788d263011..036d566c961 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/DependencyViewModel.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/DependencyViewModel.cs @@ -24,16 +24,16 @@ public DependencyViewModel(IDependencyModel model, bool hasUnresolvedDependency) _hasUnresolvedDependency = hasUnresolvedDependency; } - public IDependency OriginalModel { get; } + public IDependency? OriginalModel { get; } public string Caption => _model.Caption; - public string FilePath => _model.Id; - public string SchemaName => _model.SchemaName; - public string SchemaItemType => _model.SchemaItemType; + public string? FilePath => _model.Id; + public string? SchemaName => _model.SchemaName; + public string? SchemaItemType => _model.SchemaItemType; public int Priority => _model.Priority; public ImageMoniker Icon => _hasUnresolvedDependency ? _model.UnresolvedIcon : _model.Icon; public ImageMoniker ExpandedIcon => _hasUnresolvedDependency ? _model.UnresolvedExpandedIcon : _model.ExpandedIcon; - public IImmutableDictionary Properties => _model.Properties; + public IImmutableDictionary? Properties => _model.Properties; public ProjectTreeFlags Flags => _model.Flags; } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/PackageDependencyModel.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/PackageDependencyModel.cs index 28ad12a989f..eaae5d0d3ca 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/PackageDependencyModel.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/PackageDependencyModel.cs @@ -37,11 +37,11 @@ internal class PackageDependencyModel : DependencyModel public override string ProviderType => PackageRuleHandler.ProviderTypeString; - public override string SchemaItemType => PackageReference.PrimaryDataSourceItemType; + public override string? SchemaItemType => PackageReference.PrimaryDataSourceItemType; - public override string SchemaName => Resolved ? ResolvedPackageReference.SchemaName : PackageReference.SchemaName; + public override string? SchemaName => Resolved ? ResolvedPackageReference.SchemaName : PackageReference.SchemaName; - public override string Version { get; } + public override string? Version { get; } public PackageDependencyModel( string path, @@ -74,6 +74,10 @@ public PackageDependencyModel( { DependencyIDs = ImmutableArray.CreateRange(dependenciesIDs); } + else + { + DependencyIDs = ImmutableArray.Empty; + } } } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/ProjectDependencyModel.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/ProjectDependencyModel.cs index 72e404bdd41..18e9b78a6a9 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/ProjectDependencyModel.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/ProjectDependencyModel.cs @@ -32,9 +32,9 @@ internal class ProjectDependencyModel : DependencyModel public override string ProviderType => ProjectRuleHandler.ProviderTypeString; - public override string SchemaItemType => ProjectReference.PrimaryDataSourceItemType; + public override string? SchemaItemType => ProjectReference.PrimaryDataSourceItemType; - public override string SchemaName => Resolved ? ResolvedProjectReference.SchemaName : ProjectReference.SchemaName; + public override string? SchemaName => Resolved ? ResolvedProjectReference.SchemaName : ProjectReference.SchemaName; public ProjectDependencyModel( string path, diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/SharedProjectDependencyModel.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/SharedProjectDependencyModel.cs index 57e8b28fc29..74e76f81b84 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/SharedProjectDependencyModel.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Models/SharedProjectDependencyModel.cs @@ -33,9 +33,9 @@ internal class SharedProjectDependencyModel : DependencyModel public override string ProviderType => ProjectRuleHandler.ProviderTypeString; - public override string SchemaItemType => ProjectReference.PrimaryDataSourceItemType; + public override string? SchemaItemType => ProjectReference.PrimaryDataSourceItemType; - public override string SchemaName => Resolved ? ResolvedProjectReference.SchemaName : ProjectReference.SchemaName; + public override string? SchemaName => Resolved ? ResolvedProjectReference.SchemaName : ProjectReference.SchemaName; public SharedProjectDependencyModel( string path, diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Dependency.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Dependency.cs index d31587259c3..f0f87b7e837 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Dependency.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Dependency.cs @@ -186,11 +186,11 @@ string GetFullPath(string originalItemSpec, string containingProjectPath) } } - public string SchemaName { get; } + public string? SchemaName { get; } - private readonly string _schemaItemType; + private readonly string? _schemaItemType; - public string SchemaItemType + public string? SchemaItemType { get { @@ -205,7 +205,7 @@ public string SchemaItemType } public string Caption { get; } - public string Version { get; } + public string? Version { get; } public bool Resolved { get; } public bool TopLevel { get; } public bool Implicit { get; } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/DependenciesSnapshotFilterBase.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/DependenciesSnapshotFilterBase.cs index 9840e0df7b0..7f6425eb5aa 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/DependenciesSnapshotFilterBase.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/DependenciesSnapshotFilterBase.cs @@ -17,7 +17,7 @@ public virtual void BeforeAddOrUpdate( ITargetFramework targetFramework, IDependency dependency, IReadOnlyDictionary subTreeProviderByProviderType, - IImmutableSet projectItemSpecs, + IImmutableSet? projectItemSpecs, IAddDependencyContext context) { context.Accept(dependency); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/DuplicatedDependenciesSnapshotFilter.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/DuplicatedDependenciesSnapshotFilter.cs index f1084b56d28..97cc9b1702d 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/DuplicatedDependenciesSnapshotFilter.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/DuplicatedDependenciesSnapshotFilter.cs @@ -26,7 +26,7 @@ public override void BeforeAddOrUpdate( ITargetFramework targetFramework, IDependency dependency, IReadOnlyDictionary subTreeProviderByProviderType, - IImmutableSet projectItemSpecs, + IImmutableSet? projectItemSpecs, IAddDependencyContext context) { IDependency? matchingDependency = null; diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/IDependenciesSnapshotFilter.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/IDependenciesSnapshotFilter.cs index b3ccfbf8093..8a345c17dce 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/IDependenciesSnapshotFilter.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/IDependenciesSnapshotFilter.cs @@ -42,7 +42,7 @@ void BeforeAddOrUpdate( ITargetFramework targetFramework, IDependency dependency, IReadOnlyDictionary subTreeProviderByProviderType, - IImmutableSet projectItemSpecs, + IImmutableSet? projectItemSpecs, IAddDependencyContext context); /// diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/ImplicitTopLevelDependenciesSnapshotFilter.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/ImplicitTopLevelDependenciesSnapshotFilter.cs index c08c2441751..fe36aef0a80 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/ImplicitTopLevelDependenciesSnapshotFilter.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/ImplicitTopLevelDependenciesSnapshotFilter.cs @@ -26,7 +26,7 @@ public override void BeforeAddOrUpdate( ITargetFramework targetFramework, IDependency dependency, IReadOnlyDictionary subTreeProviderByProviderType, - IImmutableSet projectItemSpecs, + IImmutableSet? projectItemSpecs, IAddDependencyContext context) { if (!dependency.TopLevel diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/SdkAndPackagesDependenciesSnapshotFilter.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/SdkAndPackagesDependenciesSnapshotFilter.cs index e94218fe02c..21347864fff 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/SdkAndPackagesDependenciesSnapshotFilter.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/SdkAndPackagesDependenciesSnapshotFilter.cs @@ -28,7 +28,7 @@ public override void BeforeAddOrUpdate( ITargetFramework targetFramework, IDependency dependency, IReadOnlyDictionary subTreeProviderByProviderType, - IImmutableSet projectItemSpecs, + IImmutableSet? projectItemSpecs, IAddDependencyContext context) { if (!dependency.TopLevel) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/UnresolvedDependenciesSnapshotFilter.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/UnresolvedDependenciesSnapshotFilter.cs index ee706ee8448..cf6e97dc8cc 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/UnresolvedDependenciesSnapshotFilter.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/UnresolvedDependenciesSnapshotFilter.cs @@ -25,7 +25,7 @@ public override void BeforeAddOrUpdate( ITargetFramework targetFramework, IDependency dependency, IReadOnlyDictionary subTreeProviderByProviderType, - IImmutableSet projectItemSpecs, + IImmutableSet? projectItemSpecs, IAddDependencyContext context) { // TODO should this verify that the existing one is actually resolved? diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/UnsupportedProjectsSnapshotFilter.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/UnsupportedProjectsSnapshotFilter.cs index 077ff1c36fc..154a14742f2 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/UnsupportedProjectsSnapshotFilter.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/Filters/UnsupportedProjectsSnapshotFilter.cs @@ -37,7 +37,7 @@ public override void BeforeAddOrUpdate( ITargetFramework targetFramework, IDependency dependency, IReadOnlyDictionary subTreeProviderByProviderType, - IImmutableSet projectItemSpecs, + IImmutableSet? projectItemSpecs, IAddDependencyContext context) { if (dependency.TopLevel diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/ITargetedDependenciesSnapshot.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/ITargetedDependenciesSnapshot.cs index bd52c0c2ac4..ba99e992dcd 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/ITargetedDependenciesSnapshot.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/ITargetedDependenciesSnapshot.cs @@ -25,7 +25,7 @@ internal interface ITargetedDependenciesSnapshot /// /// Catalogs of rules for project items (optional, custom dependency providers might not provide it). /// - IProjectCatalogSnapshot Catalogs { get; } + IProjectCatalogSnapshot? Catalogs { get; } /// /// Top level project dependencies. diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/TargetedDependenciesSnapshot.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/TargetedDependenciesSnapshot.cs index fc7f98f71e5..fea68928ea2 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/TargetedDependenciesSnapshot.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Snapshot/TargetedDependenciesSnapshot.cs @@ -125,7 +125,7 @@ void Remove(RemoveDependencyContext context, IDependencyModel dependencyModel) void Add(AddDependencyContext context, IDependencyModel dependencyModel) { // Create the unfiltered dependency - IDependency dependency = new Dependency(dependencyModel, targetFramework, projectPath); + IDependency? dependency = new Dependency(dependencyModel, targetFramework, projectPath); context.Reset(); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Subscriptions/DependenciesChangesBuilder.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Subscriptions/DependenciesChangesBuilder.cs index 53d49d546fa..45be17528ae 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Subscriptions/DependenciesChangesBuilder.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Subscriptions/DependenciesChangesBuilder.cs @@ -78,9 +78,9 @@ public RemovedDependencyModel(string providerType, string dependencyId) public string OriginalItemSpec => throw NotImplemented(); public string Path => throw NotImplemented(); public string Caption => throw NotImplemented(); - public string SchemaName => throw NotImplemented(); - public string SchemaItemType => throw NotImplemented(); - public string Version => throw NotImplemented(); + public string? SchemaName => throw NotImplemented(); + public string? SchemaItemType => throw NotImplemented(); + public string? Version => throw NotImplemented(); public bool Resolved => throw NotImplemented(); public bool TopLevel => throw NotImplemented(); public bool Implicit => throw NotImplemented(); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Subscriptions/DependencySharedProjectsSubscriber.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Subscriptions/DependencySharedProjectsSubscriber.cs index d8e92f30e6d..7a551877d79 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Subscriptions/DependencySharedProjectsSubscriber.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/Subscriptions/DependencySharedProjectsSubscriber.cs @@ -23,7 +23,7 @@ internal class DependencySharedProjectsSubscriber : OnceInitializedOnceDisposed, private readonly List _subscriptionLinks = new List(); private readonly IProjectAsynchronousTasksService _tasksService; private readonly IDependenciesSnapshotProvider _dependenciesSnapshotProvider; - private ICrossTargetSubscriptionsHost _host; + private ICrossTargetSubscriptionsHost? _host; [ImportingConstructor] public DependencySharedProjectsSubscriber( @@ -116,7 +116,8 @@ await _tasksService.LoadedProjectAsync(() => private async Task HandleAsync(Tuple e) { - AggregateCrossTargetProjectContext currentAggregateContext = await _host.GetCurrentAggregateProjectContext(); + // _host is known to be initialized before this is called. + AggregateCrossTargetProjectContext? currentAggregateContext = await _host!.GetCurrentAggregateProjectContext(); if (currentAggregateContext == null) { return; @@ -127,7 +128,7 @@ private async Task HandleAsync(Tuple properties = projectRuleSnapshot.GetProjectItemProperties(itemSpec); + IImmutableDictionary? properties = projectRuleSnapshot.GetProjectItemProperties(itemSpec); - string originalItemSpec = resolved + string? originalItemSpec = resolved ? properties.GetStringProperty(ResolvedAssemblyReference.OriginalItemSpecProperty) : itemSpec; diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/UI/DialogServices.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/UI/DialogServices.cs index 4a912958880..caaae0b1549 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/UI/DialogServices.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/UI/DialogServices.cs @@ -20,7 +20,7 @@ public DialogServices(IUserNotificationServices userNotificationServices) _userNotificationServices = userNotificationServices; } - public bool DontShowAgainMessageBox(string caption, string message, string checkboxText, bool initialStateOfCheckbox, string learnMoreText, string learnMoreUrl) + public bool DontShowAgainMessageBox(string caption, string message, string? checkboxText, bool initialStateOfCheckbox, string learnMoreText, string learnMoreUrl) { var dlg = new DontShowAgainMessageBox(caption, message, checkboxText, initialStateOfCheckbox, learnMoreText, learnMoreUrl, _userNotificationServices); bool? result = dlg.ShowModal(); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/UI/DontShowAgainMessageBox.xaml.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/UI/DontShowAgainMessageBox.xaml.cs index 09f7fef138a..b2c1e1628df 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/UI/DontShowAgainMessageBox.xaml.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/UI/DontShowAgainMessageBox.xaml.cs @@ -9,7 +9,7 @@ namespace Microsoft.VisualStudio.ProjectSystem.VS.UI internal partial class DontShowAgainMessageBox : DialogWindow { - public DontShowAgainMessageBox(string caption, string message, string checkboxText, bool initialStateOfCheckbox, + public DontShowAgainMessageBox(string caption, string message, string? checkboxText, bool initialStateOfCheckbox, string learnMoreText, string learnMoreUrl, IUserNotificationServices userNotificationServices) { _userNotificationServices = userNotificationServices; diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/Shell/ServiceProviderToOleServiceProviderAdapter.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/Shell/ServiceProviderToOleServiceProviderAdapter.cs index 026b2be7a02..36a222bf497 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/Shell/ServiceProviderToOleServiceProviderAdapter.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/Shell/ServiceProviderToOleServiceProviderAdapter.cs @@ -22,8 +22,6 @@ public ServiceProviderToOleServiceProviderAdapter(IServiceProvider serviceProvid _serviceProvider = serviceProvider; } - public object ComServices { get; private set; } - public int QueryService(ref Guid guidService, ref Guid riid, out IntPtr ppvObject) { ppvObject = IntPtr.Zero; diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ConfiguredProjectImplicitActivationTracking.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ConfiguredProjectImplicitActivationTracking.cs index be11ca33835..4b6aeed42d8 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ConfiguredProjectImplicitActivationTracking.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ConfiguredProjectImplicitActivationTracking.cs @@ -130,7 +130,7 @@ private Task OnImplicitlyActivated() private Task OnImplicitlyDeactivated() { - var source = new TaskCompletionSource(); + var source = new TaskCompletionSource(); // Make sure the writes in constructor don't // move to after we publish the value diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/SpecialFileProviders/AbstractSpecialFileProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/SpecialFileProviders/AbstractSpecialFileProvider.cs index b39dbdb9074..f7aab58a531 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/SpecialFileProviders/AbstractSpecialFileProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/SpecialFileProviders/AbstractSpecialFileProvider.cs @@ -247,7 +247,7 @@ private async Task GetParentFolderAsync(bool createIfNotExists) if (createIfNotExists) flags |= SpecialFileFlags.CreateIfNotExist; - string path = await _specialFilesManager.GetFileAsync(SpecialFiles.AppDesigner, flags); + string? path = await _specialFilesManager.GetFileAsync(SpecialFiles.AppDesigner, flags); if (path == null) return null;