msbuild: P2Ps should be allowed when ReferenceOutputAssembly=false even given TFM incompatibilities

From @AArnott on March 3, 2017 18:40

With VS2015 projects, I can have a P2P from a portable library to a net46 library by setting metadata on the project reference:

<ProjectReference Include="..\SomeNet46Lib\lib.csproj">
  <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>

But with the .NET SDK projects, even with this metadata the build fails:

C:\Program Files (x86)\Microsoft Visual Studio\2017\d15rel\MSBuild\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.Common.targets(73,5): error : Project ‘C:\git\pinvoke\src\CodeGeneration\CodeGeneration.csproj’ targets ‘.NETFramework,Version=v4.6’. It cannot be referenced by a project that targets ‘.NETPortable,Version=v0.0,Profile=Profile92’. [C:\git\pinvoke\src\CodeGeneration\CodeGeneration.csproj]

This blocks scenarios where a P2P exists merely for the sake of ensuring build ordering but without the assembly reference. In my particular scenario, the referenced project provides a binary that the build of the portable library picks up for code generation purposes.

Copied from original issue: dotnet/sdk#939

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 8
  • Comments: 30 (25 by maintainers)

Commits related to this issue

Most upvoted comments

@rainersigwald What’s the plan for getting this fixed?

If I’m hitting this now, how am I supposed to work around it? I see https://github.com/Microsoft/msbuild/issues/2661#issuecomment-338808156, but how exactly am I supposed to be using that? Does that only work if I’m using solution-level dependencies, or is there a way to use a ProjectReference as well?

I’m asking because I’ve been able to get it working with a solution-level dependency, but because of other, unrelated problems, I can’t use solution-level dependencies right now. Is there a way to use a ProjectReference and still have my solution build with MSBuild?

Also running into this. I’m trying to build a netcoreapp3.1 exe and include it in a NuGet package under /tools, e.g.:

<ItemGroup>
  <None Include="..\Faithlife.AssemblyEmbedder\bin\$(Configuration)\netcoreapp3.1\**" Pack="true" PackagePath="/tools/netcoreapp3.1/" />
</ItemGroup>

This works fine but ideally I’d like to have a reference so that Faithlife.AssemblyEmbedder is always built before my NuGet package csproj. I have a dependency in the sln file but dotnet pack ignores that.

Currently my workaround is to just do a separate dotnet build before the dotnet pack to ensure the project is built before it’s included.

@rainersigwald any comments on the above question?

FYI something in 15.5 seems to have broken my workaround while not resolving the original bug.

Fortunately setting AddSyntheticProjectReferencesForSolutionDependencies to True in the dependent project seems to work.

I would think SkipGetTargetFrameworkProperties=true metadata on ProjectReference would work now and that we should set this automatically when ReferenceOutputAssembly=false.

From @rainersigwald on August 23, 2017 18:47

Workaround

Set

<AddSyntheticProjectReferencesForSolutionDependencies>false</AddSyntheticProjectReferencesForSolutionDependencies>

in the project that has the ProjectReference to the incompatible project. This prevents the elevation of solution build dependencies to ProjectReferences in AssignProjectConfiguration.

(Was poking around near this target for another reason and saw this.)