In a project/solution with lots of <PackageReference> dependencies, it can be difficult to find the source of a transitive dependency that's being pulled in. For example, no projects in my solution directly reference the package System.Data.SqlClient, but something is pulling it in transitively. Tracking that down "by hand" is virtually impossible in a large solution or project with lots of direct package references.
Is there any ready-made way (eg, a combination of .Net CLI commands) that, given a particular package, will find and reveal the source of the transitive reference? I use Rider, which has some awesome code navigation and "discovery"-type tools, but I can't find anything that helps with my goal.
Note: I also have VisualStudio if it has this capability built-in somewhere, I'd just need a pointer to where/how.
The capability is built into the latest Visual Studio 2019.
With Visual Studio 2019, Update 6, I can see something like the following:
Note that you can also discover packages by searching in the solution explorer.
Unfortunately it's not available in the NuGet Package Manager installed view yet.
Searching in VS did not work for me, at least not for a BCL package like System.Net.Http. What did work is looking in obj\project.assets.json, which lists all dependencies.
It's still a somewhat manual process of searching for each package up the tree. https://www.jerriepelser.com/blog/analyze-dotnet-project-dependencies-part-2/ describes the process well and provides code to automate it, but I have not tried the code.
Since I had the same problem and didn't find anything working (on SO, google and my installed VS2022 Ultimate), I've create a powershell and python script.
The script uses the nuget-deps-tree - npm package to get a dependency tree and then traverses this tree to find the nuget.
See: https://github.com/Kraego/NailDownNuget
Not an ideal solution in many cases but just to mention it. Switching to paket dependency manager could help as well, especially for bigger projects.
It has a command called paket why that quickly tells you for each package whether it's a top level, a direct or a transient dependency and additionally shows the dependency chain. See this blog post for some examples.
Related
I'm looking for a simple way to manage NuGet packages for the whole solution, to prevent conflicts between transitive NuGet packages when assembling all files into one installer.
When building a project all direct and indirect dependencies are analyzed and the NuGet resolution picks up the best matching version for each NuGet that is at least the same version as the lowest version and might also create binding redirects if necessary. (all good and fine)
The problem we have lately encountered was when we build the whole solution (200+ projects) at once, the resulting NuGet versions between all top level projects might not be identical. And due to the fact, that all resulting DLL and EXE files are installed into the same program files folder, the application can and will crash at runtime due to version mismatches when loading assemblies.
To better understand this issue I've created this sample repo.
The dependency graph looks like this:
Library1
Microsoft.IdentityModel.Tokens-5.2.1
Executable1
System.IdentityModel.Tokens.Jwt-5.3.0 (transitive reference: Microsoft.IdentityModel.Tokens-5.3.0)
Library1
results in: Microsoft.IdentityModel.Tokens-5.3.0
Executable2
Microsoft.IdentityModel.Tokens-5.2.1
results in: Microsoft.IdentityModel.Tokens-5.2.1
To demonstrate the problem, all projects compile to the same bin folder. When the whole solution is compiled and Executable2 is started, the application crashes, since the application expects Microsoft.IdentityModel.Tokens in version 5.2.1 but the actual version is 5.3.0.
For this constructed sample it is easy to find the problem and fix it with updating the Microsoft.IdentityModel.Tokens NuGet to the same version. (Manually, since Visual Studio Package Manager does not recognize this conflict in the consolidate tab).
But at a much greater scale it is far more complex to find those mismatches.
What we have found so far
Centrally managing NuGet package versions
Since it is not yet available, it cannot be used to solve the issue here.
Microsoft.Build.CentralPackageVersions
Unfortunately there is no IDE support for it, which makes managing NuGet packages very uncomfortable, which I would like to avoid if possible.
So my question is what is the best approach to avoid NuGet version conflicts between projects within the same solution?
We've experienced the same problem with some of our projects. We've been using Paket package manager since a couple of years and this has resolved that issue for us.
In short: you define on your solution level which packages you want to use in a file called 'paket.dependencies'. You can be very specific about versions, or let packet use the latest greatest. Then you can specify per project which NuGet package you want to use within that project in a 'paket.references' file. As the name implies, you reference to a package in the paket.dependencies file.
This will make sure, all references packages in your project will use the same package version. I hope this suits your needs as well.
My company uses the built in TeamCity NuGet repo to create custom NuGet packages that often depend on each other. When I, say, update a .cs page in a custom parent package I'd like for those changes to propagate to all of our packages that are dependent packages of the parent - I believe I can accomplish this using a NuGet installer to "update packages".
My fear is that while I know I can force this update upon all our packages, I want to find a way to exclude anything that isn't hosted on our company repo (which should also mean anything that is hosted on the NuGet.org repo), so anything that we are using from an outside source isn't lumped into this NuGet update.
Preferably, I'd like to know if there's a way to handle this in the our .nuspec for each of our packages (though it seems wildcards don't accomplish this). Any insight to my problem here?
Honestly, it sounds a bit like you're trying to re-create the project reference experience with NuGet packages. If it's at all reasonable to do so, perhaps your best option would be to have all projects in a single solution and use project references instead.
If you're able to migrate your projects to SDK style projects (used by .NET Core, but you can still target the .NET Framework), then you can use dotnet list package or the dotnet-outdated tool. dotnet list package --outdated has an option to specify a list of sources to use. Perhaps if you only specify your private feed it may only search that one. Otherwise the script you create to do all this will need to overwrite the nuget.config file to remove other sources (like nuget.org) when running the command to get your desired output. Then you parse the output and when it finds an update, it modifies the relevant file(s).
I'm very confused about Syncfusion Essential Studio. I want to use the XlsIo package in my app to extract some data from an Excel file and I don't understand how I should reference it.
The preferred way would be to use NuGet packages, for I which I suppose I could use the WPF nuget URL? Apparently no license key must be provided anymore to use it, which makes me wonder when I have to provide it – and why I installed a whopping 3GB tool if I could have just used this public NuGet package URL instead?
I did not install assemblies to the GAC as I plan to work on multiple devices with multiple projects and don't want to rely on assemblies being in the GAC, if possible.
I guess I can also just reference the assemblies in the essential studio install directory, but I'm not sure whether that's intended and how I'll deal with updates (cross-device issue aside).
So what I'm asking is basically: can I just use the NuGet packages, as that would be the easiest and most maintainable option in my opinion, and do I have to provide any license information at some point (e.g. deployment)?
Bonus question: what purpose exactly serves the essential studio, if I end up using NuGet packages? A mere sample viewer + number of optional tools?
Please find the response for your queries.
Query 1: Can I just use the NuGet packages, as that would be the easiest and most maintainable option in my opinion, and do I have to provide any license information at some point (e.g. deployment)?
Answer: Syncfusion is providing license on customer basis only. You no need to worry, if you have license for each developer. You can use any installation option such as Essential Studio installer, Platform installer, Link Installer or NuGet packages.
Query 2: What purpose exactly serves the essential studio, if I end up using NuGet packages? A mere sample viewer + number of optional tools?
Answer: Essential Studio build comprises of all platforms, samples & additional tools/utilities for configuration purpose. This will be helpful for evaluation purpose for the customer who doesn’t know about Syncfusion products.
Online samples are there to showcase our Syncfusion products. But sometimes user want to refer the code snippets and for window client platforms. So, Essential Studio build is necessary for these cases. Syncfusion have separate platform builds also if the customer needs to evaluate the products with specific platforms. To know more about Essential Studio setup features, click the below link.
https://help.syncfusion.com/common/essential-studio/overview
Thanks,
Mathi.
We are developing a WPF application at work which has various "common" dependencies (Unity, Prism, etc.).
It's all fine when adding new projects and then setting up the NuGet package dependency per project but when it comes to upgrades, it's really painful as it means we have to go through each and every project, delete the old references and then refetch the latest packages from NuGet.
Today for instance, I was tasked with upgrading Prism from 5.0 to 6.0 (which has breaking changes anyway) and this meant, in addition to fixing all the namespace conflicts, etc. that I had to go through every project, delete the old references, add the new dependecies and rinse and repeat.
My question is, is there a smarter way to deal with this problem or is this the standard approach?
Many thanks in advance,
Update:
I am mostly concerned with "major" upgrades which don't show up on the package manager. Version 5.0 -> 6.0 upgrade would be treated as a major upgrade and hence, would not have an automatic update applied to it in the NuGet package manager.
I don't expect NuGet to be able to do this automatically for me since such upgrades may (and often do) include breaking changes but I would like to know if there's a way to do the major upgrades less painfully than deleting the references from the projects and the packages.config for every project and then re-adding them using NuGet. For a relatively large project, this is very time consuming and I was wondering if anyone had a better way of managing such dependencies.
If you use VS2013 like you say, you can manage ALL your NuGet packages by right-clicking on your Solution and selecting 'Manage NuGet Packages For Solution'. This brings up a dialog where you can view all packages installed for all projects in the solution and all packages that have updates available. When you do upgrade the packages, VS takes care of all the reference changes required. If the package has breaking changes, then you're still on the hook for fixing those.
Disclaimer: I've never worked on a WPF project/solution but for Web/Forms apps, NuGet packages are handled this way.
I can understand your pain because i had the similar problem like you, but there is no easy way. but certainly you need to break the process differently of your daily development and your dependency update roll-out.
for the project i worked on, I use the common repository path that shared among the solutions that you work on, and you need to delete all the solutions folder references in order to get a clean state.
For each solution you work on you need to modify the property group that point to the common target repository (i'm using relative path)
Once all the things setup, you can actually perform an update with a script(I'm using python run-time script)
you can actually look at setting up common nuget-packages-folder for reference updates for detail, but it seems like what you looking at for the automate process
I had a similar problem when trying to upgrade multiple packages with alpha channel issues in Xamarin Studio, which also does not have the niceties of VS 2015 NuGet manager. I ended up writing a very simple PowerShell script that I run multiple times a day.
#
# This script updates local ibGib NuGet packages for mobileGib Android app solution.
# For convenience in copy+paste in manager console:
# ../UpdateLocalNugetPackages.ps1
Update-Package commonGib
Update-Package ibGib
Update-Package languageGib.Biz
Etc.
I believe you could tailor your NuGet commands to fit your needs.
Also, just in case you aren't aware of it, you should definitely read the NuGet command line reference. I may be mistaken, but it sounds like your scenario is doable with the Update command.
I have a library that I want to put ChromeDriver and IEDriver in so I don't have to reference those executables from each of my different testing frameworks. I have run into an issue, though, where my testing framework is looking for the drivers in the frameworks solution directory, when they exist within the library that I'm referencing. How do I solve this? Am I even going about it the right way?
Pull down the intended package through NuGet. Then Right click on on the test project>add existing>navigate to the package directory(ie chrome) and add as shown as follows.
See the screencast