Skip to content

Commit 56b2f6c

Browse files
authored
Use project directory as a working directory for Aspire processes (#49901)
1 parent 682707d commit 56b2f6c

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

src/BuiltInTools/dotnet-watch/Aspire/AspireServiceFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ private ProjectOptions GetProjectOptions(ProjectLaunchRequest projectLaunchInfo)
211211
{
212212
IsRootProject = false,
213213
ProjectPath = projectLaunchInfo.ProjectPath,
214-
WorkingDirectory = _projectLauncher.EnvironmentOptions.WorkingDirectory,
214+
WorkingDirectory = Path.GetDirectoryName(projectLaunchInfo.ProjectPath) ?? throw new InvalidOperationException(),
215215
BuildArguments = _hostProjectOptions.BuildArguments,
216216
Command = "run",
217217
CommandArguments = GetRunCommandArguments(projectLaunchInfo, hostLaunchProfile),

test/TestAssets/TestProjects/WatchAspire/WatchAspire.ApiService/Program.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
using System;
2+
13
var builder = WebApplication.CreateBuilder(args);
24

5+
Console.WriteLine($"ApiService working directory: '{Environment.CurrentDirectory}'");
6+
37
// Add service defaults & Aspire components.
48
builder.AddServiceDefaults();
59

test/dotnet-watch.Tests/HotReload/ApplyDeltaTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,9 @@ public async Task Aspire_BuildError_ManualRestart()
10541054
// wait until after DCP session started:
10551055
await App.WaitUntilOutputContains("dotnet watch ⭐ Session started: #1");
10561056

1057+
// working directory of the service should be it's project directory:
1058+
await App.WaitUntilOutputContains($"ApiService working directory: '{Path.GetDirectoryName(serviceProjectPath)}'");
1059+
10571060
// Service -- valid code change:
10581061
UpdateSourceFile(
10591062
serviceSourcePath,
@@ -1078,7 +1081,7 @@ public async Task Aspire_BuildError_ManualRestart()
10781081
await App.AssertOutputLineStartsWith(" ❔ Do you want to restart these projects? Yes (y) / No (n) / Always (a) / Never (v)");
10791082

10801083
App.AssertOutputContains("dotnet watch ⌚ Restart is needed to apply the changes.");
1081-
App.AssertOutputContains($"dotnet watch ❌ {serviceSourcePath}(36,1): error ENC0020: Renaming record 'WeatherForecast' requires restarting the application.");
1084+
App.AssertOutputContains($"dotnet watch ❌ {serviceSourcePath}(40,1): error ENC0020: Renaming record 'WeatherForecast' requires restarting the application.");
10821085
App.AssertOutputContains("dotnet watch ⌚ Affected projects:");
10831086
App.AssertOutputContains("dotnet watch ⌚ WatchAspire.ApiService");
10841087
App.Process.ClearOutput();

0 commit comments

Comments
 (0)