Msbuild: Make it easier to express dependencies among projects without referencing output assembly

Created on 9 Oct 2018  路  4Comments  路  Source: dotnet/msbuild

_From @tmat on October 8, 2018 23:44_

It is sometimes necessary to build project A before project B without project B referencing the assembly that A generates. In such cases one can use ProjectReference with ReferenceOutputAssembly="false".

This however is not sufficient in all scenarios, especially when these projects target different, incompatible frameworks and/or multi-target.

Turns out 3 properties need to be set to make this work:

<ProjectReference Include="B.csproj" 
       ReferenceOutputAssembly="false"
       SkipGetTargetFrameworkProperties="true"
       GlobalPropertiesToRemove="TargetFramework" />

This is much more complex than it should be.

Proposal: introduce a new item that can be use to express that this project depends on building another project, but has no implication on references. Such item could be called e.g. ProjectBuildOrderDependency, DependsOnProject, etc.

<DependsOnProject Include="B.csproj" />

_Copied from original issue: dotnet/sdk#2574_

Most helpful comment

I don't think adding a new item type is the right way to fix this, because ProjectReference is semantically meaningful to VS and other consumers.

I wish we had made ReferenceOutputAssembly="false" have this behavior, but because we shipped the way we did, we can't fix that now -- see https://github.com/Microsoft/msbuild/issues/2661 (and why the fix for it got backed out). This might actually just be a duplicate of that bug.

We could potentially just add a BuildOrderingOnly="true" or something, and recommend using that always over ReferenceOutputAssembly.

All 4 comments

_From @nguerrera on October 8, 2018 23:45_

cc @rainersigwald

Any change here would need to live on the MSBuild side of the fence, because you can have dependencies to SDK projects from non-SDK projects.

I don't think adding a new item type is the right way to fix this, because ProjectReference is semantically meaningful to VS and other consumers.

I wish we had made ReferenceOutputAssembly="false" have this behavior, but because we shipped the way we did, we can't fix that now -- see https://github.com/Microsoft/msbuild/issues/2661 (and why the fix for it got backed out). This might actually just be a duplicate of that bug.

We could potentially just add a BuildOrderingOnly="true" or something, and recommend using that always over ReferenceOutputAssembly.

I agree with everything you wrote. There are actually two workarounds here vs. the desire of just saying ReferenceOutputAssembly="false"

  1. SkipGetTargetFrameworkProperties (works around #2661, which I think at this point is by design / won't fix)
  2. GlobalPropertiesToRemove (works around #2366, which I think we still hope to fix -- there's an active PR)

Since it doesn't seem we can compatibly make ReferenceOutputAssembly="false" the master switch, I vote +1 on BuildOderingOnly="true" or some other new metadata.

Was this page helpful?
0 / 5 - 0 ratings