Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directory.Build.targets is not imported for multi-targeting projects where TargetFramework is not defined #1991

Closed
AArnott opened this issue Apr 19, 2017 · 1 comment
Labels

Comments

@AArnott
Copy link
Contributor

AArnott commented Apr 19, 2017

When a "Microsoft.NET.Sdk" project defines a TargetFrameworks property instead of a TargetFramework property (effectively activating the multi-targeting behavior), it no longer imports Directory.Build.targets in the top-level evaluation.

When a TargetFramework is set, it imports both Directory.Build.props and Directory.Build.targets.
But when only TargetFrameworks is defined, it only imports Directory.Build.props.

This distinction is very subtle and unexpected. It took me quite some time to diagnose a build issue before I figured this out. I trust this was an unintentional oversight that can be fixed.

Repro project:
dirprops.zip

When building the Restore target, I see this:

msbuild /t:restore
  Restoring packages for C:\temp\dirprops\lib\lib.csproj...
  Lock file has not changed. Skipping lock file write. Path: C:\temp\dirprops\lib\obj\project.assets.json
  Restore completed in 378.45 ms for C:\temp\dirprops\lib\lib.csproj.

  NuGet Config files used:
      C:\Users\andarno\AppData\Roaming\NuGet\NuGet.Config
      C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config

  Feeds used:
      https://api.nuget.org/v3/index.json
      C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
  AddInProps is executing...

But when I define TargetFramework I see both targets executing:

msbuild /t:restore /p:targetframework=netstandard1.3
  Restoring packages for C:\temp\dirprops\lib\lib.csproj...
  Generating MSBuild file C:\temp\dirprops\lib\obj\lib.csproj.nuget.g.props.
  Generating MSBuild file C:\temp\dirprops\lib\obj\lib.csproj.nuget.g.targets.
  Writing lock file to disk. Path: C:\temp\dirprops\lib\obj\project.assets.json
  Restore completed in 764.25 ms for C:\temp\dirprops\lib\lib.csproj.

  NuGet Config files used:
      C:\Users\andarno\AppData\Roaming\NuGet\NuGet.Config
      C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config

  Feeds used:
      https://api.nuget.org/v3/index.json
      C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
  AddInProps is executing...
  AddInTargets is executing...
@rainersigwald
Copy link
Member

Duplicate of #1721, fixed for the 15.3 release.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants