Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@
<Using Include="Microsoft.VisualStudio.Composition.ImportCardinality" Alias="ImportCardinality" />
<!-- Prevent accidental use of Microsoft.VisualStudio.Threading.IAsyncDisposable -->
<Using Include="System.IAsyncDisposable" Alias="IAsyncDisposable" />
<!-- Enforce use of Microsoft.IO -->
<Using Include="Microsoft.IO.Path" Alias="Path" Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'" />
<Using Include="Microsoft.IO.Directory" Alias="Directory" Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'" />
<Using Include="Microsoft.IO.SearchOption" Alias="SearchOption" Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'" />
</ItemGroup>

<Import Project="eng\imports\LanguageSettings.props" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information.

using System.Runtime.InteropServices;
using Path = Microsoft.IO.Path;

namespace Microsoft.VisualStudio.IO;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,20 @@ public async Task<bool> CreateFileAsync(string templateFile, string path)
Requires.NotNull(templateFile);
Requires.NotNullOrEmpty(path);

string directoryName = Path.GetDirectoryName(path);
string fileName = Path.GetFileName(path);
string? directoryName = Path.GetDirectoryName(path);

if (directoryName is null)
{
return false;
}

string? templateLanguage = await GetTemplateLanguageAsync();

if (string.IsNullOrEmpty(templateLanguage))
{
return false;
}

await _projectVsServices.ThreadingService.SwitchToUIThread();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ IEnumerable<string> GetFilePaths(BuildOptions options)

protected override void AddToContext(IWorkspaceProjectContext context, string fullPath, IImmutableDictionary<string, string> metadata, bool isActiveContext, IManagedProjectDiagnosticOutputService 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using Microsoft.VisualStudio.Threading;
// Debug collides with Microsoft.VisualStudio.ProjectSystem.VS.Debug
using DiagDebug = System.Diagnostics.Debug;
using Path = System.IO.Path;
using static Microsoft.CodeAnalysis.Rename.Renamer;

namespace Microsoft.VisualStudio.ProjectSystem.VS.Rename;
Expand Down Expand Up @@ -75,7 +74,13 @@ public async Task OnBeforeFilesMovedAsync(IReadOnlyCollection<IFileMoveItem> ite
}

// Get the relative folder path from the project to the destination.
string destinationFolderPath = Path.GetDirectoryName(_unconfiguredProject.MakeRelative(itemToMove.Destination));
string? destinationFolderPath = Path.GetDirectoryName(_unconfiguredProject.MakeRelative(itemToMove.Destination));

if ( (destinationFolderPath is null))
{
continue;
}

string[] destinationFolders = destinationFolderPath.Split(Delimiter.Path, StringSplitOptions.RemoveEmptyEntries);

// Since this rename only moves the location of the file to another directory, it will use the SyncNamespaceDocumentAction in Roslyn as the rename action within this set.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,14 @@ public override async Task RenameAsync(IProjectTreeActionHandlerContext context,
Requires.NotNullOrEmpty(value);

string? oldFilePath = node.FilePath;
string oldName = Path.GetFileNameWithoutExtension(oldFilePath);
string? oldName = Path.GetFileNameWithoutExtension(oldFilePath);
string newFileWithExtension = value;
CodeAnalysis.Project? project = GetCurrentProject();

await CpsFileRenameAsync(context, node, value);

if (project is null ||
if (oldName is null ||
project is null ||
await IsAutomationFunctionAsync() ||
node.IsFolder ||
_vsOnlineServices.ConnectedToVSOnline ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Microsoft.VisualStudio.Linq;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Threading;
using Path = Microsoft.IO.Path;

namespace Microsoft.VisualStudio.ProjectSystem.VS.Retargeting;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Threading;
using IFileSystem = Microsoft.VisualStudio.IO.IFileSystem;
using Path = Microsoft.IO.Path;

namespace Microsoft.VisualStudio.ProjectSystem.VS.Retargeting;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public bool IsSdkInstalled(string sdkVersion)
registryKey,
"InstallLocation");

if (!string.IsNullOrEmpty(installLocation))
if (!Strings.IsNullOrEmpty(installLocation))
{
string dotnetExePath = Path.Combine(installLocation, "dotnet.exe");
if (_fileSystem.FileExists(dotnetExePath))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ internal void ProcessDataflowChanges(IProjectVersionedValue<ValueTuple<DesignTim
// Make sure we have the up to date output path. If either of these don't exist, they will be null and we'll handle the ArgumentException below
string? basePath = configChanges.After.Properties.GetValueOrDefault(ConfigurationGeneral.ProjectDirProperty);
string? objPath = configChanges.After.Properties.GetValueOrDefault(ConfigurationGeneral.IntermediateOutputPathProperty);

if (basePath is null || objPath is null)
{
return null;
}

try
{
tempPEOutputPath = Path.Combine(basePath, objPath, "TempPE");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public FrameworkReferenceAssemblyItem(string assemblyName, string? path, string?
string? IObjectBrowserItem.AssemblyPath => GetAssemblyPath();

private string? GetAssemblyPath() => Path is not null
? System.IO.Path.GetFullPath(System.IO.Path.Combine(Framework.Path, Path))
? Microsoft.IO.Path.GetFullPath(Microsoft.IO.Path.Combine(Framework.Path, Path))
: null;

private sealed class BrowseObject(FrameworkReferenceAssemblyItem item) : LocalizableProperties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public void AddCopy(string source, string destination)
if (destinationInfo is null)
{
// Ensure the destination directory actually exists on disk
_fileSystem.CreateDirectory(Path.GetDirectoryName(destination));
_fileSystem.CreateDirectory(Path.GetDirectoryName(destination)!);
}

// TODO add retry logic in case of failed copies? MSBuild does this with CopyRetryCount and CopyRetryDelayMilliseconds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ private bool CheckCopyToOutputDirectoryItems(Log log, UpToDateCheckImplicitConfi
{
ITimestampCache timestampCache = solutionBuildContext.CopyItemTimestamps;

string outputFullPath = Path.Combine(state.MSBuildProjectDirectory, state.OutputRelativeOrFullPath);
string outputFullPath = Path.Combine(state.MSBuildProjectDirectory!, state.OutputRelativeOrFullPath!);

Log.Scope? scope1 = null;

Expand Down Expand Up @@ -1074,7 +1074,7 @@ private async Task<bool> IsUpToDateInternalAsync(

var configuredFileSystemOperations = new ConfiguredFileSystemOperationAggregator(fileSystemOperations, isBuildAccelerationEnabled, copyInfo.TargetsWithoutReferenceAssemblies);

string outputFullPath = Path.Combine(implicitState.MSBuildProjectDirectory, implicitState.OutputRelativeOrFullPath);
string outputFullPath = Path.Combine(implicitState.MSBuildProjectDirectory!, implicitState.OutputRelativeOrFullPath!);

copyItemPaths.UnionWith(implicitState.ProjectCopyData.CopyItems.Select(copyItem => Path.Combine(outputFullPath, copyItem.RelativeTargetPath)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,9 @@ protected async Task EnsureSettingsFolderAsync()
{
string fileName = await GetLaunchSettingsFilePathAsync();

string parentPath = Path.GetDirectoryName(fileName);
string? parentPath = Path.GetDirectoryName(fileName);

Assumes.NotNull(parentPath);

_fileSystem.CreateDirectory(parentPath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ internal static class ProjectTreeProviderExtensions

string? projectFilePath = provider.GetPath(target.Root);

string rootPath = Path.GetDirectoryName(projectFilePath);
string? rootPath = Path.GetDirectoryName(projectFilePath);

if (rootPath is null)
{
return null;
}

return Path.Combine(rootPath, relativePath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public AppDesignerFolderSpecialFileProvider(IPhysicalProjectTree projectTree, Pr
return null;

string? folderName = await GetDefaultAppDesignerFolderNameAsync();
if (string.IsNullOrEmpty(folderName))
if (Strings.IsNullOrEmpty(folderName))
return null; // Developer has set the AppDesigner path to empty

return Path.Combine(projectPath, folderName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ private static string[] GetPathComponents(string evaluatedInclude)

private static string[] GetPathFolders(string path)
{
return GetPathComponents(Path.GetDirectoryName(path));
string? evaluatedInclude = Path.GetDirectoryName(path);
if (evaluatedInclude is null)
{
return [];
}

return GetPathComponents(evaluatedInclude);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public Task<bool> CanRenameAsync(IProjectTree node)
if (target.IsRoot())
return string.Empty;

return Path.Combine(GetAddNewItemDirectory(target.Parent!), target.Caption);
return Path.Combine(GetAddNewItemDirectory(target.Parent!)!, target.Caption);
}

public string? GetPath(IProjectTree node)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ public static string FindRepoRootPath()
if (_root is null)
{
// Start with this DLL's location
string path = typeof(RepoUtil).Assembly.Location;
string? path = typeof(RepoUtil).Assembly.Location;

// Walk up the tree until we find the 'artifacts' folder
while (!Path.GetFileName(path).Equals("artifacts", StringComparisons.Paths))
while (Path.GetFileName(path)?.Equals("artifacts", StringComparisons.Paths) is false)
{
path = Path.GetDirectoryName(path);
}
Expand All @@ -29,6 +29,8 @@ public static string FindRepoRootPath()
_root = Path.GetDirectoryName(path);
}

Assumes.NotNull(_root);

return _root;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public static IEnumerable<object[]> GetResolvedAndUnresolvedDependencyRulePairs(
{
string unresolvedName = Path.GetFileNameWithoutExtension(unresolvedPath);
string resolvedName = "Resolved" + unresolvedName;
string resolvedPath = Path.Combine(Path.GetDirectoryName(unresolvedPath), resolvedName + ".xaml");
string resolvedPath = Path.Combine(Path.GetDirectoryName(unresolvedPath)!, resolvedName + ".xaml");

Assert.Contains(resolvedPath, resolvedPaths);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public abstract class XamlRuleTestBase

foreach ((string basePath, Type assemblyExporterType) in projects)
{
string path = string.IsNullOrEmpty(suffix) ? basePath : Path.Combine(basePath, suffix);
string path = Strings.IsNullOrEmpty(suffix) ? basePath : Path.Combine(basePath, suffix);

if (Directory.Exists(path))
{
Expand Down