dotnet / aspire

Tools, templates, and packages to accelerate building observable, production-ready apps
https://learn.microsoft.com/dotnet/aspire
MIT License
3.95k stars 486 forks source link

dotnet publish to folder for Aspire.Hosting.Testing projects #6857

Open Culan opened 21 hours ago

Culan commented 21 hours ago

Is there an existing issue for this?

Is your feature request related to a problem? Please describe the problem.

In our build pipeline we have separated the build from the test execution to enable all our test projects run in parallel on multiple test agents.

To accomplish this we have this workflow:

If this is fine we move to the test stage where we:

Obviously we want only one build to happen and we want our tests run on that particular build so to save time and space, the test agent doesn't even have to clone the repo, it just gets everything from the dotnet publish and then executes dotnet test on that dll.

When we try to apply the same to Aspire.Hosting.Testing test projects the publish seems to succeed but then when we run the tests we are hitting a DirectoryNotFoundException with an directory hinting of the agent who build it.

[xUnit.net 00:00:41.49] System.IO.DirectoryNotFoundException : E:\home\vsts\work\1\s\Source\Gateway.AppHost\ [xUnit.net 00:00:41.49] Stack Trace: [xUnit.net 00:00:41.49] at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root, ExclusionFilters filters) [xUnit.net 00:00:41.49] at Microsoft.Extensions.Hosting.HostBuilder.CreateHostingEnvironment(IConfiguration hostConfiguration) [xUnit.net 00:00:41.49] at Microsoft.Extensions.Hosting.HostApplicationBuilder.Initialize(HostApplicationBuilderSettings settings, HostBuilderContext& hostBuilderContext, IHostEnvironment& environment, LoggingBuilder& logging, MetricsBuilder& metrics) [xUnit.net 00:00:41.49] at Microsoft.Extensions.Hosting.HostApplicationBuilder..ctor(HostApplicationBuilderSettings settings) [xUnit.net 00:00:41.49] /_/src/Aspire.Hosting/DistributedApplicationBuilder.cs(132,0): at Aspire.Hosting.DistributedApplicationBuilder..ctor(DistributedApplicationOptions options) [xUnit.net 00:00:41.49] /_/src/Aspire.Hosting/DistributedApplication.cs(141,0): at Aspire.Hosting.DistributedApplication.CreateBuilder(String[] args) [xUnit.net 00:00:41.49] /_/Source/Gateway.AppHost/Program.cs(5,0): at Program.<Main>$(String[] args) [xUnit.net 00:00:41.49] at Program.<Main>(String[] args)

I've researched current issues there is none pointing exactly to my use-case but i found some hints: https://github.com/dotnet/aspire/issues/1704 - Here DamianEdwards is saying that during compile time the path to DCP from the AssemblyMetadata attributes stamped onto the AppHost

So i had a quick check on my apphost:

AssemblyMetadataAttribute: dcpclipath value: /home/vsts/.nuget/packages/aspire.hosting.orchestration.linux-x64/9.0.0/tools/dcp AssemblyMetadataAttribute: dcpextensionpaths value: /home/vsts/.nuget/packages/aspire.hosting.orchestration.linux-x64/9.0.0/tools/ext/ AssemblyMetadataAttribute: dcpbinpath value: /home/vsts/.nuget/packages/aspire.hosting.orchestration.linux-x64/9.0.0/tools/ext/bin/ AssemblyMetadataAttribute: apphostprojectpath value: /home/vsts/work/1/s/Source/Gateway.AppHost AssemblyMetadataAttribute: apphostprojectname value: Gateway.AppHost.csproj AssemblyMetadataAttribute: aspiredashboardpath value: /home/vsts/.nuget/packages/aspire.dashboard.sdk.linux-x64/9.0.0/tools/Aspire.Dashboard

Here we can see references to the build host's nuget cache and the sourcecode.

I guess that what i'm after is a dotnet publish to folder functionality that would remove any link towards the sourcecode and the build host.

Describe the solution you'd like

dotnet publish to folder that creates a package that can run independently.

Additional context

No response

Culan commented 20 hours ago

The same behavior can be observed locally with aspire-samples: