project-system icon indicating copy to clipboard operation
project-system copied to clipboard

PackageReference added under Target is not displayed in Dependency Tree

Open kabaogluemre opened this issue 1 year ago • 1 comments

Visual Studio Version

17.9

Summary

I have a Target which calculates PackageReferences to be added and it runs right before CollectPackageReferences target. Newly added packages are successfully restored and the project is successfully built on MSBuild and dotnet cli. But they are not displayed under Dependency Tree.

Here is the code;

<ItemGroup>
	<CustomProjectReference Include="..\ProjectName.MaterialBalance\ProjectName.MaterialBalance.csproj" PackageName="ProjectName.MaterialBalance" PackageVersion="$(AllVersions)" BuildConfigurations="Debug,Release,Prod,MaterialBalance"/>
	<CustomProjectReference Include="..\ProjectName.Pricing\ProjectName.Pricing.csproj" PackageName="ProjectName.Pricing" PackageVersion="$(AllVersions)" BuildConfigurations="Debug,Release,Prod,Pricing"/>
</ItemGroup>
<Target Name="SetPackageReferences" BeforeTargets="CollectPackageReferences">
	<ItemGroup>
		<PackageReference Include="@(CustomProjectReference->'%(PackageName)')" Version="%(CustomProjectReference.PackageVersion)" Condition="!$([System.String]::new('%(CustomProjectReference.BuildConfigurations)').Contains('$(Configuration)'))" />
	</ItemGroup>
</Target>

The idea is to pull referenced project as package if the active/current build configuration is not specified in BuildConfigurations metadata. Otherwise it will be added as ProjectReference. In this case, MaterialBalance and Pricing should be pulled as package.

As you can see from screenshot of ResolvePackageDependenciesDesignTime target, added package references are presenting; Capture

It presents on Package Manager screen as well; Capture2

But it is not displayed under Dependency Tree; Capture4

Expected Behavior

Added PackageReference under Target should be displayed on Packages Dependency Tree.

Actual Behavior

Added PackageReference under Target is not displayed on Packages Dependency Tree while the packages are restored and the project is built successfully.

I have provided a repo that the issue is reproduced with minimum steps.

kabaogluemre avatar Mar 11 '24 11:03 kabaogluemre

PackageReference items need to be available in project evaluation in order to display in the dependencies tree. You cannot synthesize them in targets, in the way you are doing, and have it work in VS.

What are you trying to achieve with your CustomProjectReference items? Can you use ProjectReference with some metadata instead?

drewnoakes avatar Mar 19 '24 06:03 drewnoakes

It's unclear what steps we could take here, so closing this. If you can provide more info we can revisit.

drewnoakes avatar Sep 20 '24 00:09 drewnoakes