dotnet / dotnet/aspnetcore

Auto-generated Program.cs does not have a namespace

Open
#65,509 0 comments 0 reactions 0 assignees View on GitHub
area-mvc design-proposal
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

I upgraded to .NET 10, and read that the Program.cs can get auto-generated for WebApplicationFactory tests, so no need for the `public partial class Program { }` declaration anymore.
But I have an API and a Console App in my solution that both are referenced by my test project.
So when I try to use the auto-generated Program.cs, I get the
`error CS0433: The type 'Program' exists in both 'MyAPI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' and 'MyConsoleApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'`

Previously I did wrap my API Program.cs in the project's namespace like this:
```
namespace MyAPI
{
public partial class Program { }
}
```
I suggest that the new auto-generated version gets the projects base namespace appended at the top so that this can be used by solutions with more than 1 project.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.