Skip to content

Conversation

jjonescz
Copy link
Member

@jjonescz jjonescz commented Sep 3, 2025

@jjonescz jjonescz added the Area-run-file Items related to the "dotnet run <file>" effort label Sep 3, 2025
Copy link
Contributor

github-actions bot commented Sep 3, 2025

This PR is targeting main, which is now for .NET 11-facing work. If you intended to target .NET 10, either retarget this PR to release/10.0.1xx or make sure you backport the change to release/10.0.1xx after merging. See #50394 for more details.

@jjonescz jjonescz changed the base branch from main to release/10.0.1xx September 3, 2025 08:45
@@ -133,6 +133,9 @@ Copyright (c) .NET Foundation. All rights reserved.

<!-- Uncomment this once https://github.com/Microsoft/visualfsharp/issues/3207 gets fixed -->
<!-- <WarningsAsErrors>$(WarningsAsErrors);NU1605</WarningsAsErrors> -->

<!-- Implicitly set UserSecretsId to hash of project file path. -->
<UserSecretsId Condition="'$(UserSecretsId)'==''">$([MSBuild]::StableStringHash($(MSBuildProjectFullPath), 'Sha256'))</UserSecretsId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this going to make reproducible builds more difficult? I mean, if the project does not explicitly set UserSecretsId, and it ends up referencing Microsoft.Extensions.Configuration.UserSecrets so that an UserSecretsIdAttribute is generated, then the attribute will now depend on the full path of the project, so you'll need to place the project at the same path if you ever want to reproduce the build. The effects of the full path on debug information can be avoided by PathMap but that won't affect MSBuildProjectFullPath.

Copy link
Member Author

@jjonescz jjonescz Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, interesting. I'm not sure what to do differently here though. You can always opt out from the attribute via GenerateUserSecretsAttribute=false.

I guess we could try using $(PathMap) here as well, but that seems like an overkill given you need to be referencing UserSecrets assembly and then there are opt outs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eww yeah I strongly agree with @KalleOlaviNiemitalo here - we can't set this during eval time like this.

If we had a concept of the repo/workspace root then we could use the part of the project full path from that root safely - but we only know that data once the source link targets have run..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Microsoft.Extensions.Configuration.UserSecrets is referenced by Microsoft.Extensions.Hosting, so I think this PR will cause UserSecretsIdAttribute to be generated in many services whose developers were not intending to use user secrets.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @DamianEdwards - looks like setting UserSecretsId implicitly in SDK targets might be problematic.

I can instead implement this implicit UserSecretsId computation in the user-secrets tool, but that means normal builds won't see it (e.g., custom build targets that want to read UserSecretsId for some reason).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jjonescz yep fair enough. Side effects are impactful here so seems like the right place to do it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Realized that wouldn't work - the runtime side of user-secrets config wouldn't see the ID. What about limiting this to file-based apps only? #50783

Comment on lines +137 to +138
<!-- Implicitly set UserSecretsId to hash of project file path. -->
<UserSecretsId Condition="'$(UserSecretsId)'==''">$([MSBuild]::StableStringHash($(MSBuildProjectFullPath), 'Sha256'))</UserSecretsId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another effect of this change is that, if I find a user secrets file in my user profile and want to know which project is using it and whether the file would be safe to delete, I won't be able to identify the project by grepping for the user secrets ID in source trees.

However, the format of the user secrets ID will hint that it was generated by [MSBuild]::StableStringHash rather than dotnet user-secrets init, which generates a GUID.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could append the project name to the ID to help with this.

@jjonescz jjonescz closed this Sep 9, 2025
@jjonescz jjonescz deleted the sprint-user-secrets branch September 9, 2025 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-run-file Items related to the "dotnet run <file>" effort
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants