Yellow Caution Icon/Glyph on Assembly Reference in Solution Explorer - visual-studio-2013

I am using NuGet to manage dependencies.
I created a fresh Git clone of my solution, and noticed assembly reference problems.
I have Enabled Package Restore and checked settings as suggested here, but I still have these yellow caution icons on various assembly references:
For example, I had previously added AutoMapper through NuGet, so why is it broken here, and why isn't it showing in my packages.config:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="bootstrap" version="3.0.0" targetFramework="net45" />
<package id="EntityFramework" version="6.1.1" targetFramework="net45" />
<package id="jQuery" version="1.10.2" targetFramework="net45" />
<package id="Modernizr" version="2.6.2" targetFramework="net45" />
</packages>

This usually means that the reference you have in your project refers to an assembly which cannot be found on disk. To correct this problem the most direct solution is to note which references exist, remove them, and then re-add them. Since you are using NuGet to manage dependencies your job is much easier, you simply need to:
Remove all NuGet Packages (using "Package Manager")
Remove any lingering broken assembly references throughout your solution
Re-Add NuGet Packages to all projects which need them (again using Package Manager)
Based on your description, it sounds as though some projects did not have NuGet packages added to them, and perhaps the assemblies were 'cross referenced' by a developer from the NuGet packages folder. This is a mistake. Instead the NuGet packages must be added to all projects which depend on the packages. (For example, you should never find yourself manually adding an assembly reference to AutoMapper, ever, because it is managed by NuGet for you.)
Sometimes there is a bug where these appear prior to a nuget fetch, and selecting the reference node in Solution Explorer will cause the overlay glyph (yellow caution symbol) to remove itself (meaning the reference was resolved post-load, usually by 'package restore'.)
This is most often caused by project authors creating incorrect/direct references to assemblies in non-standard locations, thus a package restore will not resolve the reference issues, and the references typically break after a package update.
HTH

I manually went and removed all references that had the yellow mark next to them and then added them back one by one. This way, they started showing up in packages.config too.
I think the reason they weren't showing in packages.config previously was because I turned on the [Restore nuget packages] option much later in development. Had I done this as soon as I started my porject, I believe they would have shown up in packages.config.
PS. I used the search on nuget's website to find out if the package was available on nuget, or if it was a framework assembly.

You need to reinstall all packages in a project using:
Update-Package -ProjectName MyProject -Reinstall

In Package Manager Console, select your Default Project
Then
Update-Package -reinstall

Related

How to deal with relative HintPath for Nuget dependency assemblies?

This issue describes in more detail and discusses the problem I was describing in a recent question - a project was in multiple solutions and the <HintPath> was to a local packages directory. So depending which solution was being built, it ran into dependency confusion issues.
Does anyone know of a good workaround? It can't be unusual to have the same project in multiple solutions and it seems crazy that Nuget, which is supposed to help avoid dependency hell, is relying on fragile local paths.
Does anyone know of a good workaround? It can't be unusual to have the
same project in multiple solutions and it seems crazy that Nuget,
which is supposed to help avoid dependency hell, is relying on fragile
local paths.
I think you could change the repositoryPath path in nuget.config file so that the hintpath will uses packages under the global nuget caches rather than copy the packages again under your solution folder. This relieves nuget package dependency.
Open C:\Users\xxx(current user name)\AppData\Roaming\NuGet\NuGet.Config and then add these in it:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value="%USERPROFILE%\.nuget\packages" />
</config>
</configuration>
Then restart VS and it will reference the packages directly from the global nuget caches.
Then run update-pacakges -reinstall under Tools-->Nuget Package Manager-->Package Manager Console to uses the new Hintpath.
Besides, use PackageReference nuget management format will avoid this behavior and you will not bother by the complex Hintpath problems. It is a new nuget package management format and much easier.
Right-click on the packages.config file--> migrate packages.config to PackageReference.
And Note that when you migrate into Build Server, and if you only build it by command line, you should run nuget restore xxx.sln to restore these packages. See this link.

How do you get NuGet package restore to work on locally deployed packages stored in VSIX targeting Visual Studio 2019?

