dotnet / dotnet/msbuild

ResolveReferences dependency on GenerateBindingRedirects target causes intermittent publishing failures

Open
#10,901 0 comments 0 reactions 0 assignees View on GitHub
Area: NetSDK gathering-feedback triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 8h
Merged PRs (30d)
141

Description

## Problem

Roslyn build from Visual Studio intermittently fails with error:

```
C:\Program Files\dotnet\sdk\9.0.100-rc.2.24474.11\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(355,5): error MSB3030: Could not copy the file "D:\github\roslyn\artifacts\obj\InteractiveHost64\Debug\net472\win-x64\InteractiveHost64.exe.config" because it was not found. [D:\github\roslyn\src\Interactive\HostProcess\x64\InteractiveHost64.csproj]
```

This is caused by the following sequence of events:

1) Roslyn.VisualStudio.Setup.csproj invokes build of InteractiveHost64.csproj with entry target `PublishedProjectOutputGroup`, which depends on target `PublishItemsOutputGroup`.
2) Roslyn.VisualStudio.Setup.csproj invokes build of InteractiveHost64.csproj with entry target `PublishVsixItems`, which depends on target `Publish` and transitively also on `PublishItemsOutputGroup`.
3)

`PublishItemsOutputGroup` depends on `ResolveReferences`, which depends on `GenerateBindingRedirects`.

`GenerateBindingRedirects` has condition `'$(BuildingProject)' == 'true'"`.

`BuildingProject` property is set by `BuildOnlySettings` in various targets that need to build assets (`Build`, `Publish`, etc.). However, `BuildOnlySettings` is not set by `PublishItemsOutputGroup` as this target should only determine the items to be published but not publish them.

The invocation of `PublishItemsOutputGroup` in [1] skips generation of binding redirects (`BuildingProject` is `false') and the second invocation is skipped because the target already executed. As a result the App.config file is never written to and the build subsequently fails to copy the file.

Binlog: [RoslynVSBuild.zip](https://github.com/user-attachments/files/17548484/RoslynVSBuild.zip)

## Proposal

It doesn't seem like `ResolveReferences` should depend on the content of the generated App.config file. It should therefore not depend on `GenerateBindingRedirects` target:

```xml



BeforeResolveReferences;
AssignProjectConfiguration;
ResolveProjectReferences;
FindInvalidProjectReferences;
ResolveNativeReferences;
ResolveAssemblyReferences;
GenerateBindingRedirects;
GenerateBindingRedirectsUpdateAppConfig;
ResolveComReferences;
AfterResolveReferences


```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.