novotnyllc / MSBuildSdkExtras

Extra properties for MSBuild SDK projects
MIT License
347 stars 42 forks source link

Solution dependencies fail due to RuntimeIdentifier being forwarded #139

Open xen2 opened 5 years ago

xen2 commented 5 years ago

I have a project with multiple RuntimeIdentifiers and it fails to build a solution reference which doesn't have a RuntimeIdentifier.

Error is

Assets file 'C:\DEV\xenko\sources\core\Xenko.Core.Tasks\obj\project.assets.json' doesn't have a target for '.NETFramework,Version=v4.7.2/win7-d3d11'. Ensure that restore has run and that you have included 'net472' in the TargetFrameworks for your project. You may also need to include 'win7-d3d11' in your project's RuntimeIdentifiers.

I think what it needs is to have RuntimeIdentifier in the ProjectReferenceWithConfiguration.GlobalPropertiesToRemove: image

MSBuild code reference (where TargetFramework is hardcoded): https://github.com/Microsoft/msbuild/blob/e77fa08888dbf7d6478b7659aeaccc39ce04c435/src/Tasks/ResolveProjectBase.cs#L280

xen2 commented 5 years ago

I could fix the problem with this kind of target:

  <Target Name="_XenkoRemoveRuntimeIdentifierFromSolutionDependencies" AfterTargets="AssignProjectConfiguration">
    <ItemGroup>
      <ProjectReferenceWithConfiguration Condition="'%(ProjectReferenceWithConfiguration.ReferenceSourceTarget)' != 'ProjectReference'">
        <GlobalPropertiesToRemove>%(ProjectReferenceWithConfiguration.GlobalPropertiesToRemove);RuntimeIdentifier</GlobalPropertiesToRemove>
      </ProjectReferenceWithConfiguration>
    </ItemGroup>
  </Target>
clairernovotny commented 5 years ago

Can you please submit a PR with the fix?