Change which NuGet packages are installed by default - visual-studio

When creating a new project in Visual Studio, say an MVC web app, several NuGet packages are installed by default (Antlr, Modernizr, WebGrease, etc.).
I would like to change the NuGet packages which are installed by default. For example, I may want to remove Antlr from the default list and add EntityFramework.
Is this possible? If so, how can I achieve this?

Related

Nuget Packages not installing anything in .net core app

I am trying to install knockoutjs and typescript in a .net core app via Nuget.
It shows in Packages but doesn't install anything in a scripts folder as has previously in asp.net.
What am I missing?
TL;DR ASP.NET Core no longer works in that way (packages copying javascript/css content into your project). You need to adapt your workflow.
.NET Core projects only work in SDK-style projects, and SDK style projects only use NuGet's PackageReference, not packages.config. The docs on migrating from packages.config to PackageReference list one package compatibility issue as not supporting the content folder, which is how in packages.config those assets are copied into your project on package install.
I can't find a doc listing recommendations for ASP.NET Core apps, but my understanding is you can either use LibMan, or use NPM, which is in line with basically the rest of the web development industry outside of .NET has been doing. If you use the new project templates to create a new ASP.NET Core Angular or ASP.NET Core React app, you'll see they create a ClientApp folder that uses npm and all the official react/angular CLI tools. The MVC template has copies of jQuery and bootstrap, without an obvious way how to update them.
might be some unsync, remove the packages folder from the solution and restore the packages again. It will fix the issue. Also check the output window, that will show the list of errors.
It shows in Packages but doesn't install anything in a scripts folder
as has previously in asp.net.
First, I agree with zivkan. It is a feature of PackageReference Nuget Management format.
VS has two format to manage nuget packages: Packages.config and PackageReference.
Since new sdk format projects(Net Core and Net Standard) only use PackageReference to manage nuget packages,it will be very different from the effect reflected by the packages.config package management format.
When you use Content files from the nuget packages with PackageReference, it will lose files from the Scripts folder.
Just as this document said, it has such compatibility issues.
Actually, you can enter C:\Users\xxxx\.nuget\packages\knockoutjs\3.5.1 and find there is a folder called Content, Nuget will copy the content of that folder into your project when you install this nuget package.
But Content folder can be recognized by Packages.config format, and as far as I know, ContentFiles folder is used in PackageReference to add the content into your project. So in your situation, the nuget package should include ContentFiles folder at the same time. See this official document.
But the knockoutjs nuget package does not have contentfiles folder. That is why net framework projects with packages.config has the content files while new sdk projects does not have it.
And this behavior change can only be effective when you create the nuget package, so you ca n’t make any kind of change, you can only contact the author of the package to make this modification, and let him add this function as soon as possible to apply to the new SDK format project.
Suggestion
So So for now, you can try these:
1) you can either manually Add the content file from C:\Users\xxxx\.nuget\packages\knockoutjs\xxxx\Content to the project by Adding Existing Items.
2) roll back to use Net Framework projects with packages.config.
3) contact with the author on this link.

Why do we always need to install efcore via nuget in visual studio?

I am wondering why do we need to install EFCORE and it can't be just installed and done with with one install?
I am wondering why do we need to install EFCORE and it can't be just
installed and done with with one install?
EFCORE can serve as an object-relational mapper (O/RM), enabling .NET developers to work with a database using .NET objects, and eliminating the need for most of the data-access code they usually need to write.
However, not all the projects need this function and VS does not have this job by default. So if you want your project use it, you should install EFCore nuget packages.
About your questions, I think you have two aspects:
1) If you want all your current projects use EFCore projects, you can perform the nuget installation procedure once. Right-click on the solution-->Manage NuGet Packages for Solutions and then select EFCore. After that, choose any projects which you want to install this package.
2) If you want to already install EFCore when you create the project, you can customize a project template which contains this nuget package.
Create a project called projecttemplate, then install EFCore.
choose Project-->Export Template-->Project Template-->select this project
After that, close VS Instance, you can select the project template called projecttemplate in the menu which already contains EFCore.
In addition, when you download the EFCore, it is downloaded only once but stored in a global nuget cache folder. Every time you install the package in your project, you install it directly from the cache folder.

Installed nuget packages in Visual Studio 2019 project checkbox unchecked

I am trying to create a packages file for the project & noticed that installed nuget packages in Visual Studio 2019 have got the project box unchecked.
I am positive that I am using these packages in the project.
For instance I am using the Entity Framework for the data access & update. I have ensured that all the packages are still being used in the project & the packages.config file has got all the packages listed in it.
Visual Studio ScreenShot
Installed nuget packages in Visual Studio 2019 project checkbox
unchecked
The window which you provided actually does not actually work as you described. And it is just designed by that.
What you need to note is that the projects that can be displayed on this window, such as 2020Portal.Data, 2020Portal.Mailbox, etc., have already installed the nuget package Entity Framework. Only projects that already have the nuget package installed can be displayed in this window. That's why they show up there.
And the checkbox functionality is only intended to enable the selected items to perform uninstall or update the nuget Entity Framework. It's just for the convenience of choosing certain operations to perform.
Hope it could help you.

Reference hell accessing .netstandard with framework VS2019 preview

I can get my .net standard 2.0 package working in a .net framework 4.7.2 dll if I do the following steps
In my standard project VS2019 61.4.4 right click the project and select pack to create the .nupkg
Then I set up a nuget package source for the package
In my framework project I install nuget package
I get the following dialog
I choose PackageReference in project file
I answer yes to accept licensing
Then I can see the following
And I can get my project working.
However on a different machine running VS2019 16.5.0 Preview 2.0, I do not get the dialog asking me to choose the package manager format.
Instead the references look like
and I can not get my project working.
[Update]
After following Lance's link to migrate packages.config to PackageReference
The project looks like
I was able to remove the unwanted packages by right clicking references and choosing Remove Unused References
The program worked!
Go Tools=>Nuget Package Manager =>General => Package Management You can control the behavior by Allow format selection on first package install. Enable the checkbox and restart VS, this change will take effect.
And note the dialog only appears when we install first package in current project. So if you create a new project and install package, it will appear. And since you once installed packages in that project, the dialog won't appear in WindowsFormApp2 any more.
(But you can easily migrate packages.config to PackageReference, see this).

Install NuGet packages automatically in VS 2010 project template

Can anyone share with me how to (or where I can find how to) install NuGet packages automatically when I create a new project based on my custom project template in Visual Studio 2010?
I am creating a new project template for a project that uses a couple NuGet packages by default. I've read the documentation on the NuGet site but this is not acceptable in that I want to reference an existing package if it's already installed in the project.
In other words, if I embed package v1 in my template (VSIX) but version 1.1 has already been installed in the solution, I want NuGet to reference version 1.1 instead of putting v1 into the solution and forcing the developer to update the package.
Is this possible? And, if so, how?
NuGet 1.5 now supports this feature without requiring that you build an ASP.NET MVC 3 project template.
http://blogs.msdn.com/b/marcinon/archive/2011/07/08/project-templates-and-preinstalled-nuget-packages.aspx
This supersedes the post that I wrote. :)
Check out this post here:
http://haacked.com/archive/2011/06/06/creating-a-custom-asp-net-mvc-project-template.aspx
The article mentioned that the NuGet packages need to be on your machine, however this should change in the future (if it hasn't already).

Resources