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
6 changes: 4 additions & 2 deletions src/Aspire.Cli/Projects/ProjectLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ internal interface IProjectLocator

internal sealed class ProjectLocator(ILogger<ProjectLocator> logger, IDotNetCliRunner runner, CliExecutionContext executionContext, IInteractionService interactionService, IConfigurationService configurationService, AspireCliTelemetry telemetry, IFeatures features) : IProjectLocator
{
private static readonly HashSet<string> s_supportedProjectFileExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { ".csproj", ".fsproj", ".vbproj" };
Copy link
Member

@mitchdenny mitchdenny Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might need to introduce a FileExtensionHelper.IsSupportedMsBuildFile(...) which encapsulates the check. That way we can reuse it. There are a few other places in the CLI where we make assumptions about using *.csproj files.


public async Task<List<FileInfo>> FindAppHostProjectFilesAsync(string searchDirectory, CancellationToken cancellationToken)
{
var allCandidates = await FindAppHostProjectFilesAsync(new DirectoryInfo(searchDirectory), cancellationToken);
Expand Down Expand Up @@ -345,8 +347,8 @@ await Parallel.ForEachAsync(appHostFiles, parallelOptions, async (candidateFile,
throw new ProjectLocatorException(ErrorStrings.ProjectFileDoesntExist);
}
}
// Handle .csproj files
else if (projectFile.Extension.Equals(".csproj", StringComparison.OrdinalIgnoreCase))
// Handle .cs|fs|vbproj files
else if (s_supportedProjectFileExtensions.Contains(projectFile.Extension))
{
logger.LogDebug("Using project file {ProjectFile}", projectFile.FullName);
return projectFile;
Expand Down
10 changes: 7 additions & 3 deletions tests/Aspire.Cli.Tests/Projects/ProjectLocatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,15 @@ public async Task UseOrFindAppHostProjectFileThrowsIfNoProjectWasFound()
Assert.Equal("No project file found.", ex.Message);
}

[Fact]
public async Task UseOrFindAppHostProjectFileReturnsExplicitProjectIfExistsAndProvided()
[Theory]
[InlineData(".csproj")]
[InlineData(".fsproj")]
[InlineData(".vbproj")]
public async Task UseOrFindAppHostProjectFileReturnsExplicitProjectIfExistsAndProvided(string projectFileExtension)
{
var logger = NullLogger<ProjectLocator>.Instance;
using var workspace = TemporaryWorkspace.Create(outputHelper);
var projectFile = new FileInfo(Path.Combine(workspace.WorkspaceRoot.FullName, "AppHost.csproj"));
var projectFile = new FileInfo(Path.Combine(workspace.WorkspaceRoot.FullName, $"AppHost{projectFileExtension}"));
await File.WriteAllTextAsync(projectFile.FullName, "Not a real project file.");

var runner = new TestDotNetCliRunner();
Expand Down Expand Up @@ -1170,3 +1173,4 @@ public async Task FindExecutableProjectsAsync_FindsMultipleExecutableProjects()
Assert.Contains(executableProjects, p => p.FullName == winExeFile.FullName);
}
}