-
Couldn't load subscription status.
- Fork 1.2k
Description
Describe the bug
There is a race condition in common publish targets which creates intermittent issues in a customer project when they dotnet publish a solution that references a project P (e.g. a test project) and it's dependency D which has dependencies E1,E2,....
In short: if the p2p GetCopyToPublishDirectoryItems target triggers first it fails, if the sln ref triggers first it works.
In the correct case:
Publish runs in order AssignProjectConfiguration, _SplitProjectReferencesByFileExistence, _ComputeUserRuntimeAssemblies
In the wrong case:
Publish calls AssignProjectConfiguration, but _SplitProjectReferencesByFileExistence was already run and is therefore skipped.
So the situtation can produce intermittently wrong D.deps.json with E1,E2... missing and runtime errors.
To Reproduce
A consistent reproduction can be simulated here:
dotnet new console -o dts_repro
dotnet new classlib -o dependency
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<!-- empty project -->
<ProjectReference Include="..\dependency\dependency.csproj" />
</ItemGroup>
<Target Name="WrongOrder">
<MSBuild Projects="dts_repro.csproj" Targets="GetCopyToPublishDirectoryItems" />
<MSBuild Projects="dts_repro.csproj" Targets="Publish" />
</Target>
</Project>
dotnet build -t:WrongOrder
workaround we identified (yet to be confirmed by customer)
<Target Name="WorkaroundDTS2292725"
BeforeTargets="_SplitProjectReferencesByFileExistence"
DependsOnTargets="AssignProjectConfiguration" />Further technical details
17.13 common publish targets