Thank you for reaching out.
What you are trying to do is start a Windows service as part of debugging and have Visual Studio automatically attach to the service process so you can debug early startup code.
In Visual Studio 2022, this is not supported. When you configure debugging to run net.exe start MyService, Visual Studio correctly attaches to net.exe, because it always attaches to the process it launches. It does not automatically attach to a different process (your service executable) that net.exe starts.
Because of this design, Visual Studio cannot start a Windows service and then switch the debugger to the service process by name. That is why your current setup always ends up attached to net.exe.
Microsoft documents that Windows services must be started by the Service Control Manager, and the normal debugging flow is to start the service first and then attach to its process. Debugging early startup code (like OnStart) is difficult when attaching after the service is already running. https://learn.microsoft.com/dotnet/framework/windows-services/how-to-debug-windows-service-applications
For debugging early service startup, the documented way is to trigger the debugger from inside the service itself. You can do this by calling System.Diagnostics.Debugger.Launch() at the beginning of OnStart. When the service starts, Windows will prompt you to choose a debugger, and Visual Studio will attach at that point.
https://learn.microsoft.com/visualstudio/debugger/how-to-debug-the-onstart-method
Please let us know if you require any further assistance, we’re happy to help. If you found this information useful, kindly mark this as "Accept Answer". So that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.