NuGet/Home

Comment for not-imported package build logic

Open

#8,445 opened on Aug 12, 2019

View on GitHub
 (2 comments) (1 reaction) (0 assignees)HTML (292 forks)batch import
Area:LoggingFunctionality:RestorePriority:2Style:PackageReferenceType:DCRhelp wanted

Repository metrics

Stars
 (1,459 stars)
PR merge metrics
 (Avg merge 464d 23h) (1 merged PR in 30d)

Description

I just had a bad time trying to figure out why a package I referenced wasn't working for one of the TargetFrameworks in the project. It turned out that this was because we (accidentally) referenced the package only for one of the TFs in the project.

NuGet (correctly!) generated MSBuild logic to import the build/ folder from the package for the affected TF and for the outer build, but not for the other TF in the project.

It would have been nice if there had been a breadcrumb in the generated build logic that said something like

<!-- Package Whatever is not referenced in TargetFramework X -->

Details about Problem

NuGet product used (NuGet.exe | VS UI | Package Manager Console | dotnet.exe): dotnet CLI primarily

NuGet version (x.x.x.xxx): 5.3.0.0

dotnet.exe --version (if appropriate): 3.0.100-preview9-013744

VS version (if appropriate): 16.3 previews

OS version (i.e. win10 v1607 (14393.321)): all

Worked before? If so, with which NuGet version: no

Detailed repro steps so we can see the same problem

Have a conditional package reference, like

  <ItemGroup Condition="'$(TargetFramework)' == 'net46'">
    <PackageReference Include="MicroBuild.Core" Version="0.3.0" /><!-- can be any package with a build/ folder -->
  </ItemGroup>

Restore. The generated .props file looks like

  <ImportGroup Condition=" '$(TargetFramework)' == '' AND '$(ExcludeRestorePackageImports)' != 'true' ">
    <Import Project="$(NuGetPackageRoot)microbuild.core\0.3.0\buildCrossTargeting\MicroBuild.Core.props" Condition="Exists('$(NuGetPackageRoot)microbuild.core\0.3.0\buildCrossTargeting\MicroBuild.Core.props')" />
  </ImportGroup>
  <ImportGroup Condition=" '$(TargetFramework)' == 'net46' AND '$(ExcludeRestorePackageImports)' != 'true' ">
    <Import Project="$(NuGetPackageRoot)microbuild.core\0.3.0\build\MicroBuild.Core.props" Condition="Exists('$(NuGetPackageRoot)microbuild.core\0.3.0\build\MicroBuild.Core.props')" />
  </ImportGroup>

I'd love to see an additional comment for each import that could have been emitted but wasn't because the reference was not valid for that TF.

Sample Project

8845.zip

Contributor guide