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
61 changes: 3 additions & 58 deletions extension/src/debugger/languages/dotnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,60 +56,6 @@ class DotNetService implements IDotNetService {
}

async buildDotNetProject(projectFile: string): Promise<void> {
const isDevKitEnabled = await this.getAndActivateDevKit();
if (isDevKitEnabled) {
this.writeToDebugConsole(lookingForDevkitBuildTask, 'stdout', true);

const tasks = await vscode.tasks.fetchTasks();
const buildTask = tasks.find(t => t.source === "dotnet" && t.name?.includes('build'));

// The build task may not be registered if there are is no solution in the workspace or if there are no C# projects
// with .csproj files.
if (buildTask) {
// Modify the task to target the specific project
const projectName = path.basename(projectFile, '.csproj');

// Create a modified task definition with just the project file
const modifiedDefinition = {
...buildTask.definition,
file: projectFile // This will make it build the specific project directly
};

// Create a new task with the modified definition
const modifiedTask = new vscode.Task(
modifiedDefinition,
buildTask.scope || vscode.TaskScope.Workspace,
`build ${projectName}`,
buildTask.source,
buildTask.execution,
buildTask.problemMatchers
);

extensionLogOutputChannel.info(`Executing build task: ${modifiedTask.name} for project: ${projectFile}`);
await vscode.tasks.executeTask(modifiedTask);

let disposable: vscode.Disposable = { dispose: () => {} };
return new Promise<void>((resolve, reject) => {
disposable = vscode.tasks.onDidEndTaskProcess(async e => {
if (e.execution.task === modifiedTask) {
if (e.exitCode !== 0) {
reject(new Error(buildFailedWithExitCode(e.exitCode ?? 'unknown')));
}
else {
return resolve();
}
}
});
}).finally(() => disposable.dispose());
}
else {
this.writeToDebugConsole(noCsharpBuildTask, 'stdout', true);
}
}
else {
this.writeToDebugConsole(csharpDevKitNotInstalled, 'stdout', true);
}

return new Promise<void>((resolve, reject) => {
extensionLogOutputChannel.info(`Building .NET project: ${projectFile} using dotnet CLI`);

Expand Down Expand Up @@ -325,10 +271,9 @@ export function createProjectDebuggerExtension(dotNetServiceProducer: (debugSess
const runApiOutput = await dotNetService.getDotNetRunApiOutput(projectPath);
const runApiConfig = getRunApiConfigFromOutput(runApiOutput);

// Build if the executable doesn't exist or forceBuild is requested
if ((!(await doesFileExist(runApiConfig.executablePath)) || launchOptions.forceBuild)) {
await dotNetService.buildDotNetProject(projectPath);
}
// There may be an older cached version of the file-based app, so we
// should force a build.
await dotNetService.buildDotNetProject(projectPath);

debugConfiguration.program = runApiConfig.executablePath;

Expand Down
2 changes: 2 additions & 0 deletions src/Aspire.Hosting/Dcp/DcpExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,8 @@ private void PrepareProjectExecutables()
{
var projectLaunchConfiguration = new ProjectLaunchConfiguration();
projectLaunchConfiguration.ProjectPath = projectMetadata.ProjectPath;
projectLaunchConfiguration.Mode = _configuration[KnownConfigNames.DebugSessionRunMode]
?? (Debugger.IsAttached ? ExecutableLaunchMode.Debug : ExecutableLaunchMode.NoDebug);

projectLaunchConfiguration.DisableLaunchProfile = project.TryGetLastAnnotation<ExcludeLaunchProfileAnnotation>(out _);
// Use the effective launch profile which has fallback logic
Expand Down
33 changes: 33 additions & 0 deletions tests/Aspire.Hosting.Tests/Dcp/DcpExecutorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,39 @@ public async Task ProjectLaunchConfiguration_Populated_WhenLaunchProfileSpecifie
Assert.Equal("http", plc.LaunchProfile);
}

[Theory]
[InlineData("Debug", ExecutableLaunchMode.Debug)]
[InlineData("NoDebug", ExecutableLaunchMode.NoDebug)]
public async Task ProjectLaunchConfiguration_RespectsDebugSessionRunMode(string runMode, string expectedMode)
{
var builder = DistributedApplication.CreateBuilder();
builder.AddProject<Projects.ServiceA>("proj", launchProfileName: "http");

using var app = builder.Build();
var model = app.Services.GetRequiredService<DistributedApplicationModel>();

var kubernetes = new TestKubernetesService();
var configBuilder = new ConfigurationBuilder();
configBuilder.AddInMemoryCollection(new Dictionary<string, string?>
{
[KnownConfigNames.DashboardOtlpGrpcEndpointUrl] = "http://localhost",
["AppHost:BrowserToken"] = "token",
["AppHost:OtlpApiKey"] = "otlp-key",
[DcpExecutor.DebugSessionPortVar] = "12345",
[KnownConfigNames.DebugSessionRunMode] = runMode
});
var configuration = configBuilder.Build();

var executor = CreateAppExecutor(model, configuration: configuration, kubernetesService: kubernetes);

await executor.RunApplicationAsync();

var exe = Assert.Single(kubernetes.CreatedResources.OfType<Executable>());
Assert.True(exe.TryGetProjectLaunchConfiguration(out var plc));
Assert.NotNull(plc);
Assert.Equal(expectedMode, plc!.Mode);
}

[Fact]
public async Task ProjectLaunchConfiguration_Disabled_WhenLaunchProfileExcluded_InDebugSession()
{
Expand Down
Loading