dotnet / aspire

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

Consider using Roslyn Analyzer (Source generator) for `IServiceMetadata` gen. #601

Open IEvangelist opened 1 year ago

IEvangelist commented 1 year ago

Currently the IServiceMetadata implementations that are created within the Projects namespace are discovered and compiled using the following MSBuild target:

https://github.com/dotnet/aspire/blob/12af412b50c7533a75748edae2776d70a64c890e/src/Aspire.Hosting/build/Aspire.Hosting.targets#L15-L64

I'm proposing that you consider creating and using a Roslyn Analyzer (Source generator) instead. When I first explored this generated IServiceMetadata implementation I was surprised to see that I could edit the file, which wouldn't be the case with a source generated file.

Additionally, I would like to propose that instead of replacing . and - with _, that you simply remove them instead. For example, consider the following differences in these two approaches:

This feels a bit more idiomatic.

DamianEdwards commented 1 year ago

Replacing non-safe chars with _ is consistent with what templates and VS does today so I'm inclined to keep doing that.

davidfowl commented 10 months ago

Move out of scope for v1