Visual Studio References versus Dependencies, Assemblies, and Packages - c#

In Visual Studio 2019, in a .NET Framework (not .NET Core) console application project, how do I add NuGet packages so that they show up in the "Packages" section of a "Dependencies" instead of just as "References" with other assemblies? That is, I'd like to get this (which is from a Microsoft example app)...
... instead of this (which is what I have in my app after adding Newtonsoft.Json and MSAL using the NuGet package manager tool) ...
Notice, in my app, there is a "References" section but no "Dependencies" section, and the packages are mashed in with the other references. The only thing I could find to try was to right-click on References then select the "Migrate packages.config to PackagesReference", which yielded this ...
(StackOverflow bug? When I try to add a third image, it shows some totally random image in a different language. What the picture shows, though I can't get it to add, is the same "References" section except that the Json and MSAL references have a different icon.)
... which is closer (the packages are now "references", I guess) but there is still no Dependencies section with partitioned Assemblies and Packages subsections.
Assuming the MS example is doing it "right" and that I am doing it "wrong", how do I get from where I am to where they are?

Ah! I think I found the answer at Visual Studio 2017 References vs Dependencies. It appears I need to use a different project type if I want the newer style project file.

Related

Visual studio references show some libraries not loaded

I have been working maven projects since 2 two years.First of all, I import maven projects to eclipse then
thanks to my pom.xml some dependencies is installed and I see these dependencies on my maven dependencies folder on eclipe project explorer.It connected to my .M2 folder.
Right now , I import a .Net framework project (which is written with C#) in my visual studio program.The solution explorer (references section) show many dependencies(they gives error).Then I found these libraries then I created a folder which is called nugetPackages and I connected my nuget packages manager to that folder(tools/options/nuget package manager/package sources).I reopen my project and libraries on references section does not give any error.My question is where does that libraries names come from ? There are any file like that pom.xml.
I hope I can explain my situation.
Are the libraries (DLLs) that you want to reference in your project NuGet packages or just some framework libraries? If they are Nuget packages they should be described in packages.config file http://prntscr.com/1140xn0 for the classic .NET application (.net framework 4.5 for example) In a .Net Core applications the Nuget packages that are required are defined in the file .csproj file http://prntscr.com/11412iq. In both cases, you can download all required NuGet packages by right clicking on the .sln file and selecting Restore Nuget Packages http://prntscr.com/1140zsk This will automatically create the nugget folder and download all required Nuget packages. If you have manually added dlls you need to navigate to them and select them by right-clicking References - Add reference http://prntscr.com/114142x

Visual Studio 2015 multiple solutions strategy (TFS)

What is the best strategy when having multiple solutions where some projects in a solution make a reference to an assembly of another project in another solution.
- Solution 1
-- Proj1
-- Proj2
- Solution 2
- OtherProj 1
- Solution 3
- FooProj1
- FooProj2
For example if OtherProj, FooProj1 and FooProj2 use Proj1 or Proj2 assemblies.
Now I have to build for example Proj1 and manually copy/paste that assembly to a solution folder in Solution 2 and Solution 3.
I can't reference directly, because that would use a local path and if I check in via source control (TFS) my colleague receives my local path (that is why we copy/paste in the solution folder so that the path is always relative).
What we were thinking of is adding a post build event and copy the assemblies to a shared folder on a server \myserver\assemblies\relaase\Proj1.dll and then reference to these files in our solution/project.
Would that be a good strategy, because it would work also with source control, or are there any other strategies to work?
(Something exists like Shared Projects in Visual Studio, but I think that is more for a single solution but multiple platforms instead of sharing around)
You should publish the output of each project/solution as a Nuget Package and take dependencies on those packages.
It is very easy to have the output of your Project or Solution packaged as a Nuget Package with most of the capabilities built in. A NuGet Repository can be a Network Share or you can use a hosted service (MyGet, VSTS/TFS, others).
The VS extension, NuGet Reference Switcher is one solution for this situation. From it's description:
NuGet Reference Switcher is a Visual Studio extension which automatically switches NuGet assembly references to project references and vice-versa. This is useful when developing applications which reference own NuGet packages.
Here is the VS 2015 version.
Here is the VS 2017 version.

How to view the source code from downloaded packages in Visual Studio

I am working on TOTP and have downloaded a package in Visual Studio 2013 by:
Tools --> Library Package Manager --> Manage Nuget Package Packages
However there seems to be no documentation for this downloaded package. So is there anyway I can view all the code and implementation in this package in order for me to know how to use the classes in the package?
After including the package:
using Albireo.Otp;
using Albireo.Base32;
I can go to the definition from the classes within the package by
right clicking the class --> Go To Definition.
But is there a way to view all the files and implementations from this downloaded package?
For that specific library, the source is at https://github.com/kappa7194/otp
To answer your question, You can either use Assembly Explorer or Object Browser in VS.
Go to Solution Explorer -> Open references --> Right click on the referenced library
Im using VS 2016 not sure if VS 2013 has that feature.

PetaPoco core .cs file not visible in ASP.NET 5 Class Library package

I am building a new project in ASP.NET 5.
In my solution I have added a new Class Library (Package) project.
I right click on this project and choose for Manage Nuget packages to install PetaPoco.Core.
When I install everything seems fine except that the PetaPoco.cs file is not in my project.
In my references I se the PetaPoco version 5.1.171 installed.
Is this something different then a normal class library and do I need to use something else in order to use the installed PetaPoco class or is it a problem during the installation?
I have removed and reinstalled this but still the same.
Someone that can help me out?
/Michael
It looks like the PetaPoco.Core package isn't setup to be used in portable class libraries (PCLs).
Including content files in PCLs like the Models folder that PetaPoco.Core creates requires a different NuGet setup than a regular project. Documentation on this can be found on NuGet. I downloaded their package directly and can confirm that it is not setup in the way the linked resource describes.
It may be that the project requires features that are not available yet cross-platform, or they simply haven't had time to make changes to support PCLs, or some other reason that I am not aware of.
NuGet packages are usually installed as DLLs in the bin folder of your project, with the needed references also added automatically to the project. They usually don't include source files. You may find sources - if available - on the package/project website.
Visual Studio IntelliSense will pick up the DLLs and show what it can about the classes and methods inside, including comments and method signatures.
See here for a tutorial, including how to build your own NuGet packages.
EDIT: PetaPoco is the exception that does add a .cs file... see comment below.

All projects referencing sub-project must install NuGet package Microsoft.Bcl.Build (C#/Windows Phone 7)?

I'm having a particularly difficult refactoring session involving a C# solution with multiple projects in Visual Studio 2012. I needed to pull out a bunch of code into their own assemblies so that code could be shared across several projects, all in the same solution. However, no matter what I try, I get warnings for the projects that reference the new shared projects that "All projects referencing {shared project name} must install nuget package Microsoft.Bcl.Build".
I have been over the dependent projects and the shared projects with a fine-tooth comb, verifying in detail that they all use the same version and exact same DLL for the Microsoft.Bcl version 1.0.1.19 and Microsoft.Bcl.Async version 1.0.16 packages:
System.Runtime
System.Threading.Tasks
Microsoft.Threading.Task
Microsoft.Threading.Tasks.Extensions
Microsoft.Threading.Tasks.Extensions.Phone
The DLL paths are all resolved and identical. The XAP file does build but I still get that warning telling me that Microsoft.Bcl.Build is not referenced in the dependent projects, despite the fact that I can see that it is.
If I try instead to uninstall and then reinstall those two packages using NuGet for each project involved, I get references with empty paths and the warning icon for the 5 DLL references involved. For some reason NuGet adds the references but can't find the DLLs. Also, if I do this, I find myself with the problem frequently of having projects where I get the "Can't add reference" error when trying to add a reference. Then I have close and re-open the solution, and that leads to a "project failed to load" error. So I have to edit the project file manually, remove the faulty package import statements, and reload the project.
How can I fix this problem and what is the general technique for avoiding this headache in the future? Letting NuGet manage missing packages didn't help at al.
In case anyone else comes across this and #Swell's solution made you go "wtf":
I recently went through an older MVC project and updated it (updated razor, asp, http, etc. nuget packages). The project, independent of itself, built fine, but when i went to publish it failed with the OP's errors.
It turns out it's because I didn't update the *.Tests project associated with it (should have figured, though not sure why Tests is that closely tied to the project). So, to fix:
Right-click the Solution and manage nuget packages.
Go through all the packages that were updated in the web project and apply them to the other projects as well (each "Update" will display a tree with the applicable projects, I was fine just OKAY-clicking through).
Rebuild.
You should now be good and it shouldn't bark at you. Hope that helps others.
I just came throught the same issue and a bug is opened here: http://nuget.codeplex.com/workitem/3268
What I've done is the following, I added to the solution level the package Microsoft.Bcl.Build
In my dev env if you don't have the package loaded, just right click the solution and select manage nuget packages, you see a yellow bar with a restore button, just click it and you will be fine.
In my build script before compiling the project I run this command:
.\myproject\.nuget\NuGet.exe install .\myproject\.nuget\packages.config -OutputDirectory .\myproject\packages
This will restore solution level packages and you will be fine.
This should be fixed by the end of this summer in version 2.7 according to the issue report

Categories