question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ContentFiles not included with multiple TargetFrameworks and --no-incremental after upgrading to 6.0.300

See original GitHub issue

Describe the bug

After installing the 6.0.300 SDK, running dotnet build --no-incremental fails when using <TargetFrameworks> (plural) and including a nuget package that bundles source files as contentFiles (as described in docs here).

Specifically, multi-targeted projects using the popular Nullable library by @manuelroemer started failing non-incremental builds after upgrading to 6.0.300. This library provides a shim for nullability annotations on older targets, and does so by including several .cs.pp source files under contentFiles in its nuget package. The problem isn’t with this library, but that the files it provides are being excluded from the build.

It does work when passing a specific framework (such as -f net48), or when only specifying a single <TargetFramework>. So I believe the problem is with content files not being included when dispatching to each framework’s build.

Everything does work when the .NET SDK is pinned to 6.0.203 in a global.json file, so this is new for 6.0.300.

I tried on both Windows 11 21H2 and macOS 12.4 with the same results.

To Reproduce

See minimal repro in issue here: https://github.com/manuelroemer/Nullable/issues/24

Failed build output:

C:\Users\mattj\Code\MyApp>dotnet build --no-incremental                                          
Microsoft (R) Build Engine version 17.2.0+41abc5629 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  All projects are up-to-date for restore.
C:\Users\mattj\Code\MyApp\Program.cs(16,35): error CS0246: The type or namespace name 'NotNullWhenAttribute' could not be found (are you m
issing a using directive or an assembly reference?) [C:\Users\mattj\Code\MyApp\MyApp.csproj]
C:\Users\mattj\Code\MyApp\Program.cs(16,35): error CS0246: The type or namespace name 'NotNullWhen' could not be found (are you missing a 
using directive or an assembly reference?) [C:\Users\mattj\Code\MyApp\MyApp.csproj]
  MyApp -> C:\Users\mattj\Code\MyApp\bin\Debug\net6.0\MyApp.dll

Build FAILED.

C:\Users\mattj\Code\MyApp\Program.cs(16,35): error CS0246: The type or namespace name 'NotNullWhenAttribute' could not be found (are you m 
issing a using directive or an assembly reference?) [C:\Users\mattj\Code\MyApp\MyApp.csproj]
C:\Users\mattj\Code\MyApp\Program.cs(16,35): error CS0246: The type or namespace name 'NotNullWhen' could not be found (are you missing a  
using directive or an assembly reference?) [C:\Users\mattj\Code\MyApp\MyApp.csproj]
    0 Warning(s)
    2 Error(s)

Time Elapsed 00:00:01.01

Working build output (without --no-incremental):

C:\Users\mattj\Code\MyApp>dotnet build                 
Microsoft (R) Build Engine version 17.2.0+41abc5629 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  All projects are up-to-date for restore.
  MyApp -> C:\Users\mattj\Code\MyApp\bin\Debug\net48\MyApp.exe
  MyApp -> C:\Users\mattj\Code\MyApp\bin\Debug\net6.0\MyApp.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:00.94

Further technical details

  • Include the output of dotnet --info
C:\Users\mattj>dotnet --info
.NET SDK (reflecting any global.json):
 Version:   6.0.300
 Commit:    8473146e7d

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22000
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\6.0.300\

Host (useful for support):
  Version: 6.0.5
  Commit:  70ae3df4a6

.NET SDKs installed:
  2.1.818 [C:\Program Files\dotnet\sdk]
  3.1.419 [C:\Program Files\dotnet\sdk]
  5.0.408 [C:\Program Files\dotnet\sdk]
  6.0.202 [C:\Program Files\dotnet\sdk]
  6.0.203 [C:\Program Files\dotnet\sdk]
  6.0.300 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.25 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.25 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.25 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  • The IDE (VS / VS Code/ VS4Mac) you’re running on, and its version N/A - occurs on command line

  • Here are binlogs that may be useful: binlogs.zip

Thanks

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:7
  • Comments:14 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
asherbercommented, Jul 8, 2022

On .pp files: https://docs.microsoft.com/en-us/nuget/create-packages/source-and-config-file-transformations#specifying-source-code-transformations

It may have been a workaround in Nullable, but in other libraries (like LibLog), it’s a legitimate way to include transformable source code files in a NuGet package.

2reactions
gtbuchanancommented, Jul 8, 2022

The issue appears to be related to the use of .pp as the file extension to hide the file in Visual Studio. I believe this is fixed with https://github.com/manuelroemer/IsExternalInit/pull/14 and https://github.com/manuelroemer/Nullable/pull/26. I couldn’t find any official info about the .pp file extension so I’m not sure if it was just a hack nor why this would only be a problem with the Rebuild target and TargetFrameworks property.

@seesharper I see that LightInject.Source is also using this strategy so it might benefit from the same change as an alternative to waiting for this to be fixed here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nuget package contentFiles not copied to .NET Core project
I install this Nuget package in my .NET Core 2.1 project but the image is missing. No trace of the image in the...
Read more >
NuGet package's content files are not copied to .NET Core ...
Neither "files" nor "contentFiles" are copied to the project, if it is referenced. So what is the solution then?
Read more >
Multi-targeting for NuGet Packages
Description of the various methods to target multiple .NET Framework versions from within a single NuGet package.
Read more >
Support multiple .NET Framework versions in your project file
Description of the various methods to target multiple .NET Framework versions from within a single NuGet package in your project file.
Read more >
Copy files from the NuGet package to the destination ...
But I have an issue with copying files to the module folder in the destination project when installing. It creates some references for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found