what is the correct way of installing Google.Apis.Calendar.v3 using PowerShell - powershell

Using PowerShell v7.3.1, I am trying to install the Google.Apis.Calendar.v3 library, but I get this error.
As suggested I run Get-PackageSource
I have also installed .NET Framework 4.8.1
I have also tried Install-Module PowerShellGet -Force, which successfully installed the module, but then when I try Install-Package Google.Apis.Calendar.v3 I get the same error.
what is the correct way of installing Google.Apis.Calendar.v3 using PowerShell?

Google.Apis.Calendar.v3 is a Google package. Which is hosted on NuGet
You don't appear to have NuGet set as a package source See: register-packagesource
register-PackageSource -Name MyNuGet -Location https://www.nuget.org/api/v2 -ProviderName NuGet

Related

How to use Powershell's Uninstall-Package to uninstall *a* specific package from *a* specific csproject

So I'm trying to automate some workflow and I'm running into issues with uninstalling/reinstalling a specific package on a specific csproject. I know this is possible with Package-Manager, but how would I achieve this within a powershell script? Here's what my script looks like so far:
# delete package folder from local feed
Remove-Item 'C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\<packageFolder>' -Recurse
# delete past package
Remove-Item '.\<package>.nupkg'
# pack new package
nuget pack '<nuspecPath>.nuspec' -NoDefaultExcludes
# push package to local feed
nuget add '.\<package>.nupkg' -Source 'C:\Program Files (x86)\Microsoft SDKs\NuGetPackages'
**# Everything below this is not currently working #**
# Remove project's outdated package
Uninstall-Package -Name '<packageName>' -Project '<pathToProject>' -Force
# Install new package to project
Install-Package -Name '<packageName>' -Project '<pathToProject>' -Source 'C:\Program Files (x86)\Microsoft SDKs\NuGetPackages' -Force
So, apparently -Project or -ProjectName are not recognized atrributes when using Uninstall-Package in powershell.. So, how do I specify powershell to uninstall a specific package on a specific csproject? Any help or insights would be much appreciated!
I tried the above code and kept getting complaints about -ProjectName attribute. I thought that this command would uninstall a nuget package from a specific project and then reinstall a new version of that package to the project.
The following answer is valid for .NET (Core) SDK-style projects, but does not work for "classic" .NET Framework projects (see this comment):
You may use the dotnet CLI to manage your projects and solutions.
Run the following command to list all packages:
dotnet list <PATH-TO-PROJECT> package
Run the following command to remove a package from the project:
dotnet remove <PATH-TO-PROJECT> package <PACKAGE-NAME>
See Install and manage NuGet packages with the dotnet CLI for more information.

'No match was found ..' when installing a module with -MinimumVersion

I believe I might be misunderstanding the -MinimumVersion parameter of Install-Module
The help states
Specifies the minimum version of a single module to install. The version installed must be greater than or equal to MinimumVersion. If there is a newer version of the module available, the newer version is installed.
However, with the following command
Install-Module -Name RunAsUser -MinimumVersion 2.3.1
I receive this error
PackageManagement\Find-Package : No match was found for the specified search criteria and module name 'RunAsUser'.
Try Get-PSRepository to see all available registered module repositories.
If I instead run
Install-Module -Name RunAsUser -RequiredVersion 2.3.1
It will install version 2.3.1 successfully. If I run
Install-Module -Name RunAsUser
It will install the latest which is 2.4.0 Am I misusing the -MinimumVersion parameter?
Powershell version 5.1.19041.2364
I got this error trying to update PowershellGet with -Scope CurrentUser
PackageManagement\Install-Package : The following commands are already available on this
system:'Find-Package,Install-Package,Uninstall-Package'. This module 'PackageManagement' may override the existing
commands. If you still want to install this module 'PackageManagement', use -AllowClobber parameter.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1809 char:21
Seemed like all these issues related to 1.0.0.1 so I simply went into C:\Program Files\WindowsPowershell\Modules\PowerhsellGet and moved the folder 1.0.0.1 out of there. Now everything is working as expected.

