Install NuGet packages automatically in VS 2010 project template - visual-studio-2010

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).

Related

How to install and use the latest Bootstrap in an MVC5 project?

I'm trying to use Bootstrap in my ASP.NET MVC5 project (I'd like to use .NET 5, but Visual Basic is not fully supported yet.)
I installed the latest NuGet package, but no folders/files were added to my project—only the package itself under the References node.
I found this extensive answer, but it's somewhat dated and it addresses a project architecture of ASP.NET Core. I added the suggested Package.json file, but no folder node_modules was added anywhere in my project.
How do I get started using the Bootstrap NuGet package in my MVC5 project?
--EDIT--
I'm using PackageReference, not Packages.config.
For Bootstrap is a client-side library,If you download by Nuget Package Manager, you can find it in the %UserProfile%\.nuget\packages directory. You could copy and paste it to your project.
Actually I suggest you could use LibMan for client-side library.
Here is the steps you could follow:
Create the folder wwwroot/lib;
In Solution Explorer, right-click the project folder in which the files should be added. Choose Add > Client-Side Library.
Search for bootstrap#5.0.2 like below:
Click the Install button to download the files.
Reference:
Use LibMan with ASP.NET Core in Visual Studio
Note:
The js and css are in wwwroot/bootstrap/dist/.

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.

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).

VS 2017 - NuGet Manager does not add reference

I´m trying to add System.Management.Automation to my project.
My project uses the .Net framework 4.5.
In my last project, I was able to add this reference easily by the NuGet manager console where I just had to type "Install Package" + the package name.
This time I tried the same but without any success.
I also already tried the following steps but still no success:
Reinstall the package by "Update-Package"
Delete the NuGet package so VS will reinstall it
Clear Nuget Manager Cache
Change the .Net framework
Clear project
I don´t have any other options left so hopefully someone of you can help me.

Change which NuGet packages are installed by default

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?

Resources