I am aware there are multiple questions on this topic already, but they all seem outdated. To clarify, I am using the "new" VSIX manifest format, and trying to follow the official instructions here: https://learn.microsoft.com/en-us/nuget/visual-studio-extensibility/visual-studio-templates
I have one project template and a couple of item templates that go with it. They all depend on deploying a NuGet package that should come bundled locally with the VSIX. I have examined the resulting VSIX file and all the files seem to be in the right place:
The project template has the required XML for declaring which packages to install:
<WizardExtension>
<Assembly>NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</Assembly>
<FullClassName>NuGet.VisualStudio.TemplateWizard</FullClassName>
</WizardExtension>
<WizardData>
<packages repository="extension" repositoryId="VsixID.etc.etc">
<package id="Rx-Linq" version="2.2.5" />
</packages>
</WizardData>
The repositoryID matches the ID attribute in the .vsixmanifest file.
There is an individual Asset entry for each package, with the form:
<Asset Type="Rx-Linq.2.2.5.nupkg" d:Source="File" Path="Packages\Rx-Linq.2.2.5.nupkg" d:VsixSubPath="Packages" />
I have removed all packages.config and all the package references from the .csproj file installed by the VSIX (and even from the VSIX project itself just for good measure).
I have inspected the output VSIX and there is indeed a Packages folder in the VSIX containing all the .nupkg files. This folder is indeed unpacked and copied into the Visual Studio Extensions folder.
Despite all this, when I create a new project with the template, VS displays an error message saying: Failed to restore package from C:\users\<pathtoextensions>\Packages.
The thing is, the .nupkg files are actually present in the exact folder that the error message refers to.
I have been searching this for days and I can't seem to find any reference to best practices that actually work. It seems like these VSIX manifests are geared towards the legacy packages.config way of doing things, and there are discussions about how to extend them to use PackageReference instead.
Can anyone give any advice at all at how we are supposed to proceed going forward? Are packages not supposed to be deployed with the VSIX anymore? Are we supposed to just fill in the project with PackageReference entries and just let the user resolve them manually?
I feel like I am missing something fundamental here and any insight would be extremely valuable.
Update: I have also opened an issue on the NuGet github repository, as this is clearly a problem with the PackageRestore feature when restoring packages stored in a VSIX installer. Everything else mentioned in this question is working as intended and expected, except the package restore.
How do you actually include NuGet packages in Visual Studio Project
Templates VSIX targeting Visual Studio 2019?
Actually, there is no way to specify in a VS project template project that nuget packages can be used both using packages.config and PackageReference. Only two project templates of nuget management types can be created separately.
I have an easy way and since you have some issues with PackageReference format, you can try this funtion:
PackageReference
1) add these reference node in projecttemplate.csporj file:
<ItemGroup>
<PackageReference Include="Rx-Linq">
<Version>2.2.5</Version>
</PackageReference>
</ItemGroup>
2) When you create a project by this project template, please check these two options and VS will automatically read xxx.csproj and then recover the corresponding nuget package based on the information in it during build process.
Note: also make sure that the nuget url is checked and can be access under Package Source.
packages.config
In additon, for packages.config, you can just create a file named packages.config and then add your nuget info into it:
1)
2) add these into projecttemplate.csproj file:
<ItemGroup>
<Content Include="packages.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Reference Include="Rx-Linq, Version=2.2.5, Culture=neutral, PublicKeyToken=eb42632606e9261f, processorArchitecture=MSIL">
<HintPath>..\packages\Rx-Linq.2.2.5\lib\net472\xxxxxxx.dll</HintPath>
</Reference>
</ItemGroup>
Note: if this nuget package has dependencies, you should also add them(above steps) into packages.config and xxxx.csproj file. This funcution is a little more complicated than yours but it works. So, I recommend that you use PackageReference format.
More info you can refer to this similar issue.

Installing SQLite NuGet Package installs the package but the reference is not available. VS2019 Community

I"m writing a c# application using SQLite and I need the the SQLite Reference. Using NuGet I locate the package and the output window shows a successful install.
Looking at the packages config file in the solution explorer it shows the version installed.
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="SQLite" version="3.13.0" targetFramework="net472" />
</packages>
However under the project References in the Solution explorer SQLite is not there.
I have watched tutorials online where the same process is done on other machines and all is ok, all of the references pop up after NuGet finishes the installation.
I'm using VS2019 and from what I understand there were some changes on how NuGet operates, however I had VS2015 and VS2017 Community and had the same issues. I'm really at a standing point as I have no idea how to get the reference to show up so I can access it in my program.
SQLite has no Assembly reference so adding it there is not an option.
I have seen posts about a NuGet config file and Package Config File as well as the possibility of the package being installed outside of the Solution Folder but I don't know where. I have looked in the output location of the solution and none of the references are located in the debug folder anywhere.
I feel the Dll's are being installed outside of the solution folder but I don't know where and how to get Visual Studio to get them to the proper location or reference there existing location correctly.
Rebuild and Restore NuGet Packages provide no solution.
Any help would be greatly appreciated.
Installing SQLite NuGet Package installs the package but the reference
is not available. VS2019 Community
I assume you have installed sqlite version 3.13.0 nuget package.If so, it is the behavior of this nuget package. This package is very special in that it is a transactional SQL database engine that implements self-contained, serverless, zero-configuration.
In simple terms, it is a configuration function package that operates on related data when the project is running, rather than a package that provides a reference class library for the project.
Let me explain it in more detail:
This is the content of the nuget package sqlite version 3.13.0
Note that each folder provides specific functionality for the installation project.
And the function of the lib folder is to add its content(xxxx.dlls) as reference to a new project. In a word, Only the Dlls in lib folder can be recognized by nuget and added into Reference.
You can refer to this link for more detailed info about the function of the folders.
Second, there is a file called SQLite.props in the Build folder. The file will do some configuration to your project during build process.
In it, you can see these files:
<Content Include="$(MSBuildThisFileDirectory)..\..\runtimes\win7-x64\native\*">
<Link>x64\%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>False</Visible>
</Content>
</ItemGroup>
<ItemGroup Condition=" (Exists('packages.config') Or Exists('packages.$(MSBuildProjectName).config')) And '$(Platform)' == 'x86'">
<Content Include="$(MSBuildThisFileDirectory)..\..\runtimes\win7-x86\native\*">
<Link>%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>False</Visible>
</Content>
</ItemGroup>
<ItemGroup Condition=" (Exists('packages.config') Or Exists('packages.$(MSBuildProjectName).config')) And '$(Platform)' == 'x64'">
<Content Include="$(MSBuildThisFileDirectory)..\..\runtimes\win7-x64\native\*">
<Link>%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>False</Visible>
</Content>
So when you build your project, the SQLite.props file will be executed and they will provide services during build or at the runtime.
All of these indicates it is a package for specific execution functions rather than a nuget package for adding reference libraries to the project.
Suggestion
As a suggestion, you could install System.Data.SQLite in your project. And this nuget package provides the dlls which you want in Reference.
Hope it could help you.

