[Bug]: Appears to be impossible to run a command between build dependent projects and expand wildcards
- Dominant language
- C#
- Stars
- 5.5k
- Forks
- 1.5k
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 141
Description
### Issue Description
Stackoverflow reference here: https://stackoverflow.com/questions/77929595/how-do-i-late-resolve-in-csproj-files
The stackoverflow reproduction is overshortened; what's going on is the "dotnet run" command runs a direct dependency.
Trying to fix it:
```
BeforeTargets="BeforeBuild" is too early
BeforeTargets="PrepareResources" is too late
BeforeTargets="BeforeCompile" is too late
BeforeTargets="BeforePrepareResources" cannot function as that target doesn't exist
```
Regression? Probably. According to our git repo; this worked in the feature development branch on 2024-02-05 on .NET 8 (which means the sdk must be a .NET 8 version but I can't ask git history for the exact sdk version) and broke since. I can't get a sane answer of the branch maintainer when it started failing because he conflates it with this bug: https://github.com/dotnet/msbuild/issues/9179
### Steps to Reproduce
1) Unpack this[msbuildrace.zip](https://github.com/user-attachments/files/17335409/msbuildrace.zip) zip file; it creates a directory msbuildrace
2) from a clean tree; try to build the dll and get the error
`...\msbuildrace\dll> dotnet build`
3) try to fix that error by changing BeforeBuild to BeforeCompile and try again
`...\msbuildrace\dll>sed -i s/BeforeTargets=^"BeforeBuild^"/BeforeTargets=^"BeforeCompile^" dll.csproj`
`...\msbuildrace\dll>dotnet build`
`...\msbuildrace\dll>dir bin\Debug\net8.0\*.dat`
There should be two .dat files in the compilation output but we got none.
### Expected Behavior
Build runs through and expands * after the custom build step runs so that CopyToOutputDirectory works
Note that having the tool write them to the output directory *doesn't work* because this is a dll and the copy needs to propagate.
### Actual Behavior
Random build breakage depending on a CPU race condition; I think I made a reliable reproduction but it might not be.
### Analysis
msbuild does wildcard expansion too soon
### Versions & Configurations
D:\dev>dotnet --version
8.0.403
D:\dev>dotnet msbuild --version
MSBuild version 17.11.9+a69bbaaf5 for .NET
17.11.9.46202
We don't use the standalone msbuild; only dotnet build (which contains an embedded copy of msbuild)
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.