Document the way of sharing code between AppHost and its referenced projects
- Dominant language
- C#
- Stars
- 6.3k
- Forks
- 991
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 196
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Is your feature request related to a problem? Please describe the problem.
Please document the way to share code between AppHost and its referenced projects.
This would typically be constants etc.
For example I'm trying to share `HealthEndpointPath` property from `ServiceDefaults` with the `AppHost` project.
The way I'm achieving this is by adding the contsants class in the `ServiceDefaults` project, then adding a link to that file from the AppHost project. It doesn't seem to work well the other way.
### Describe the solution you'd like
Document the ways to share code between the AppHost and its references, in both directions, i.e. when it mainly belongs in AppHost and it needs to be shared down, or the other way around.
### Additional context
This is especially important for tests that use WebApplicationFactory with reference to one of the projects.
In such scenario, adding a code file 'as link' between the AppHost and one of the projects results in *CS0433: The type 'AppHostResourceNames' exists in both 'AspireApp4.ServiceDefaults, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' and 'AspireApp4.AppHost, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'*.
### Workarounds
1. Add a pre-processor definition to AppHost project (`ASPIRE`), and make the accessibility of the shared class depend on that:
```csharp
#if ASPIRE
internal
#else
public
#endif
class AppHostResourceNames
```
Then add it as a linked file in the other projects
2. Make the class internal and as a link to shared project then expose the fields via a different type name to avoid the conflict / disambiguation.
Contributor guide
Assessment
This issue has not been assessed yet.