KEMBAR78
Directory.build.targets not imported when cross-targeting · Issue #1721 · dotnet/msbuild · GitHub
Skip to content

Directory.build.targets not imported when cross-targeting #1721

@tmat

Description

@tmat

Microsoft.Common.CrossTargeting.targets doesn't import these. As a result properties and tasks defined in Directory.build.props, Directory.build.targets are not available in the outer build.

Repro:

  1. Create a .NET Core Library with project:
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFrameworks>netcoreapp1.0;net46</TargetFrameworks>
  </PropertyGroup>
</Project>
  1. Add Directory.Build.targets next to the .csproj file:
<Project>  
  <Target Name="MyTarget">
    <Error Text="Boom!"/>
  </Target>
</Project>
  1. Run
> msbuild /t:Restore ClassLibrary.csproj
...
> msbuild /t:MyTarget ClassLibrary.csproj
Project "ClassLibrary.csproj" on node 1 (MyTarget target(s)).
ClassLibrary.csproj : error MSB4057: The target "MyTarget" does not exist in the project.
Done Building Project "ClassLibrary.csproj" (MyTarget target(s)) -- FAILED.

If the project targets a single framework like so:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp1.0</TargetFramework>
  </PropertyGroup>
</Project>

The target is invoked as expected:

Project "ClassLibrary.csproj" on node 1 (MyTarget target(s)).
Directory.Build.targets(7,5): error : Boom!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions