dotnet user-secrets init --file app.cs should add #:property UserSecretsId=... to the top of the C# file. Similarly how dotnet package add and similar command work. We might need to publish the #: directive manipulation utilities as internal source-only package to share the logic.