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

ExcludeAssets="compile" has no effect on ProjectReference. #47403

Closed
teo-tsirpanis opened this issue Mar 10, 2025 · 3 comments
Closed

ExcludeAssets="compile" has no effect on ProjectReference. #47403

teo-tsirpanis opened this issue Mar 10, 2025 · 3 comments
Assignees
Labels
Area-NetSDK untriaged Request triage from a team member

Comments

@teo-tsirpanis
Copy link

Describe the bug

I have a project that depends on another project at runtime, but must not reference it at compile time. In order to achieve this, I tried adding an ExcludeAssets="compile" metadata to the ProjectReference, but it had no effect and the second project was visible to the compiler.

To Reproduce

Build this solution. It should fail with a compile error but it does not.

Exceptions (if any)

Further technical details

Using .NET SDK 9.0.200.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-NetSDK untriaged Request triage from a team member labels Mar 10, 2025
@baronfel
Copy link
Member

This isn't a bug so much as it is a design difference - ExcludeAssets is a Nuget-only concept, and it controls what categories of assets from the NuGet package are referenced by the referencing project.

ProjectReference has none of those controls. The closest to what you want is probably ReferenceOutputAssembly="false" from https://learn.microsoft.com/en-us/visualstudio/msbuild/common-msbuild-project-items?view=vs-2022#projectreference. It would be a good idea to have ProjectReference learn about asset categories, but that's a Large unit of work that is as of yet not done.

@Forgind
Copy link
Member

Forgind commented Mar 10, 2025

This isn't a bug so much as it is a design difference - ExcludeAssets is a Nuget-only concept, and it controls what categories of assets from the NuGet package are referenced by the referencing project.

ProjectReference has none of those controls. The closest to what you want is probably ReferenceOutputAssembly="false" from https://learn.microsoft.com/en-us/visualstudio/msbuild/common-msbuild-project-items?view=vs-2022#projectreference. It would be a good idea to have ProjectReference learn about asset categories, but that's a Large unit of work that is as of yet not done.

Is there an issue on NuGet to teach ProjectReference about ExcludeAssets? If not, perhaps we can make it.

@Forgind Forgind closed this as not planned Won't fix, can't repro, duplicate, stale Mar 10, 2025
@baronfel
Copy link
Member

It would be on MSBuild, not NuGet, because MSBuild owns the ProjectReference Protocol. I'm sure I've read an issue about this over there (or written one myself) but can't find it now for some reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-NetSDK untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

3 participants