-
Notifications
You must be signed in to change notification settings - Fork 253
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
Should dependent assemblies less than or equal to projet's target be added when package is installed? #7740
Comments
Thank you for your feedback! |
What info do you need? |
Hi, if what you want is to add OtherDll.dll in MyApp.exe project(targeting net472), you may add "-IncludeReferencedProjects" at the end of original nuget pack command. You don't have to edit the .nuspec file. |
Hi, OtherDll is included in the nuget package as described in the post above. It is not added as a reference to MyApp.exe which of course causes it to break. Is that the expected behavior? |
Thank you for your reply! |
@heng-liu I'm sorry you closed this ticket as I don't think the issue is resolved. Please understand that my question is not related to "-IncludeReferencedProjects". In my case OtherDll.dll is not a project - it is a third party binary that is reference by my project. What I understand your reply to mean is that: After I specify explicitly that dependencies that are to be included in my nuget:
and after I confirm that the dependencies are in fact added to my .nupkg:
Than, at the time I install my nuget on the consuming application, the files I have explicitly specified as dependencies may be ignored by the installer for no reason? I do not understand under what circumstances nuget SHOULD ignore a dependency and knowingly cause a nuget installation to fail. Why would I include a .dll in my .nupkg if I did not intended for that .dll to be referenced as part of the installation? In this specific case being discussed in this ticket where the .dll is actually included in the .nupkg, what is the reason that that the installer failed to add it to the consuming application? Thank you! |
Thank you for your feedback! |
@heng-liu Hi heng-lu, please reopen this ticket because I do not think this topic is resolved. Perhaps I'm not doing a good job of stating my questions or perhaps I don't understand your reply. Here again are my questions: Question 1: Question 2: I don't understand your reply about editing the nuspec file - did you intend that as a reply to a different post? |
Just stumbled across this issue. NuGet first selects a TFM (target framework moniker) for asset selection, before selecting assets. So, which dlls, or how many dlls exist in each Therefore in the scenario where you bundle a dependent assembly in your package with your assembly, it needs to be in the same TFM directory as your assembly, even if it was compiled against a lower TFM. An alternative to that is to put the other dll in its own package and make it a dependency of your package. I consider this good practice anyway since other packages may want to use that other dll and if it's always used a package there are fewer problems than if multiple packages have the same assembly name, causing the build system to choose which one to use and potentially have problems. I hope this helps. |
@leaderanalytics To answer your questions:
NuGet is a package manager, not an assembly manager. NuGet don't examine assemblies and what assembly references each assembly has and ensure that they will work at compile or runtime. That's the package author's responsibility. NuGet does check NuGet dependencies, which are different to assembly "dependencies". In the original question there was no nuget dependency, therefore the idea of ignoring a dependency is out of context.
The package in the original question is instructing NuGet to inform MSBuild that
The package says "I have this set of assets for net47 projects, and these other set of assets for net472 projects". The idea is that if you have a library that can provide improved or additional functionality in newer versions of the .NET Framework, then NuGet selects those assets. But if a project using the package targets an older .NET Framework, NuGet selects the assets that allows the project to use the package's reduced functionality. Assuming the user-scenario for this question is that you want to package an assembly that has a dependency on another assembly, there are two options:
If my two comments on this issue don't help, please explain the problem you are trying to solve. We might be able to find a solution more quickly than discussing specific technical implementation details. If my comments helped you understand how NuGet works, and you still find the documentation confusing, I would appreciate feedback on what is confusing. If you have suggestions how it could be improved, that would be better. |
@zivkan Please reopen until I respond. |
This is not my intent at all! My package contains exactly one set of dependencies and those dependencies should be installed for all versions of the framework greater than or equal to .net 4.7. The preceding is my intent - If my package is incorrect please tell me how to fix it. I am not asking nuget to manage or examine anything. I am giving it a single, explicit list of files to install when the package is installed.
Again - this is NOT my intent. I have only one set of dependencies. My intent is to tell Nuget: "Create a package that will work with .net 4.7 or above. When the user installs the package ADD A REFERENCE TO THESE TWO ASSEMBLIES. As is demonstrated with the attached projects Nuget is only adding a reference to ONE of the assemblies. Why is that happening? Please see attached projects which reproduce the behavior described in this ticket. |
If you open So, you need to go to project properties and change your project to target ".NET Framework, v4.7" instead. Since you're already packing In short, when you want to package multiple dlls in a single package and have all of them referenced by a project using the package, all the dlls must exist in the same |
I didn't look very carefully at Now, the main problem with this is as I mentioned in my previous comment, your dll was compiled against net472, so net47 and net471 projects using your project should fail to compile and/or fail to run because your assembly, despite being in the However, net47 and net471 projects should correctly reference both dlls when referencing your package. Since the project assembly was automatically added to When you want projects using your package to reference all the dlls in the appropriate |
How does nuspec know to create net47 and net472 folders? In my nuspec I am simply telling it to create a package that targets net47.
If that is the case nuget should generate an error when the package is created. I am not choosing what .dlls wind up in which directories. Nuget is doing that. It is interesting to note that MyDll.dll winds up in the net47 directory even though MyDll.dll is invalid for 4.7. Rather than create an invalid set of files to install I would expect nuget to not create a net47 directory at all.
I don't understand this based on your previous comments. If MyDll.dll targets 4.7.2 it should NOT be added as reference for a net47/net471 project. Is that correct?
In the net472 directory I think if nuget is smart enough to determine the minimum framework version my pkg can target it should be smart enough to create folders for those frameworks only. In this specific example net47 should not be created and net472 should be created correctly. |
The project is net472, hence the project dll in the In order to minimise further miscommunications (my personality is that I'm a very detailed oriented person, but this can lead to information overload, particularly when I'm not clear about the context of the information I'm giving), here are two ways you can solve the problem:
The key is that the file target in the nuspec needs to match the project's target framework version exactly. Either of these solutions should result in your package working as you intend. |
I forgot to mention that we're currently considering adding some additional pack validation, so thanks to your feedback, I've added checking |
Thanks for that answer. That does fix the problem in this case. To close out this issue I think you should answer my original question directly. Key words are "if a match is not found". Adding a compatibility check is good (I suppose) but will it solve the entire problem? As you said:
So if you do a compatibility check nuget will see that MyDll.dll is not compatible with net47 so a package will not be create for it. That will solve one problem. The second issue is not copying other required dlls:
The above is the issue I am asking about. Will the above issue be fixed with a compatibility check? Thanks again for your help. You have answered many questions - except the ones I keep asking! :) |
PM> $host
Name : Package Manager Host
Version : 4.9.3.5777
InstanceId : d190a8ae-335c-4f75-9f14-09ac364bee12
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : en-US
CurrentUICulture : en-US
NuGet Version: 4.9.2.5706
usage: NuGet [args] [options]
Type 'NuGet help ' for help on a specific command.
This document says:
Question: If a match is not found will NuGet also copy dependent assemblies for less-than-or-equal versions of project's target framework?
Example Project configuration:
MyApp.exe - net472
depends on
MyDll.dll - net472
depends on
OtherDll.dll - net47 or greater
nuspec:
Build command:
NuGet.exe pack MyDll.csproj -Outputdirectory bin\release -properties Configuration=Release
This is what is created in the .nupkg:
When I add the .nupkg via Visual Studio to MyApp.exe project only MyDll.dll is added - OtherDll.dll is not added.
My question stated differently is: Should nuget install BOTH .dll files? Each one has an assembly that is less than or equal to the project's target framework.
See also
#7316
The text was updated successfully, but these errors were encountered: