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

The MSBuild "pack" target is missing a property for explicit assembly references #6858

Open
MaxG117 opened this issue Apr 23, 2018 · 6 comments
Labels
Functionality:Pack Priority:3 Issues under consideration. With enough upvotes, will be reconsidered to be added to the backlog. Status:Excluded from icebox cleanup Status:Inactive Icebox issues not updated for a specific long time Style:PackageReference Type:Feature
Milestone

Comments

@MaxG117
Copy link

MaxG117 commented Apr 23, 2018

I can't figure out how the NuSpec <references> element maps to a csproj or MSBuild property. I believe it is because this mapping was omitted. The following articles:
https://docs.microsoft.com/en-us/nuget/reference/msbuild-targets#pack-target
https://docs.microsoft.com/en-us/dotnet/core/tools/csproj#nuget-metadata-properties
fail to mention this.

Please let me know how to specify an explicit assembly reference for the pack target in a csproj file, explain why this capability does not exist, or use this issue to implement the mapping. Thank you.

@jainaashish
Copy link
Contributor

@rohit21agrawal can you quick peek into this and respond accordingly?

@rohit21agrawal
Copy link
Contributor

currently this capability does not exist. We will add this to our feature backlog. Thanks for reporting!

@rohit21agrawal rohit21agrawal added the Priority:1 High priority issues that must be resolved in the current sprint. label Apr 25, 2018
@MaxG117
Copy link
Author

MaxG117 commented Apr 25, 2018

I have an additional question/request.

My nuget package consists of two assemblies: A.DLL and B.DLL, The consumer of my package (a.k.a. the target project) only needs to reference A.DLL, but A.DLL requires B.DLL at runtime. This is why I added an explicit assembly reference to A.DLL using the <references> NuSpec element. This worked as expected when targeting .NET Framework -- building the target project placed both A.DLL and B.DLL into the build output directory and the target project executes successfully.

However, I'm now targeting .NET Standard and I found out that dotnet publish does not copy B.DLL into the publish directory. The only way to get B.DLL into the publish directory was to remove the explicit assembly reference to A.DLL from the NuSpec file. I believe this is a dotnet publish bug, If B.DLL is copied to the build output directory, it should also be copied to the publish directory. Please let me know if I should open a separate issue.

@rohit21agrawal
Copy link
Contributor

rohit21agrawal commented Apr 26, 2018

@MaxG117 can you show us the nuspec you use to build your package, and the nuspec that's present inside the generated package, along with the contents of the obj folder (*.g.props, *.g.targets, project.assets.json) , after you run a restore?

@jainaashish jainaashish added Priority:2 Issues for the current backlog. Style:PackageReference and removed Priority:1 High priority issues that must be resolved in the current sprint. labels Jun 29, 2018
@mishra14 mishra14 added the WaitingForCustomer Applied when a NuGet triage person needs more info from the OP label Jun 29, 2018
@TechnikEmpire
Copy link

TechnikEmpire commented Jul 22, 2018

I've seen this as well. Microsoft.Data.Sqlite suffers from the same/similar problem if I'm understanding the notes here. If I reference that package in a .NET Standard library, then have a consumer reference my package (which references Microsoft.Data.Sqlite), the targets that unpack the Sqlite native assemblies into the bin folder on build will not get executed. I have to explicitly reference Microsoft.Data.Sqlite to get the package to work properly in this use cause (which I was argue is not only normal, but fundamental) and it's extremely annoying to pass this on to consumers. You're basically forced to hand out broken packages.

@MaxG117
Copy link
Author

MaxG117 commented Jan 9, 2019

@rohit21agrawal I finally had some time to look into this again, sorry for the delay.

In my previous comment I said that B.DLL was copied to the build output directory, but dotnet publish did not copy it to the publish directory. Either I was wrong or something changed since then, as B.DLL is not copied to the build output directory either. So at least there's consistency.

Here's the summary of my problem with creating a nuget package. I hope someone can guide me to a solution (I renamed A and B to make it easier):

  1. My project produces two class libraries: PublicLib.DLL, containing public API for my customers, and PrivateLib.DLL, containing code that is only used by PublicLib.DLL.
  2. PrivateLib.DLL is an internal implementation detail and may change at any time. I don't want my customers using it, because future changes will break their applications.
  3. My nuget package must contain both libraries, because PublicLib.DLL requires PrivateLib.DLL at runtime.
  4. If I place both DLLs into the lib\{tfm} directory, the customer's application automatically gets assembly references to both DLLs, permitting violations of # 2 above.

This problem is somewhat similar to #6614 -- my customer could start using the functionality in PrivateLib.DLL, but I cannot solve it the same way as #6614, because my PrivateLib.DLL is not and cannot be in a public nuget package.

I tried creating an explicit assembly reference to PublicLib.DLL in my .nuspec file. Unfortunately, this doesn't just prevent an automatic assembly reference to PrivateLib.DLL, it also completely ignores PrivateLib.DLL -- even if I get this DLL into the nuget lib\{tfm} directory, the customer's application doesn't copy it to either build output or publish directory. I need to be able to specify that PrivateLib.DLL is required by PublicLib.DLL at runtime only, so it appears in the "runtime" section of the customer application's .deps.json file and gets copied to the publish directory when the customer publishes.

Is this possible? Perhaps if not with nuget/nuspec/csproj settings, are there any other ways to accomplish this?

@nkolev92 nkolev92 removed the WaitingForCustomer Applied when a NuGet triage person needs more info from the OP label Jan 14, 2019
@ghost ghost added the Status:Inactive Icebox issues not updated for a specific long time label Sep 1, 2022
@nkolev92 nkolev92 added Priority:3 Issues under consideration. With enough upvotes, will be reconsidered to be added to the backlog. and removed Priority:2 Issues for the current backlog. labels Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Functionality:Pack Priority:3 Issues under consideration. With enough upvotes, will be reconsidered to be added to the backlog. Status:Excluded from icebox cleanup Status:Inactive Icebox issues not updated for a specific long time Style:PackageReference Type:Feature
Projects
None yet
Development

No branches or pull requests

8 participants