Azure / Azure/azure-functions-core-tools
Incorrect warning ".csproj not found in (...) directory tree. Skipping user secrets file configuration." when using siblings \src and \bin folders
- Dominant language
- C#
- Stars
- 1.5k
- Forks
- 498
- Avg merge
- 5d 4h
- Merged PRs (30d)
- 15
Description
### Version
Latest version.
https://github.com/Azure/azure-functions-core-tools/blob/9d08c4305e1e97ca9f7935ec79ef2ccd3e996179/src/Azure.Functions.Cli/Helpers/ProjectHelpers.cs
### Description
In Visual Studio 2022 with C#, when a MyAzureFunction.csproj file has a MSBuild property "UserSecretsId" to use Secrets Manager but its output folder (bin\) is not a subfolder of the folder of the .csproj file, the following false warning is shown:
`"Csproj not found in \bin\Debug\MyAzureFunction\net9.0 directory tree. Skipping user secrets file configuration."
`
This is because in the azure-functions-core-tools/src/Azure.Functions.Cli/Helpers/ProjectHelpers.cs file (https://github.com/Azure/azure-functions-core-tools/blob/9d08c4305e1e97ca9f7935ec79ef2ccd3e996179/src/Azure.Functions.Cli/Helpers/ProjectHelpers.cs#L44), there is a function FindProjectFile to find the .csproj file and then the "UserSecretsId" property.
Instead, it should try to find the [assembly: UserSecretsId("mysecretid")] attribute inside the compiled assembly, so that it is independent of the source code location.
### Steps to reproduce
Create a Visual Studio solution with this layout:
```
mysolution.sln
Directory.Build.props
\src\MyAzureFunction.csproj
\src\(.cs files)
\bin\
\obj\
```
where Directory.Build.props has this content:
```
$(MSBuildThisFileDirectory)obj\$(MSBuildProjectName)\
$(MSBuildThisFileDirectory)bin\$(Configuration)\$(MSBuildProjectName)\
```
so that the compiled assembly is generated in this folder:
`\bin\Debug\myazurefunction\net9.0`
instead of in this folder:
`\src\bin\Debug\myazurefunction\net9.0`
and add the following property to the .csproj file:
```
my_guid
```
Then, run the project from within Visual Studio. You get a warning:
`".csproj not found in (...) directory tree. Skipping user secrets file configuration."`
while actually the compiled assembly has the attribute UserSecretsId and it can use Secrets Manager.
Contributor guide
Research direction
Start in src/Azure.Functions.Cli/Helpers/ProjectHelpers.cs, especially FindProjectFile and the UserSecretsId lookup, then reproduce the issue with the sibling src and bin layout described. Trace how the compiled assembly is located and inspected; done means the warning is not emitted and the UserSecretsId attribute can still configure user secrets for this layout.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100