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.

ResolvePackageAssets target is skipped for multiple target frameworks and Rebuild target in 17.2.0

See original GitHub issue

Issue Description

The ResolvePackageAssets target is skipped if three conditions are met:

  1. The feature “multiple target frameworks” is used in csproj;
  2. The Rebuild target is selected;
  3. The version of msbuild is 17.2.0 or newer.

That results in skipping code generation from source-only nuget packages with pp-files. That results in failed rebuilds.

The Build target runs the ResolvePackageAssets target in such conditions. Also, some older versions of the msbuild run the ResolvePackageAssets target is such conditions.

Steps to Reproduce

  1. Create an ClassLibrary1.csproj file in an empty folder with the following content:
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFrameworks>netstandard2.0</TargetFrameworks>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="StackTraceParser.Source" Version="1.3.1" />
  </ItemGroup>
</Project>
  1. Add an cs-file to the folder:
namespace ClassLibrary1
{
    public class GeneratedFileContainer
    {
        StackTraceParser x;
    }
}
  1. Run dotnet build /t:rebuild in the folder.

Expected Behavior

Build succeeded.

Actual Behavior

Build FAILED.

d:\work\CheckNullaRebuild\ClassLibrary1\GeneratedFileContainer.cs(5,9): error CS0246: The type or namespace name ‘StackTraceParser’ could not be found (are you missing a using directive or an assembly reference?)

Analysis

dotnet build /t:build finishes successfully. So there is an issue the Rebuilt target.

The type StackTraceParser is generated by the ResolvePackageAssets target from pp-file. See https://github.com/atifaziz/StackTraceParser/blob/master/StackTraceParser.csproj#L66

The reason why the ResolvePackageAssets target is skipped during the Rebuild target run is value of the _CleaningWithoutRebuilding parameter. In order for the target to be run, the parameter should not have a true value.

If the selected target is Build, the _CleaningWithoutRebuilding parameter is undefined. So the ResolvePackageAssets target is not skipped.

If the feature “multiple target frameworks” is not used in csproj and the selected target is Rebuild, the _CleaningWithoutRebuilding parameter is set to true by the _SdkBeforeClean target and then set to false by the_SdkBeforeRebuild target. So the ResolvePackageAssets target is not skipped.

If the feature “multiple target frameworks” is used in csproj and the selected target is Rebuild, the _CleaningWithoutRebuilding parameter is set to true by the _SdkBeforeClean target. But it is never set to false because the DispatchToInnerBuilds runs the Build target instead of the Rebuild target for each target framework. So the _CleaningWithoutRebuilding parameter value remains true and the ResolvePackageAssets target is not run.

Versions & Configurations

d:\work\CheckNullaRebuild\ClassLibrary1>dotnet msbuild --version
Microsoft (R) Build Engine version 17.2.0+41abc5629 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

17.2.0.20702

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Forgindcommented, May 26, 2022

Great repro, by the way, @alexandersorokin. Very helpful in pointing me to the underlying issue.

0reactions
benvillaloboscommented, Jul 28, 2022

MSBuild Team Triage: The targets for this issue don’t exist in the msbuild repo. The flags that control the build ordering seem to exist in the SDK repo: _SdkBeforeRebuild _SdkBeforeClean , etc. Moving to the sdk repo

Read more comments on GitHub >

github_iconTop Results From Across the Web

ResolvePackageAssets target is skipped for multiple ...
The feature "multiple target frameworks" is used in csproj ;; The Rebuild target is selected;; The version of msbuild is 17.2.0 or newer....
Read more >
Problem with multi target frameworks in asp web site project
My question is this: Why is asp.net web sites ignoring my targetFramework in web.config, when adding multi target frameworks, by project ...
Read more >
NETSDK1005 and NETSDK1047: Asset file is missing target
NET SDK issues error NETSDK1005 or NETSDK1047, the project's assets file is missing information on one of your target frameworks.
Read more >
Target Framework defined in Directory.Build.props causes ...
The "ResolvePackageAssets" task failed unexpectedly. NuGet.Frameworks.FrameworkException: Invalid framework identifier ''. at NuGet.Frameworks.
Read more >
Ignore Specific files for a target framework on C# | Medium
I wrote code for a repo that has two target frameworks. One is netstandard the other is net461 . I wanted to ignore...
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