Code Monkey home page Code Monkey logo

vssetup.powershell's Introduction

Visual Studio Setup PowerShell Module

build status: master build status: develop github release github releases: all PowerShell Gallery

This PowerShell module contains cmdlets to query instances of Visual Studio 2017 and newer. It also serves as a more useful sample of using the Setup Configuration APIs than the previously published samples though those also have samples using VB and VC++.

Installing

With Windows Management Framework 5.0 or newer (which installs PowerShell and comes with Windows 10), or PowerShellGet for PowerShell 3.0 or 4.0, you can download and install this module easily.

Install-Module VSSetup -Scope CurrentUser

To install for all users, pass AllUsers instead of CurrentUser, or just leave the -Scope parameter out of the command entirely.

You can also download the ZIP package from the Releases page on this project site and extract to a directory named VSSetup under a directory in your $env:PSMODULEPATH.

Expand-Archive VSSetup.zip "$([Environment]::GetFolderPath("MyDocuments"))\WindowsPowerShell\Modules\VSSetup"

Using

You can query all usable instances of Visual Studio and other products installed by the Visual Studio installer.

Get-VSSetupInstance

To get the instance for a specific installation directory, you can run the following.

Get-VSSetupInstance 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community'

If you want to select the latest instance that contains the .NET desktop development workload, you can pipe all instances - usable or not - to Select-VSSetupInstance that provides more fine grain control over which instances you enumerate.

Get-VSSetupInstance -All | Select-VSSetupInstance -Require 'Microsoft.VisualStudio.Workload.ManagedDesktop' -Latest

Feedback

To file issues or suggestions, please use the Issues page for this project on GitHub.

License

This project is licensed under the MIT license.

Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

vssetup.powershell's People

Contributors

b-higginbotham avatar bbrandt avatar davilimap avatar heaths avatar jberezanski avatar kinddragon avatar lwillia avatar microsoft-github-policy-service[bot] avatar milarso81 avatar preecington avatar tydunkel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vssetup.powershell's Issues

Cannot install VSSetup

Ran the following commands in Admin PowerShell window. The module did not load properly. Running Windows internal Microsoft release RS3 RTM Version 10.0.16299 Build 16299.

