Looking at the Web.config runtime section that opens with:
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
follows is a list of depen. Asse. where inside the bindingRedirect the 'newVersion="valu" ' does not always match to what Nuget reports.
Is this something to rectify or ignore?
thx
By NuGet reports I assuming you mean the version number that NuGet shows for a particular NuGet package.
First of all, the NuGet package version does not necessarily match the version of the assembly or assemblies in the package. So the binding redirect version may be different. A good example of this is log4net:
log4net NuGet package version: 2.0.3
log4net assembly version: 1.2.13
So if one of your NuGet packages is referencing an older version of log4net, whilst your project is referencing the latest version, then I would expect a binding redirect to be added which refers to log4net 1.2.13.
NuGet will add binding redirects when a package is installed. You can also manually get NuGet to update the binding redirects for a project by running the Add-BindingRedirect command in the Package Manager Console window.
Add-BindingRedirect MyProjectName
If on rebuilding your entire solution you get a warning that looks like:
MSB3247 - Found conflicts between different versions of the same dependent assembly
Then you should look into fixing the binding redirects or seeing if you can upgrade the older NuGet packages so the conflicts are resolved that way. Otherwise your application may fail to load a particular assembly.
Visual Studio 2013 supports automatic binding redirection for applications that .NET Framework 4.5.1 which is another thing to consider if this applies.
Related
What am I doing wrong here?
I have a DLL in .net Standard 2.0, and a console application, also in .net standard 2.0. The DLL is going to eventually be a custom nuget package for internal use by my dev team.
I installed System.Text.Json version 6.0.0 and I get the following runtime error:
"Could not load file or assembly 'System.Text.Json, Version=6.0.0.0".
I can see the nuget package in the location that Visual Studio 2022 is looking in.
Any thoughts on how I debug this?
I tried to explicitly install each of the dependencies, but that did not work.
***EDIT: I just realized that I no longer get that FileNotFound Exception if I explicitly copy that package's DLL into the console app's execution directory, but then I get a new FileNotFound exception for one of its dependencies. When I explicitly copy that DLL, I get another FileNotFound exception for the next dependency, and so on. I just assumed that the dependent nuget packages would get encapsulated in the dll that's using them. Copying each of the dependent DLL's is not really an acceptable solution.
After some investigation, I thought my issue might be related to:
Dependent DLLs of a NuGet package not copied to output folder
or related to:
MSBuild doesn't copy references (DLL files) if using project dependencies in solution
but that was not the case.
The output of my console app project was a DLL, even though it was clearly set to "Console Application". I just assumed that this was a new runtime method for VS2022, but that's not it. My console application Target was set to ".Net Standard 2.0", which is intended for DLL's. Once I set the Target to ".Net 6.0", everything worked as expected, and all the DLL's and packages were copied over correctly.
My DLL, which is being turned into a Nuget package, was properly set to ".net Standard 2.0".
I have a Visual Studio, C# solution with several projects. Some of those point to older versions of some packages. my local nuget repo has more current, stable versions. e.g.
What I want to do is update all those old 3.0.246-alpha references to the latest stable version, 3.1.0
What is the best way to do that?
Output window after clicking Install:
errors at top of screen:
This is what I want to fix. There is no version 3.0.246 of that module, so I want Nuget to overide it with latest stable version, 3.1
Due to the limitation, I post this as an answer, but may include some comments.(Sorry for that)
As I searched online(nuget.org), I found no packages called TBSM.*, perhaps they were created by yourself/your company… and just used(saved) locally?
From the error message, it reported that the NuGet package was not found on source XXXXX, so did you perform some operations to remove the old version of the NuGet packages? (Maybe also removed the NuGet cache files?)
I did some tests:
Since I don’t know the specific structures of your projects/NuGet Package, I just created two NuGet packages for test locally with same names(ID) and different versions, and then added the package source path to the settings, and installed the first NuGet package into one project, after that deleted this NuGet package and the cache files. Then tried to Update it, NuGet Package manager could still update it to the latest version successfully, even if I uncheck these options: Allow NuGet to download missing packages and Automatically check for missing packages during build in Visual Studio from VS > Tools > Options > NuGet Package Manager > General.
Of course, I may not remove all of the NuGet packages’ cache files, or the issue is cause by the specific NuGet packages’ structures(cause I used two NuGet packages, but yours maybe used the same one with something updated)…
What I suggest:
1). If it is possible, you can have a try Uninstall and then Install the relates version.(remember to make a backup before this)
2). Try to select this two options in VS(Tools > Options > NuGet Package Manager > General), “Allow NuGet to download missing packages” and “Automatically check for missing packages during build in Visual Studio”, and then click Clear All NuGet Cache(s) button. Make sure you have added the right path source from VS > Tools > Options > NuGet Package Manager > Package Sources and try to install/update the NuGet packages again.(Generally, clear cache will not cause errors, but please remember to make a backup before clearing cache)
If I understand Scott Hanselman's post here correctly then I should be able to reference a .net standard library from a framework 4.7.2 solution.
I want to use Nuget to install such a reference.
I am using Azure DevOps Artifacts for the Nuget package. When I push my .net standard solution I can see that the package does create and that the Nuget install command is
Install-Package SBD.Standard -version 2.0.0-CI-etc
However when I try this at the PM console for my framework 4.7.2 project I get
Could not install package 'SBD.Standard 2.0.0-etc'. You are trying to install this package into a project that targets
'.NETFramework,Version=v4.7.2', but the package does not contain any assembly references or content files that are compatible with that
framework
moreover I do not see SBD.Standard as an avialable package in the relevant feed from within VS2019 -> Manage nuget packages for solution.
I think I need packages.config
I was able to create a new 4.7.2 project and add the nuget package that used .net standard 2.0 (but not 2.1)
When I tried to add the nuget package I got a dialog asking me to select the Nuget package manager format
so I chose Packages.config and that worked.
I am not sure I have it right. I solved my problem but am not sure whether this was it after all. SInce PackageReference is more recent it should work.
Some additional explanations for this issue.
There is an issue for NuGet restore when you using new SDK-based project type or PackageReference in the .net framework:
https://github.com/NuGet/Home/issues/5461
https://github.com/dotnet/sdk/issues/1755
When we use packages.config projects or non-SDK based project type, NuGet do not check compatibility during install/restore.
So, to resolve this issue, we need make sure the referenced project is an old style csproj or use packages.config.
That the reason why the packages.config works for you.
Hope this helps.
My company is moving to using NuGet for our internal dependencies for desktop applications. This works fine for versioned imports, but in some cases (like during pre-Beta on a product) we'd like to grab the latest version of the dependency on our build servers and have the csproj files find it without issue.
We'd like to use automatic package restore, but that seems to be constrained by a specific version (as noted in this question). Using nuget restore followed by nuget update is also a possibility, but it doesn't seem to work solution-wide the way that restore does (and we have a couple dozen projects that have to share the same version of the same dependency).
Our best solution so far has been to add a hint path to the dependency binary in a non-versioned manner, i.e.,
<Reference Include="Dependency">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Dependency\lib\net40\Dependency.dll</HintPath>
</Reference>
And use the pre-build event to run
nuget.exe install Dependency -NoCache -ExcludeVersion
Is there a better way to do this? It would be nice to do it the most standard way possible so that we can get tooling support and new developers to the project can more easily know how to add their own dependencies via NuGet.
As of Nuget.exe v2.8.3, there isn't any way to do a solution-wide restore and update (at least when not all the projects in a given folder hierarchy are part of a solution). We ended up using the workflow described in How do I update a single nuget package in a project from the command line?.
I'm trying to install protobuf-net (2.0.0.602) in a portable class library, I just can't seem to get this to work. I get this error:
PM> install-package protobuf-net
'protobuf-net 2.0.0.602' already installed.
install-package : Could not install package 'protobuf-net 2.0.0.602'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.0,Profile=Profile4', but
the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
Inspecting the package it appears to target portable-sl4+wp71+windows8, however when i create a vinalla project targeting these frameworks I can't get it to work (profile4 is listed above, but I've tried a few different ones to see what sticks). I've just updated nuget in studio. Running 'nuget' from the package manager console shows the nuget version as 2.1.31022.9038.
If I browse to the protobuf-net.dll within the package (under lib\portable-sl4+wp71+windows8) it will allow me to reference it and all is good.
I can just manually add it, but am I missing something obvious.
Any help appreciated.
This appears to be just a slight tweak needed to the nuget config; I had specified portable-sl4+wp71+windows8, when actually I needed to specify portable-sl4+net4+wp7+windows8, to include regular .NET.
This is fixed in 2.0.0.611, which has been pushed to NuGet.