Reputation: 29227
(Visual Studio 2019, .Net framework, C# projects)
I checkout an old C# (.Net framework 4) solution (which was developed by someones I don't know) with a lot of projects from a repository. However, there are a lot of errors which are caused by Nuget packages not loaded correctly (there are small yellow triangles on these packages).
The following xml code is copied from the .csproj
files. All these Reference
s with HintPath
have the error. It seems the original developers save the dll files to a separated folder ..\..\Lib\
.
However, the folder doesn't exist. How to resolve the issue?
<ItemGroup>
<Reference Include="Castle.Core">
<HintPath>..\..\Lib\NHibernate\Fluent\Castle.Core.dll</HintPath>
</Reference>
<Reference Include="Castle.DynamicProxy2">
<HintPath>..\..\Lib\NHibernate\Fluent\Castle.DynamicProxy2.dll</HintPath>
</Reference>
<Reference Include="FluentNHibernate">
<HintPath>..\..\Lib\NHibernate\Fluent\FluentNHibernate.dll</HintPath>
</Reference>
<Reference Include="log4net">
<HintPath>..\..\Lib\Log4net\log4net.dll</HintPath>
</Reference>
<Reference Include="NHibernate">
<HintPath>..\..\Lib\NHibernate\Fluent\NHibernate.dll</HintPath>
</Reference>
<Reference Include="NHibernate.ByteCode.Castle">
<HintPath>..\..\Lib\NHibernate\Fluent\NHibernate.ByteCode.Castle.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
The output window shows the following message,
1>c:\program files (x86)\microsoft visual studio\2019\enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "NHibernate". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
1>c:\program files (x86)\microsoft visual studio\2019\enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "NHibernate.ByteCode.Castle". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
Upvotes: 0
Views: 1487
Reputation: 141
In my case I resolved that issue doing this:
Verifying that both checkboxes on Package Restore are checked and clicking Clear All NuGet Cache(s) button
Upvotes: 0
Reputation: 23858
However, the folder doesn't exist. How to resolve the issue?
I think you are moving your project to a new environment. In the previous environment, you changed the repositoryPath of the nuget.config
(restore the mechanism for nuget in the current VS environment) file to a folder called Lib. You can refer to this official document.
So it displays as
<HintPath>..\..\Lib\NHibernate\Fluent\NHibernate.ByteCode.Castle.dll</HintPath>
However, in your new environment, there are no changes to your current vs nuget configuration information using the default address, it like
<HintPath>..\..\packages\NHibernate\Fluent\NHibernate.ByteCode.Castle.dll</HintPath>
And the conflict is between the current default nuget mechanism and the previous nuget mechanism.
Suggestion
As a suggestion, please try my steps to troubleshoot your issue:
1) close VS Instance, delete theNuget.Config
under C:\Users\user\AppData\Roaming\NuGet
2) reopen your project-->Right-clcik on the Solution and choose Restore Nuget Packages
3) Tools
-->Nuget Package Manager
-->Package Manage Console
and then type
update-Package -reinstall
In addition, if these do not work, you should manually remove these packages.
Before it, please delete the Nuget.Config
first.
1) make a list to record the names of these nuget packages and then delete <Reference>
tag of these nuget packages in the xxxx.csproj
, packages.config
file.
2) clean the nuget cache and then install these packages on Manage NuGet Packages
(Right-click on the project-->Manage NuGet Packages
).
Hope it helps.
Upvotes: 0
Reputation: 15082
I am quite confident that the solution does not use NuGet. The original developer almost certainly checked in binaries into source control, in that lib
directory.
NuGet does add <HintPath>
elements into the project when the project uses packages.config
, which was the only option available before Visual Studio 2017. However, the default directory is $(relative path to solution directory)\packages
, not $(..)\lib
, although this can be changed with a nuget.config
file.
But, NuGet has a specific folder structure within the packages
folder, which will always be $(PackageId).$(PackageVersion)
. Since the subfolders under lib
just say NHibernate
and log4net
without a package version, it's not possible for this to have originally come from NuGet. edit: in addition, assemblies within a package are always in a lib\
folder, so if the assembly came from NuGet, the hint path should be ..\packages\log4net.1.2.3\lib\<tfm>\log4net.dll
. Technically the <tfm>
part is optional for packages that only want to support packages.config
, but the vast majority of packages do use it. I'd be shocked if a package as popular as log4net or nhibernate didn't use the <tfm>
folders. So, there's basically no chance that this was ever installed through NuGet.
If you wish to start using NuGet, you can remove the references to those assemblies (either in VS, or hand edit the csproj), and then use NuGet's Package Manager UI to install the packages. It'll add the relevant references back, this time with a hint path to a NuGet folder that will exist.
Upvotes: 2
Reputation: 253
That's ok to save libs to a separate folder e.g. out of repository. It seems your app can't to get this dll-s. First check if dll-s exist in these folders. The second - try to repair/re-download libs from nuget. If it wont work, provide more info about warnings
Upvotes: 0