NuGet newbie mayhem

I'm really new to NuGet and having all kinds of trouble with it. So the latest problem is that I generated a bunch of .nupkg files and put them in a shared folder on the network and then set NuGet up to look there for updates. So let's say in the folder I have:
Author.library.2.1.0.nupkg
Author.library.2.2.0.nupkg
Author.library.2.2.1.nupkg
I then found out that the target framework (.net) is different for some of my projects (under the same solution), so I generated new packages for each target:
Author.library.net40.2.1.0.nupkg
Author.library.net40.2.2.0.nupkg
Author.library.net40.2.2.1.nupkg
Author.library.net45.2.1.0.nupkg
Author.library.net45.2.2.0.nupkg
Author.library.net45.2.2.1.nupkg
Next I right-clicked on the solution and chose Manage NuGet Packages for Solution and then went to Online, pointed to the Installed Packages and was able to install each package to the applicable projects (.csproj files). But now when I open the NuGet Package Manager for the solution and click on Installed Packages, all I see is once instance of library. If I click on it, on the right I can see that it's pointing to the Author.library.net45 package, but I have no way of seeing the .net40 version of the library. So I can't add it to the .40 projects.
And lastly, what if I want some of the projects to point at an older version of a package. I know that I am suppose to be able to specify that in the packages.config file:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Author.Library" version="2.2.0" allowedVersions="
[2.0.0,2.3.0)" targetFramework="net45" />
</packages>
which should load anything above (and including) 2.0 through 2.3)
or
<package id="Author.Library" version="(,2.4.0" targetFramework="net45" />
which should load any version below 2.4.
So my main question is why can't I see the two versions of the package in the NuGet Package Manager? And also, how do I best limit the versions that will apply to a particular library.
It looks like you cannot see the different packages since they both have the same package id of Author.Library. This is based on what you have shown in your packages.config file.
Also I would not have separate NuGet packages just for assemblies that target different frameworks. Instead put them in a single NuGet package in their own lib directory (e.g. lib/net40 lib/net45). You can have multiple assemblies targeting different frameworks in the same NuGet package. NuGet will pick the best match when installing the NuGet package into the project. Also note that you can use a NuGet package that contains just .NET 4.0 assemblies with a .NET 4.5 project since the assembly is compatible.
The allowedVersions attribute in the packages.config file is the thing to use if you want to restrict the NuGet packages that a project can update to.

A dependency is not been resolved in InstallShield

A dependency is not been resolved in InstallShield.
My environment is VS 2010 and InstallShield Limited Edition.
I have a project that I’m trying to deploy using an InstallShield Limited Edition project.
The project to deploy has several references added via NuGet:
<packages>
<package id="Common.Logging" version="2.0.0" />
<package id="CsvHelper" version="1.4.0" />
<package id="log4net" version="1.2.10" />
<package id="NServiceBus" version="3.2.1" />
<package id="NServiceBus.Host" version="3.2.1" />
<package id="Quartz" version="2.0.1" />
</packages>
In the Setup project I added the primary output of the project (Step 2 Specify Application Data / Files). All dependencies are added (right click on the primary output -> dependencies from scan at build) except one. The Quartz.dll is missing from that list and from the files that are installed.
How can I fix this so all dependencies are resolved and added to the setup?
I don’t want to add the Quartz.dll manually because its location will change when a new version is available via NuGet.
BTW: Quartz.dll is a project reference.
IMO, dependency analysis tools ( and other profiling tools ) are good for gaining datapoints in making your own analysis of how an application works and what it's runtime / deployment needs are.
Attempting to encapsulate this process with an automagical "easy" button isn't a good strategy.
If you know your code nees "quartz.dll" then confirm that:
1) It's redistributable
2) It's doesn't already have a deployment solution ( For example, System.Windows.Forms gets deployed by the .NET FRamework Install )
3) Author it into your install manually if needed.
4) Turn off dependency scanning and repeat this process for all of your dependencies.
Is it more work then asking a piece of software to figure it out for you? Of course. Will it be more deterministic and reliable? Absolutely... and that's why we get paid the big bucks.

Resources