Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PackageReference added under Target is not displayed in Dependency Tree #9415

Open
kabaogluemre opened this issue Mar 11, 2024 · 1 comment
Assignees
Labels
Feature-Dependency-Node "Dependencies" node in Solution Explorer that display project, binary & package references Triage-Approved Reviewed and prioritized

Comments

@kabaogluemre
Copy link

kabaogluemre commented Mar 11, 2024

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.

@adamint adamint self-assigned this Mar 14, 2024
@adamint adamint added Feature-Dependency-Node "Dependencies" node in Solution Explorer that display project, binary & package references Triage-Approved Reviewed and prioritized labels Mar 14, 2024
@drewnoakes
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature-Dependency-Node "Dependencies" node in Solution Explorer that display project, binary & package references Triage-Approved Reviewed and prioritized
Projects
None yet
Development

No branches or pull requests

3 participants