PS C:\WINDOWS\system32> Install-Module VSSetup -Scope CurrentUser
PS C:\WINDOWS\system32> Get-VSSetupInstance
Get-VSSetupInstance : The term 'Get-VSSetupInstance' 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 correct and
try again.
At line:1 char:1

  • Get-VSSetupInstance
  •   + CategoryInfo          : ObjectNotFound: (Get-VSSetupInstance:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException
    
    

PS C:\WINDOWS\system32> Get-Command -Module VSSetup
PS C:\WINDOWS\system32>

Create list of possible component names

I am trying to use this repository as an example of how to locate the MSVC tools (cl.exe, link.exe, et al) without making any assumptions as to where VS is installed. I understand that I can use the Select-VSSetupInstance cmdlet to identify the latest working version of VS that has the required workload. Unfortunately, I do not know what the internal name of the component or workload that contains the MSVC tools is, and therefore do not know what parameters to pass to that cmdlet! Could you please add a listing to this repository of all the workload display names and the corresponding programmatic IDs? This would make use of this code much easier. Thanks!

VS Preview not detected

I installed VS 2019 Preview, and noticed it's not detected as an instance while running:
Get-VSSetupInstance

Is there some option I'm missing or it just doesn't work with preview instances?

The setup configuration provider registration fix

I'm looking for a fix of visual studio registration or 'Microsoft Setup Configuration query API' registration (COM?). I know this is not a vssetup.powershell issue, but could be fixed by ' vssetup.powershell.

I noticed the symptom when I tried to install ReSharper on the VS2017 - 15.7 but the installer showed the following warning message:

Installer could not access the Microsoft Setup Configuration query API

So, I also run Get-VSSetupInstance (from this module) and get this error:

WARNING: The setup configuration provider is not registered. Assuming no registered instances.

Could be possible add a Cmd-Let to fix the registration?

I also run a clean up with:

%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\resources\app\layout\InstallCleanup.exe -i

and installed the VS again, but doesn't work.

Support asterisk for Product parameter to search all products

Please consider adding asterisk as special value for Product parameter of Select-VSSetupInstance that will search through all instances. This would allow finding all products with required workloads or components installed regardless if it is full VS instance or for example Build Tools installation.

vswhere tool supports * value for products filter as of version 1.0.40

Select-VSSetupInstance -Latest - is it about install date or version?

Select-VSSetupInstance -Latest - is it about install date or version?

The help says

-Latest [<SwitchParameter>]
    Select the most recently installed instance with the highest version (within the optional `-Version` range).

so it is not clear whether it is about date or version.

If we take a look at the code
then it looks like it is about installation dates and versions are not checked.

If it is true, is it by design that Latest deals with installation dates, not versions?

In any case, the help might be more clear about what is checked.

NB (Just for cross-reference) Loosely related to this issue nightroman/Invoke-Build#122

What's the equivalent of vswhere -find in vssetup.powershell

Hello

I would prefer to use vssetup.powershell, which is PowerShell native than vswhere.exe. However I can't find the PowerShell equivalent for the -find parameter of vswhere. For instance:

vswhere.exe -latest -requires Microsoft.VisualStudio.TestTools.TeamFoundationClient -find **\Microsoft.TeamFoundation.Client.dll

Is it supported by PowerShell? If so, how should I write it?

Thank you for your help

François

PS: this is a duplicate of vswhere:issue#189

Get-VsSetupInstance is unable to find the newly installed instance of Visual Studio 2019 without a reboot

We have a script which uses winget and custom powershell modules to install tools and visual studio 2019 for a self-hosted Azure Devops build agent. More often than not, Get-VSSetupInstance is unable to detect the newly installed instance of VS2019 if I execute it from the same powershell session used to install VS 2019. If I reboot the machine and re-execute Get-VSSetupInstance, it works. Is there something I am doing wrong? When installing visual studio, I am passing the --norestart parameter as specified here: https://docs.microsoft.com/en-us/visualstudio/install/use-command-line-parameters-to-install-visual-studio?view=vs-2019. The variable $VS2019 is used to calculate path for vsixinstaller.exe which we then use to programmatically download and install VSIX from the marketplace.

This is the powershell snippet we use and without a reboot, $VS2019 variable is $null.

switch ($Edition) {
    'Enterprise' { $DisplayName = 'Visual Studio Enterprise 2019'}
    'Professional' { $DisplayName = 'Visual Studio Professional 2019'}
    'Community' { $DisplayName = 'Visual Studio Community 2019'}
    'BuildTools' { $DisplayName = 'Visual Studio Build Tools 2019'}
}

$VsSetup = Get-InstalledModule -Name VsSetup -ErrorAction SilentlyContinue -Verbose:$false

if ($null -eq $VsSetup) {
    Install-Module -Name VsSetup -Repository PSGallery -Verbose:$false
}

Import-Module -Name VsSetup -Verbose:$false

$VS2019 = Get-VsSetupInstance -ErrorAction SilentlyContinue -Verbose:$false |  `
    Where-Object { ($_.DisplayName -ieq $DisplayName) -and ($_.Product.Id -ieq "Microsoft.VisualStudio.Product.$($Edition)") } | `
    Select-VSSetupInstance -Latest -Verbose:$false

Compatibility with Powershell 6.0?

I tried installing the feature as per the documentation steps and the module seems to install. However, when i attempt to invoke using the following command: Get-VSSetupInstance

The command is not detected. Lower versions of PS (5.0 below) seem to work, though.

Specs used:

  • PS 6.0.0-alpha.18
  • Win7 x64

Using 2019 BuildTools with 2017 compiler

Visual Studio 2019 installer allows you to install different versions of the compiler. e.g.

MSVC v142 - VS 2019 C++ x64/x86 build tools (v14.24)
MSVC v141 - VS 2017 C++ x64/x86 build tools (v14.16)
MSVC v140 - VS 2015 C++ build tools (v14.00)

I have all three of these installed but:

> Get-VSSetupInstance -All

InstanceId          : 13fe59b9
DisplayName         : Visual Studio Build Tools 2019
InstallationVersion : 16.4.29728.190
InstallationPath    : C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools
InstallDate         : 04/02/2020 16:22:55

How do I therefore set up a powershell session so that I can use the 2017 tools?

Failed to install module due to failed access to cloud file

When trying to install VSSetup module by running the following command:

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser
Install-Module VSSetup -Scope CurrentUser -Force -Confirm:$false

But it fails with "Access to the cloud file is denied"

PackageManagement\Install-Package : Access to the cloud file is denied
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1809 char:21

  • ... $null = PackageManagement\Install-Package @PSBoundParameters
  •                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Exception
    • FullyQualifiedErrorId : System.ComponentModel.Win32Exception,Microsoft.PowerShell.Commands.RemoveItemCommand,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

Not sure how to resolve this issue. Can't seem to find any help online as well.

Add support for previous VS versions

First of all, great module, very useful in build scripts!

I am mainstaining a couple of projects where it is desirable that they are buildable using previous versions of VS / tools. I therefore had to create a wrapper around VSSetup to be able to locate VS 2013 and 2015 too.

It would be nice if the VSSetup supported at least 2 previous VS versions natively.

Add DSC support

PowerShell modules can also deploy DSC types. Consider a DSC type to check if an instance matching the desired product and workloads is present, and to either update the existing product (if compatible, e.g. Enterprise requested and Enterprise present, so update it; otherwise, install it) or install a new one (i.e. while supported via command line, it's not supported in the user interface so probably not this option).

Digital signature from Microsoft is missing for the scripts

I am expecting Microsoft to digitally sign its powershell scripts. This might make the process in a rolling github relase more cumbersome. On the other hand the process of digitally signing the scripts can be automated. In the current state the unsigned script violates the execution policy on all Windows systems:

CouldNotAutoloadMatchingModule - script not signed!

Install command in README doesn't work

Install-Module VSSetup -Scope CurrentUser
Install-Module : A parameter cannot be found that matches parameter name 'Scope'.
At line:1 char:24
+ Install-Module VSSetup -Scope CurrentUser
+                        ~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Install-Module], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Install-Module

Further, I'm very curious how Powershell would know where to resolve VSSetup from.

I am on Windows 10 build 14393.rs1_release.161220-1747

Instances with errors are not enumerated

This is to track a potential bug in the COM server DLL I'm looking into. To allow the integration tests to pass I had to remove the "errors" property from instance 2, which should still indicate the instance is launchable.

need -Require SSIS

I need a way to -Require SSIS - that is, get whatever instance supports building Integration Services packages. Right now, I have a 2019 and a 2022. My -Latest is failing because 2022 does not yet have support for SSIS. I did a list of the workload/components, but it's not listed. Is there a way to capture these?
image

Can't import VSSetup module

version 2.0.1.32208

import-module vssetup
import-module : The following error occurred while loading the extended type data file: Error in TypeData
"Microsoft.VisualStudio.Setup.Instance": Type "Microsoft.VisualStudio.Setup.PowerShell.InstanceAdapter"
should be a PSPropertyAdapter.
At line:1 char:1

  • import-module vssetup
  •   + CategoryInfo          : InvalidOperation: (:) [Import-Module], RuntimeException
      + FullyQualifiedErrorId : FormatXmlUpdateException,Microsoft.PowerShell.Commands.ImportModuleCommand
    

Select-VSSetupInstance does not return Build Tools instances

For build agents, typically one will install just build tools, and not full Visual Studio.
In my situation, I have VS2017 (full) and VS2019 build tools installed on the agent, Get-VSSetupInstance nicely returns:

InstanceId          : b58ec7ca
DisplayName         : Visual Studio Build Tools 2019
InstallationVersion : 16.3.29403.142
InstallationPath    : C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools
InstallDate         : 10/9/2019 9:39:06 PM

InstanceId          : ed899074
DisplayName         : Visual Studio Professional 2017
InstallationVersion : 15.9.28307.770
InstallationPath    : C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional
InstallDate         : 10/17/2017 8:06:13 PM

However, if I pipe that to Select-VSSetupInstance -Latest, I only get back the VS2017 instance, which is not the latest.

It seems the Select-VSSetupInstance function only returns retail install instances?

Thanks

Cannot Remove-Module since VSSetupVersionTable is constant

Apparently never tested just removing the VSSetup module. One cannot since $VSSetupVersionTable is constant, nor can it be forcibly removed. Should make it read-only. Seems there'd be little incentive to change the values and $PSVersionTable doesn't prevent it either. Should also probably set the AllScope option as is set on $PSVersionTable.

BuildTools 16.3 not getting selected

I have BuildTools 16.3.8 installed on my machine Windows 10 1909 Build.
image

And want to get the installation path for the MSBuild. Eventually I want to run following command to get the InstallationPath:
Get-VSSetupInstance | Select-VSSetupInstance -Version '[16.2,)' -Latest | Select-Object -ExpandProperty InstallationPath

And I see nothing in output. So I tried debugging this and found that the Select-VSSetupInstance does not return anything.

PS C:\Windows\System32> Get-VSSetupInstance


InstanceId          : 50bb1fd5
DisplayName         : Visual Studio Build Tools 2019
InstallationVersion : 16.3.29503.13
InstallationPath    : C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools
InstallDate         : 10/17/2019 9:31:32 AM



PS C:\Windows\System32> Get-VSSetupInstance | Select-VSSetupInstance
PS C:\Windows\System32>

What am I missing?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.