How install packages in Net 5.0 runtime of local (or remote) computer, so that will be available for all projects I create, without add explicitly to each project with nuget ?
Ideally each package installed in this way should be reachable just declaring it's namespace.
Example:
the package is Microsoft.Extensions.Configuration.Json
install this way the package
create a console .net application, and I do not add nuget package
use package classes just declaring "using Microsoft.Extensions.Configuration"
Hope there is a way to do this
This can't be done. It would quite quickly become unusable when different projects needs different versions of these packages (like when you start a new .Net 6 project in the future and all old projects want the .Net 5 assemblies).
What you could do however is to create your own meta package with your default list of packages, that way you would only need to install one package to your new projects which would then include all the ones you want.
How to create meta package (package of all packages) like Microsoft.AspNetCore.All in nuget?
Related
We have a solution with 7 to 8 different projects including class libraries and mvc apps. We are using .net 4.6.2 and netstandard 2.0.
We are trying to convert class libraries to nuget packages and instead of referencing the projects directly in our web apps, use nuget packages. We have created the packages and added them in packages.config and the packages are getting installed perfectly fine.
Now, when I remove previous reference and add a new reference and point it to the nuget package, my web apps doesn't work and give assembly not found error.
I think I'm not adding the reference correctly , and need help on this.
If you are using NuGet packages now then you would install the package into each project which needs the assemblies and NuGet will add the references for you. You don't add the references by adding them from the packages directory.
E.g. Install-Package MyPackage MyProject
Installing Packages from Nuget are one of the most efficient ways for developing C# applications. It's a huge time saver.
However, can a Package I install from Nuget also contain a package(s) installed within it? If so how can I view sub-packages within a Package?
Short answer is yes, you can use packages inside of other packages. They are called dependencies, and the other packages will get installed along side the first package. Here's the Microsoft Documentation on nuget package dependency.
EDIT:
Here's how to view/manage these in visual studio. You can view all other packages in the dependencies section shown below. This package depends on System.ValueTuple with a version of 4.5.0 or greater.
In order to use Serilog I had to install multiple Nuget packages to a project. My WPF app has multiple dlls. Should I install all required Nuget packages of serilog to all projects in my solution? Also in general if my solution that has multiple projects, having common Nuget project dependencies, whether Should I install it in all projects or there is any other procedure of implementation.
My app is .Net Framework 4.6 app.
Given you're targeting .NET Framework 4.6, I'm assuming you intend to use Serilog's ILogger to write logs.
In that case, you need to install the package Serilog in all projects that will write to the log. This package is where ILogger is implemented, which your projects will need.
All other packages (sinks, enrichers, etc.) need only to be installed on the project that actually configures the log (in your case, the WPF project).
One of the nuget packages that I am using have a minor problem that I have solved with a pull request. I would however want to include the fix in the build of my own application and I do not want to wait until the fix is released as part of a new version of the nuget package. Which procedure should I now follow to achieve this?
Can I keep my package reference and override the assembly provided by nuget with my own custom version of the assembly? I have tried to just copy the custom assembly to the corresponding location in nuget packages folder but it does not work.
Do I have to remove the nuget package reference and keep the custom library in my version control until the fix gets released?
Especiall when you're working with a team or using a build server, you'll want to not do an in-place replace of the same package version.
You can either add a direct reference to the custom-built assembly (and be sure to version it or to include the source in source control so your colleagues or the build server can compile it themselves), or create a new NuGet package with a higher version number and upgrade to that version.
If you don't have a private NuGet server, you can simply add a (shared) directory as package source for your custom built package, as explained in How to install a Nuget Package .nupkg file locally?.
It may work with the same package version, but then you'll have to remove and reinstall it, and make sure it isn't cached anywhere so the old package won't simply be added again. So you better just change the version number.
I have a C# solution targeted for framework 4.5.1 but the server I need to install this on uses 4.0 so I need to roll this back.
The developer has used NuGet (which I'm not really familiar with) for dependency management. I've seen there is a way to request specific versions of each library so I'm hoping there is a feature which allows me to restrict these to a specific .NET version.
How can I get NuGet to install the latest dependencies for .NET version 4, or is this not a feature it supports?
If you change the target framework of the project then Visual Studio will check the compatibility of the NuGet packages and tell you which ones are compatible or not and whether they need to be reinstalled. You can then reinstall them from the Package Manager console using the -reinstall option.
Update-Package –reinstall <packageName>
NuGet does not directly support a way to restrict or install NuGet packages for a specific .NET version. The NuGet package will either support that .NET version or not. You can restrict a project to a specific version of the NuGet package by using the allowedVersions attribute in the packages.config file but that is independent of the .NET version the NuGet package supports.
Nuget should install packages that are available for the targeted version of .NET
Check your packages folder, or check the documentation of each dependency for support of .NET 4.0
In some cases you may just be able to re-target your application without uninstalling any Nuget packages.
To install a specific version of a Nuget package, you can use the "-Version" flag
Example -
Install-Package AvalonDock -Version 2.0.1320
References -
http://docs.nuget.org/Consume/Package-Manager-Console
http://dutton.me.uk/2013/07/24/how-to-install-a-specific-version-of-a-package-with-nuget/