Graph build with traversal projects packs each TargetFramework of multi-targeting projects
- Dominant language
- C#
- Stars
- 5.5k
- Forks
- 1.5k
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 141
Description
### Issue Description
A csproj with a `TargetFrameworks` property should only be packed in the build of the project that has no `TargetFramework` global property defined. Traversal projects honor this, unless `-graph` is specified at the command line. Then all target frameworks try to pack. When this happens concurrently, the build often fails with a timing break.
### Steps to Reproduce
It's simple, really. Take a simple csproj:
```xml
net9.0;net8.0
```
A traversal that points to it:
```xml
```
And a global.json:
```json
{
"sdk": {
"version": "9.0.300",
"rollForward": "patch",
"allowPrerelease": false
},
"msbuild-sdks": {
"Microsoft.Build.Traversal": "4.1.82"
}
}
```
Or use [Repro.zip](https://github.com/user-attachments/files/20496697/Repro.zip)
Then run `dotnet pack -graph -bl`. You'll likely see the break. And if you don't, you can try again (after removing build artifacts), or just inspect the .binlog to see that too many `GenerateNuspec` targets ran.
Then try again with just `dotnet pack` (again, in a clean state) and it will work properly.
### Expected Behavior
I expect `dotnet build -graph` to run the Pack target only on SomePackage.csproj top-level, no TargetFramework properties specified.
### Actual Behavior
Timing break due to overbuild of the `Pack` target.
```
SomePackage net9.0 failed with 1 error(s) (0.2s) → SomePackage\bin\Release\net9.0\SomePackage.dll
C:\Program Files\dotnet\sdk\9.0.300\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error : The process cannot access the file 'C:\temp\msbuildbugrepro\SomePackage\obj\Release\SomePackage.1.0.0.nuspec' because it is being used by another process.
SomePackage net8.0 succeeded (0.4s) → SomePackage\bin\Release\net8.0\SomePackage.dll
```
### Analysis
_No response_
### Versions & Configurations
_No response_
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.