dotnet / dotnet/msbuild

Project references not always copied even when Private is transitively set to True

Open
#1,845 3 comments 8 reactions 0 assignees View on GitHub
needs-design triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 8h
Merged PRs (30d)
141

Description

# Overview
Take [the following solution][reprorepo], with emphasis on references:
![References overview](https://cloud.githubusercontent.com/assets/8878006/23790767/c9ac4fc6-0580-11e7-85c8-49a08347f035.png)
Solid lines denote project references with `Private` set to `True`.
Dashed lines denote project references with `Private` set to `False`.
Dash-dot lines denote project references with `Private` undefined.

# Issue
With MSBuild 14.0, `ClassLibrary0` is not copied to `ConsoleApplication6`'s output directory.
This is consistent for builds from inside Visual Studio 2015, as well as from the command line.

# Analysis
Using Kirill Osenkovs [MSBuild Structured Log Viewer][analysis-tool].
In the build of `ConsoleApplication6`, MSBuild realizes it needs `ClassLibrary0`. However, for whatever reasons it cannot find the reference:
![build-analysis-1](https://cloud.githubusercontent.com/assets/8878006/23790766/c9ab9324-0580-11e7-9c94-299f5b3fe69e.png)

A partial insight is given by this message when building `ClassLibrary2`.
![build-analysis-2](https://cloud.githubusercontent.com/assets/8878006/23790765/c9ab7006-0580-11e7-825f-88aef0796b5d.png)

We now understand and accept that `ClassLibrary0` won't be copied to `ClassLibarary2`.

Note that this means that the `Private` flag is actually [tri-state][quotegravell], which can be quite a surprise for Visual Studio users acustomed to the boolean `Copy Local` property.

However, this doesn't explain why `ClassLibrary0` is not copied to `ConsoleApplication6`, since there is a complete chain of project references having `Private` set to `True` straight from `ConsoleApplication6` to `ClassLibrary0`.

# Work-Around
From the analysis, it's quite easy to fix the issue:
Set `Private = True` for the project reference from `ClassLibrary2` to `ClassLibrary1`.

[reprorepo]: https://github.com/chm-tm/msbuild-projectref-private-glitch
[analysis-tool]: https://github.com/KirillOsenkov/MSBuildStructuredLog
[quotegravell]: http://stackoverflow.com/questions/14923804/assembly-being-copied-local-when-it-shouldnt-be#comment20939785_14923854

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.