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.

Rebuild fails when project with multiple TFMs references Source Code-only Nuget package

See original GitHub issue

Issue Description

  • I have a csproj that targets both net48 and net6.0
  • It also references a Source-code only nuget package (AddUp.AnyLog in this example, but reproduced with other similar packages)
  • If I rebuild (from VS or with dotnet build --no-incremental or with MSBuild /t:Rebuild), it fails
  • If I simply build, it works fine
  • Note that in the single TFM case, everything works just fine.

Steps to Reproduce

  • Use the attached solution: MultipleTfmsSourceOnlyRepro.zip
  • Then either:
    • dotnet build .\MultipleTfmsSourceOnlyRepro.sln --no-incremental or
    • MSBuild.exe .\MultipleTfmsSourceOnlyRepro.sln /t:Rebuild or
    • Rebuild from Visual Studio 2022
  • You should obtain a few CS0234 and CS0236 errors (types and namespaces that cannot be found)
    • In the VS case, I also some time after I interact with the editor get a handful of IDE1100 errors (Error reading content of source file…)
  • Now, simply build the solution
  • Everything is back to normal
    • and VS does not complain any more with IDE1100

Attached are also:

  • The ‘rebuild’ binlog ("C:\Program Files\dotnet\sdk\6.0.402\MSBuild.dll" D:\repositories\tests\MultipleTfmsSourceOnlyRepro\MultipleTfmsSourceOnlyRepro.sln /t:Rebuild /v:diag /nologo /clp:NoSummary;Verbosity=minimal /bl): rebuild.binlog.zip
  • The ‘build’ binlog ("C:\Program Files\dotnet\sdk\6.0.402\MSBuild.dll" D:\repositories\tests\MultipleTfmsSourceOnlyRepro\MultipleTfmsSourceOnlyRepro.sln /t:Build /v:diag /nologo /clp:NoSummary;Verbosity=minimal /bl): build.binlog.zip

Expected Behavior

Rebuilding the project should just work

Actual Behavior

Failures: types not found

Analysis

I’ve dug a bit in the binlogs and here are my findings:

  • Because the dependency is a source-code package, a bunch of files are copied over to sub-directories of obj/Debug/<TFM>/NuGet/<Hash>/
  • However, it seems those files are not passed down as input source to the Csc task in the Rebuild case.
  • I’ve tracked down this to the RunProduceContentAssets target being skipped because _CleaningWithoutRebuilding is true
  • Up the call stack, I have this _SdkBeforeClean target:
      <Target Name="_SdkBeforeClean">
        <PropertyGroup Condition="'$(_CleaningWithoutRebuilding)' == ''">
          <_CleaningWithoutRebuilding>true</_CleaningWithoutRebuilding>
          <EmitAssetsLogMessages>false</EmitAssetsLogMessages>
        </PropertyGroup>
      </Target>
    
  • Because the property is empty or does not exist yet, it is assigned to true when obviously (I am rebuilding here), it should not.
  • I didn’t dig further down, but I suspect there’s something not being set correctly in the case we rebuild a multiple-TFMs project

In the meantime, I managed to work around this by explicitly adding <_CleaningWithoutRebuilding>false</_CleaningWithoutRebuilding> in my csproj. But… This isn’t the cleanest thing to do, and I have no Idea what other impacts it may have in other places…

Versions & Configurations

  • Visual Studio 2022 v17.3.6
  • dotnet --version: 6.0.402
  • MSBuild: 17.3.2+561848881

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rainersigwaldcommented, Oct 13, 2022

That analysis is fairly convincing to me! Moving to SDK, where RunProduceContentAssets lives.

0reactions
odaletcommented, Jul 5, 2023

Well, I did find a workaround, but it’s a hack and not robust to change at all: I’m relying on the private MSBuild property _CleaningWithoutRebuilding that can be removed or have its semantics change at any time. I’d rather MSBuild provided an official (ideally documented) way to support this scenario as I expect I’m not the only one who needs this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues with project references in some projects, but not ...
Hi, I'm sitting with a project that show these strange errors: "The type or namespace 'Xrm' does not exist in the namespace 'Microsoft'...
Read more >
This project references NuGet package(s) that are missing ...
This error usually occurs when you change the project directory name or path. edit the .proj file and replace the new directory name...
Read more >
Migrate from packages.config to PackageReference
The migrator analyzes the project's NuGet package references and attempts to categorize them into Top-level dependencies (NuGet packages that ...
Read more >
Please stop lying about .NET Standard 2.0 support!
In this post I have a bit of a rant about Microsoft's NuGet packages lying about supporting .NET Standard 2.0 when they kinda...
Read more >
Bring Your .NET Apps Forward with the .NET Upgrade ...
Some of the NuGet packages referenced by the project may not work with the new target. This upgrade step queries NuGet (and any...
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