Unable to install NuGet package provider in PowerShell Core on Linux

I'm trying to set up the NuGet package provider on Linux in PowerShell 7 so I can useInstall-Package to get a package from the NuGet Gallery. However, when I run:
Install-PackageProvider -Name NuGet -Force
I get the following error:
Install-PackageProvider: No match was found for the specified search criteria for the provider 'NuGet'.
The package provider requires 'PackageManagement' and 'Provider' tags. Please check if the specified
package has the tags.
I did a bit of searching and found a few questions from this site and others where this error occurs, some answers saying I need to force TLS 1.2:
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
some saying to specify -RequiredVersion on Install-PackageSource, some saying to use-ForceBootstrap, and some saying to use -Force. None of these work and I'm still met with the same error each time. Get-PackageProvider lists NuGet as a provider.
I'm was also unable to install the NuGet provider on Windows using PowerShell Core with the same error. Is this just not supported from PowerShell Core?
I also received this error and specifying the version (currently 3.0.0.1) also fails. What worked for me was piping the packageprovider into Install-PackageProvider
Get-PackageProvider | where name -eq 'nuget' | Install-PackageProvider
You may add -Force if you want to avoid answering yes to The package(s) come(s) from a package source that is not marked as trusted. Are you sure you want to install software from ''?
The NuGet location has been updated. You can also do it in one line:
Register-PackageSource -Name nuget.org -ProviderName NuGet -Location "https://api.nuget.org/v3/index.json" -Trusted
Having TLS12 set in conjunction with Install Nuget package worked for me.
Below is how I used the command:
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
Install-PackageProvider -Name NuGet
In addition to #DougMaurer's answer, I also had to configure the package source as well:
$sourceArgs = #{
Name = 'nuget.org'
Location = 'https://api.nuget.org/v3/index.json'
ProviderName = 'NuGet'
}
Register-PackageSource #sourceArgs

install-package with chocolatey never adds anything to the path environment variable

The command install-package <packagename> -providerName chocolatey never seems to add anything to the PATH envirnoment variable (Windows 10 Build 15063).
For example running
install-package docfx -providerName chocolatey
install-package wkthmltopdf -providerName chocolatey
does not do it. Where as
choco install docfx
choco install wkhtmltopdf
does it. When I run the latter the commands docfx and wkhtmltopdf are available in the command line.
So my question is: How is installation different when using the choco command directly compared to install-package and what can I do about this?
As Rob Reynolds pointed out to me on gitter that package provider is not ready for prime time:
do not use the
prototype provider for OneGet/PackageManagement - it's not official,
it's a non-fully featured prototype made by MS and it may have
security issues. See
https://github.com/chocolatey/chocolatey-oneget/issues/5#issuecomment-275404099
for details

Install-Module : The term 'Install-Module' is not recognized as the name of a cmdlet

