Cannot add package to visual studio. (System.Management.Automation) - c#

Trying to add System.Management.Automation package to my project in visual studio because I want to run powershell commands through my code, but am getting the error:
The project does not support adding package references through the add
package command. My dotnet --version is: 7.0.102
I inputted
dotnet add package System.Management.Automation --version 7.3.2
into the package manager console, and was expecting it to work as normal when adding a nuget package, however instead received the error
Error while adding package 'System.Management.Automation' to project
'C:\Users\userone\source\repos\blackjack21\blackjack21.csproj'. The
project does not support adding package references through the add
package command.
No idea what to do.

Related

Nuget package installed even if it is not included in project [duplicate]

I want to list down all the nuget packages along with its dependencies recursively.
Project is in VS2017 and .NET Core.
I tried with Get-Package -ProjectName "Your.Project.Name" it displays all the nuget packages in project. I want all the dependencies also printed.
You can use the dotnet cli: dotnet list package --include-transitive. The dotnet-outdated global tool probably has similar functionality.

c# dotnet CLI "error: There are no versions available for the package 'Newtonsoft.Json'."

I am new to c# , I am trying to add package to my project I tried before to add "Microsoft.Toolkit.Uwp.Notifications" by dotnet cli dotnet add package Microsoft.Toolkit.Uwp.Notifications , and then tried to mimic Microsoft example Microsoft.Docs but it always shows this error , any help please?
info : Adding PackageReference for package 'Newtonsoft.Json' into project 'C:\Users\moham\cs\cs.csproj'.
error: There are no versions available for the package 'Newtonsoft.Json'.
EDIT :
when I tried dotnet add package Newtonsoft.Json --version 13.0.1 I got this error : CMD error
I had the same issue, I fix it running this command
dotnet nuget add source --name nuget.org https://api.nuget.org/v3/index.json
See this issue https://github.com/dotnet/sdk/issues/4156 for more details.
Hope this helps you ;)
Welcome to the world of C#! While Microsoft.Toolkit.Uwp.Notifications doesn't appear to be dependent on Newtonsoft.Json, there may be another dependency in your project file. May I have you try adding Newtonsoft.Json FIRST, and then attempt to add the Mictrosoft.Toolkiy.Uwp.Notifications package afterwards?
dotnet add package Newtonsoft.Json --version 13.0.1
dotnet add package Microsoft.Toolkit.Uwp.Notifications --version 7.0.1

dotnet restore on .NET Framework project not working

I have a .NET project with the following in its .csproj
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
When I run dotnet restore project-file.csproj I get the following:
Nothing to do. None of the projects specified contain packages to restore.
Why is this? I thought the dotnet cli could work with non Core projects too?
I have nuget packages that are referenced, so I expect the cli to go and download the nuget packages.
dotnet cli works properly with .NET Framework only if the project was created from dotnet new command. If you create project from Visual Studio the structure of .csroj files will be different and you usually cannot run cli commands towards them
Visual Studio only allows you to run nuget commands from nuget console (package manager console) within Visual Studio itself.
If you want to do nuget restore from command line:
Download nuget executable from https://www.nuget.org/downloads
(it is not a installer/package, but actual executable!)
Save it to a folder of your choice and add it to the PATH.
Then, as suggested above: nuget restore solutionname.sln (but this time you don't have to run Visual Studio!)

How to add a package from a local source?

I'm trying to build a C# console application using Visual Studio Code but when I try to install packages the application uses wrong local folder with as a local source.
I have dotnet installed in my C program files, I think the program will be solved if I can use my dotnet folder as a local source but I don't know how to do it.
I tried these commands in terminal :
dotnet add package Microsoft.EntityFrameworkCore
dotnet add package Microsoft.EntityFrameworkCore.Design
dotnet add package Microsoft.EntityFrameworkCore.Tools
and I get this error:
MovieAPP>dotnet add package Microsoft.EntityFrameworkCore Writing C:\Users\Ahmed\AppData\Local\Temp\tmpB0AD.tmp info : Adding PackageReference for package 'Microsoft.EntityFrameworkCore' into project 'E:\courses\C-Sharp\MovieAPP\MovieAPP.csproj'. log : Restoring packages for E:\courses\C-Sharp\MovieAPP\MovieAPP.csproj...
Writing C:\Users\user\AppData\Local\Temp\tmpACF8.tmp
info : Adding PackageReference for package 'Microsoft.EntityFrameworkCore' into project 'E:\courses\C-Sharp\MovieAPP\MovieAPP.csproj'.
log : Restoring packages for E:\courses\C-Sharp\MovieAPP\MovieAPP.csproj...
error: The local source 'C:\Users\user\Downloads\Compressed\WebMatrixExtensionsGallery' doesn't exist.

Managing References in Visual Studio 2012

Please help me understand: I have a Visual Studio project. It has Nuget package manager enabled. I install several libraries. The library versions are shown in packages.config. Each library has a corresponding entry in References.
Now, say I want to change the library version from, say, 2.2.0 to 2.1.0. How I do this? At first I assumed you could just change the version number in packages.config. But when I do this, and get Nuget to download an earlier version of the library, the project references are not changed.
Do I have to manually remove each and every reference in the project to 2.2.0 and replace it with 2.1.0?
I get the feeling I'm "doing it wrong", but there doesn't seem to be any examples I can find of anyone doing it right.
Thanks for any help!
Using jQuery as an example:
If you want to rollback to a previous version you can run the Uninstall-Package jQuery and Install-Package jQuery -Version 2.1.0 commands from the package manager console.
Also, the package nuget page will have a list off all the versions available. EX: jQuery
All of this and more available in the nuget Docs
You can't simply change the version in the config file since your project still holds a reference to the binaries, so the binaries need to be replaced too.
Now, I'm not entirely sure if there is a "downgrade" Powershell command but you can certainly uninstall the specific package and then install a lower version. By using the Package Manager Console. So from within Visual Studio:
Go to the View menu -> Other Windows -> Package Manager Console
Select the Default Project from the dropdown list
Then run the following command to uninstall the package
The command to uninstall is...
Uninstall-Package YOUR_PACKAGE_NAME
To install a lower version, run this command...
Install-Package YOUR_PACKAGE_NAME -Version 1.0
These and other commands are very well documented in The Package Manager Console Powershell Reference
Uninstall-Package Command
Install-Package Command

Categories