[Feature Request]: ability to create target maps when circular dependency exists instead of exiting with error
- Dominant language
- C#
- Stars
- 5.5k
- Forks
- 1.5k
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 141
Description
### Summary
Using the `-graph` (target graph) feature to build a graph involving a circular dependency would be tremendously helpful to debug and get rid of the circular dependency. The circular dependency could be pointed out by way of outlining it in a different color or otherwise.
### Background and Motivation
Please consider [ClVersionRetrieve.proj](https://github.com/assarbad/msbuild-batching/blob/main/ClVersionRetrieve.proj) as of [dda59c6](https://github.com/assarbad/msbuild-batching/commit/dda59c6794a84677626e7ea1bc6d6c6d7f6fc13f).
The project mimics a Visual C++ project, but sidesteps the actual `Build` target.
When I originally built it prior to the revision mentioned above, I was only able to build it directly like so:
```
msbuild -p:Configuration=Release -t:ClVersionRetrieve -verbosity:normal ClVersionRetrieve.proj
```
however, using the `Rebuild` target instead (or using it from within the solution):
```
msbuild -p:Configuration=Release -t:Rebuild -verbosity:normal ClVersionRetrieve.proj
```
caused an error:
```
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(5587,7): error MSB4006: There is a circular dependency in the
target dependency graph involving target "CleanReferencedProjects". [D:\source\repos\msbuild-batching\ClVersionRetrieve.proj]
```
The error refers to the `DependsOnTargets` attribute in the following snippet:
```
```
With the aforementioned revision I emptied out the `Clean` target (and removed all its dependencies and dependents) to resolve the issue.
However, even after doing that I get an error when attempting to create the target graph, while the build itself works fine. The error I get when attempting the above is:
```
$ msbuild -p:Configuration=Release -t:Rebuild -verbosity:normal ClVersionRetrieve.proj -graph
MSBuild version 17.7.2+d6990bcfa for .NET Framework
Build started 2023-09-26 22:20:03.
MSBUILD : error : MSB4251: There is a circular dependency involving the following projects:
MSBUILD : error : D:\source\repos\msbuild-batching\ClVersionRetrieve.proj ->
MSBUILD : error : D:\source\repos\msbuild-batching\ClVersionRetrieve.proj
Build FAILED.
MSBUILD : error : MSB4251: There is a circular dependency involving the following projects:
MSBUILD : error : D:\source\repos\msbuild-batching\ClVersionRetrieve.proj ->
MSBUILD : error : D:\source\repos\msbuild-batching\ClVersionRetrieve.proj
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.15
```
### Proposed Feature
Extend `-graph` such that it doesn't issue `MSB4251` and instead -- at most -- outputs a warning, otherwise proceeding to output a graph that can be used to investigate the circular dependency issue.
### Alternative Designs
_No response_
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.