I was trying to install Azure using Install-Module Azure in PowerShell. I got the following error:
PS C:\Windows\system32> Install-Module Azure
Install-Module : The term 'Install-Module' is not recognized as the name of a cmdlet, function, script file,
or operable program. Check the spelling of the name, or if a path was included, verify that the path is corre
ct and try again.
At line:1 char:1
+ Install-Module Azure
+ ~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Install-Module:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Why is PS not recognizing the basic Install module? Without this I can't even install Azure. What should I do?
Since you are using the lower version of PS:
What you can do in your case is you first download the module in your local folder.
Then, there will be a .psm1 file under that folder for this module.
You just
import-Module "Path of the file.psm1"
Here is the link to download the Azure Module:
Azure Powershell
This will do your work.
Another GUI based option to fix this error is to download the PackageManagement PowerShell Modules (msi installer) from Microsoft website and install the modules.
Once this is installed you will not get the error
'Install-Module' is not recognized as the name of a cmdlet.
You should install the latest version of PowerShell, then use this command Install-Module Azure to install azure module. Because from Powershell 5.0 onwards you , you will be able to use the cmdlet to Install-Module, Save-Module
PS > $psversiontable
Name Value
---- -----
PSVersion 5.1.14393.576
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.576
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
More information about install Azure PowerShell, refer to the link.
I have Windows 10 and PowerShell 5.1 was already installed. For whatever reason the x86 version works and can find "Install-Module", but the other version cannot.
Search your Start Menu for "powershell", and find the entry that ends in "(x86)":
Here is what I experience between the two different versions:
I lost couple of days trying to resolve this until I got a simple solution. I just copy from another Win10 machine with a working Powershell 5.1 installation the following directories:
C:\Program Files\WindowsPowerShell\Modules\PackageManagement
C:\Program Files\WindowsPowerShell\Modules\PowerShellGet
To the same directories in the problem machine and don't change permissiones or anything and just run the command Install-Module and the problem was solved. I hope this can help some tormented soul.
If you are trying to install a module that is listed on the central repository for PS content called PowerShell Gallery, you need to install PowerShellGet. Then the command will be available. I'm currently using PS 4.0. Installing PowerShellGet did the trick for me.
Source:
With the latest PowerShellGet module, you can:
Search through items in the Gallery with Find-Module and Find-Script
Save items to your system from the Gallery with Save-Module and Save-Script
Install items from the Gallery with Install-Module and Install-Script
Upload items to the Gallery with Publish-Module and Publish-Script
Add your own custom repository with Register-PSRepository
Another great article to get started with PS Gallery.
I didn't have the NuGet Package Provider, you can check running Get-PackageProvider:
PS C:\WINDOWS\system32> Get-PackageProvider
Name Version DynamicOptions
---- ------- --------------
msi 3.0.0.0 AdditionalArguments
msu 3.0.0.0
NuGet <NOW INSTALLED> 2.8.5.208 Destination, ...
The solution was installing it by running this command:
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
If that fails with the error below you can copy/paste the NuGet folder from another PC (admin needed):
C:\Program Files\PackageManagement\ProviderAssemblies\NuGet:
WARNING: Unable to download from URI 'https://onegetcdn.azureedge.net/providers/Microsoft.PackageManagement.NuGetProvider-2.8.5.208.dll' to ''.
WARNING: Failed to bootstrap provider 'https://onegetcdn.azureedge.net/providers/nuget-2.8.5.208.package.swidtag'.
WARNING: Failed to bootstrap provider 'nuget'.
WARNING: The specified PackageManagement provider 'NuGet' is not available.
PackageManagement\Install-PackageProvider : Unable to download from URI
'https://onegetcdn.azureedge.net/providers/Microsoft.PackageManagement.NuGetProvider-2.8.5.208.dll' to ''.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\PSModule.psm1:6463 char:21
+ $null = PackageManagement\Install-PackageProvider -Name $script:NuGe ...
Run the below commands as admin to install NuGet using Powershell:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Install-PackageProvider -Name NuGet
I was running an older server where I couldn't run install-module because the PowerShell version was 4.0. You can check the PowerShell version using the PowerShell command line
ps>HOST .
https://gallery.technet.microsoft.com/office/PowerShell-Install-Module-388e47a1
Use this link to download necessary updates. Check to see if your
Windows version needs the update.
I think the answer posted by Jeremy Thompson is the correct one, but I don't have enough street cred to comment. Once I updated nuget and powershellget, Install-Module was available for me.
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Install-PackageProvider -Name Powershellget -Force
What is interesting is that the version numbers returned by get-packageprovider didn't change after the update.
The fix for me was to use PowerShell 7 instead of 5 (Windows Terminal).
Get latest Powershell 7.* version, which is now cross platform
https://github.com/PowerShell/PowerShell
Actually my solution to this problem was much simpler, because I already had the latest version of PowerShell and is still didn't recognize Install-Module command. What fixed the "issue" for me was just typing the command manually, since originally I tried copying the snippet from a website and apparently there was some issue with the formatting when copy&pasting, so when I typed the command manually it installed the module without any problem.