MsBuild SDK project style: project dependencies sometimes fails

1.2k views Asked by At

In the solution I have some dependent project configured as SDK style projects:

  • Proj A responsible for doing some routine as MsBuild task
  • Proj B project which requires such processing for compiling correctly
  • Task is configured at Proj B as MsBuild target with attribute BeforeTargets="CoreCompile".

Based on that Proj A should be fully compiled before running task on Proj B compilation. Both projects has different compilation target (NetStandard20 and Net462). Therefore I couldn't make a direct reference but do solution-wide project dependency with setting property AddSyntheticProjectReferencesForSolutionDependencies as false (otherwise msbuild tries to make project dependency forcible).

In that setup, MsBuild sometimes fails on compilation: Proj A started to compile but haven't finished in time when Proj B run the task. MSBuild is started on CI machine with key /m.

Any ideas are welcomed.

1

There are 1 answers

5
Martin Ullrich On BEST ANSWER

In this case you actually do want a synthetic project reference but there is a subtle issue in MSBuild at the moment that creates some issues across project references if the project having the dependency is multi-targeting. This is fixed in 15.9.

Please try it out in the visual studio preview version of 15.9 (at the time of writing: 15.9 Preview 2).

If you don't want to wait, you can add a similar project reference in the csproj file yourself:

<ItemGroup>
  <ProjectReference Include="..\other\project.csproj"
    ReferenceOutputAssembly="false"
    LinkLibraryDependencies="false"
    CopyLocal="false"
    SkipGetTargetFrameworkProperties="true"
    GlobalPropertiesToRemove="TargetFramework"
    />
</ItemGroup>