ResolvePackageAssets target is skipped for multiple target frameworks and Rebuild target in 17.2.0
See original GitHub issueIssue Description
The ResolvePackageAssets
target is skipped if three conditions are met:
- The feature “multiple target frameworks” is used in
csproj
; - The
Rebuild
target is selected; - 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
- 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>
- Add an
cs
-file to the folder:
namespace ClassLibrary1
{
public class GeneratedFileContainer
{
StackTraceParser x;
}
}
- 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:
- Created a year ago
- Reactions:2
- Comments:5 (4 by maintainers)
Top GitHub Comments
Great repro, by the way, @alexandersorokin. Very helpful in pointing me to the underlying issue.
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