aspire icon indicating copy to clipboard operation
aspire copied to clipboard

Update `WithArgs` to accept object array

Open afscrome opened this issue 9 months ago • 0 comments

I'd like to be able to do the following

builder
  .AddExecutable(...)
  .WithEndpoint(name: "endpoint")
  .WithArgs("-p", builder.Resource.GetEndpoint("endpoint").Property(EndpointProperty.Port));

But this doesn't work as the WithArgs callback only accepts string array params - https://github.com/dotnet/aspire/blob/d4acce5704b8f086cd38c2e29b2766669d8a1277/src/Aspire.Hosting/ResourceBuilderExtensions.cs#L162-L165

For now, can work around this with the callback overload that does accept objects

return builder
  .AddExecutable(...)
  .WithArgs(context =>{
      context.Args.Add("-p");
      context.Args.Add(builder.Resource.GetEndpoint(endpointName).Property(EndpointProperty.TargetPort));
    });

afscrome avatar May 20 '24 11:05 afscrome