[AspireDeployment] AspireService.GetAspireHostAsync() is unable to return AspireHost instance while the AspireApp is running
In VS IDE, while an AspireApp.AppHost is running, invocation to AspireService.GetAspireHostAsync() results in no data being returned. Once the AspireApp stops running, this endpoint returns the correct result.
From VS IDE:
... azd vs-server service 'AspireService/v1.0' attached StreamJsonRpc.RemoteInvocationException: failed to load app host manifest: generating app host manifest: dotnet run --publisher manifest on project 'C:\Users\balach\source\repos\AspireStarterApp10\AspireStarterApp10.AppHost\AspireStarterApp10.AppHost.csproj' failed: exit code: 1, stdout: Building... C:\Program Files\dotnet\sdk\8.0.300-preview.24101.10\Microsoft.Common.CurrentVersion.targets(4980,5): warning MSB3026: Could not copy "C:\Users\balach\source\repos\AspireStarterApp10\AspireStarterApp10.ServiceDefaults\bin\Debug\net8.0\AspireStarterApp10.ServiceDefaults.dll" to "bin\Debug\net8.0\AspireStarterApp10.ServiceDefaults.dll". Beginning retry 1 in 1000ms. The process cannot access the file 'C:\Users\balach\source\repos\AspireStarterApp10\AspireStarterApp10.ApiService\bin\Debug\net8.0\AspireStarterApp10.ServiceDefaults.dll' because it is being used by another process. The file is locked by: "AspireStarterApp10.ApiService (10956)" [C:\Users\balach\source\repos\AspireStarterApp10\AspireStarterApp10.ApiService\AspireStarterApp10.ApiService.csproj] C:\Program Files\dotnet\sdk\8.0.300-preview.24101.10\Microsoft.Common.CurrentVersion.targets(4980,5): warning MSB3026: Could not copy "C:\Users\balach\source\repos\AspireStarterApp10\AspireStarterApp10.ServiceDefaults\bin\Debug\net8.0\AspireStarterApp10.ServiceDefaults.dll" to "bin\Debug\net8.0\AspireStarterApp10.ServiceDefaults.dll". Beginning retry 1 in 1000ms. The process cannot access the file 'C:\Users\balach\source\repos\AspireStarterApp10\AspireStarterApp10.Web\bin\Debug\net8.0\AspireStarterApp10.ServiceDefaults.dll' because it is being used by another process. The file is locked by: "AspireStarterApp10.Web (13924)" [C:\Users\balach\source\repos\AspireStarterApp10\AspireStarterApp10.Web\AspireStarterApp10.Web.csproj] ...
We talked about this in triage a bit. The problem is that we use dotnet run to run the app host in order to get the manifest - and that fails if the app is already running. @davidfowl proposed that we start calling some MS Build Target via dotnet msbuild and that target can be built in a way such that we don't have these publishing issues and it can run while the app host itself is also running.
We can run just the GenerateManifest task and get its outputs thusly (this is against an apphost project):
dotnet msbuild -getTargetResult:GenerateAspireManifest
{
"TargetResults": {
"GenerateAspireManifest": {
"Result": "Success",
"Items": [
{
"Identity": "obj/Debug/net8.0/Aspire/manifest.json",
"FullPath": "/Users/matell/dd/ellismg/AspireStarter6/AspireStarter6.AppHost/obj/Debug/net8.0/Aspire/manifest.json",
"RootDir": "/",
"Filename": "manifest",
"Extension": ".json",
"RelativeDir": "obj/Debug/net8.0/Aspire/",
"Directory": "Users/matell/dd/ellismg/AspireStarter6/AspireStarter6.AppHost/obj/Debug/net8.0/Aspire/",
"RecursiveDir": "",
"ModifiedTime": "2024-03-12 13:33:41.0001809",
"CreatedTime": "2024-03-12 13:29:10.3799700",
"AccessedTime": "2024-03-12 13:33:41.0192689",
"DefiningProjectFullPath": "/Users/matell/.nuget/packages/aspire.hosting/8.0.0-preview.3.24105.21/build/Aspire.Hosting.targets",
"DefiningProjectDirectory": "/Users/matell/.nuget/packages/aspire.hosting/8.0.0-preview.3.24105.21/build/",
"DefiningProjectName": "Aspire.Hosting",
"DefiningProjectExtension": ".targets"
}
]
}
}
}
Fetching TargetResults.GenerateAspireManifes.Items[0].FullPath is likely what we want.
Looking at the implementation of GenerateAspireManifest - it ends up just running the app host itself - I'm not sure if @davidfowl would change how this works (the task does have Inputs and Outputs defined, and I observe from repeated rebuilds that it looks like there is some level of caching going on today). FYI - @davidfowl - I expect that DOTNET_ENVIRONMENT is really an Input (in the MSBuild sense) to manifest generation but it doesn't seem to be captured in the MSBuild logic - I'm worried that moving to this will may break AppHosts that conditionalize based on what environment you are in) if we don't force manifest regeneration when DOTNET_ENVIRONMENT changes.
@ellismg @weikanglim don't think it is a blocker for VS/Aspire 8.0 GA. Moving to Dilithium bucket, feel free to pull this into specific milestones, if need be.