问题描述
大家好,
我们已经在我的项目中使用以下代码来检查VS2017是否安装在机器中。
问题描述:
下面的代码返回VS2017安装路径(C:\Program Files(x86)\ Mesrosoft Visual Studio\2017 \Professional)如果我们有VS2017的机器。
$
在单独的VS2019机器中,它返回VS2019安装路径(C:\Program Files(x86) )\ Microsoft Visual Studio \\\ 2019 \专业)正确。
但是,在VS2019和VS2017安装的机器上它只返回VS2017安装路径(C:\\ \\ Program Program(x86)\ Microsoft Visual Studio \\\ 2017(专业),所以我们无法在VS(2019& VS2017)安装的机器上找到VS2019或不安装。
Already we are using below code in my project to check VS2017 installed or not in machine .
Issue Description:
Below code returns VS2017 installed path (C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional) if we have machine with VS2017.
In VS2019 alone machine ,it returns VS2019 installation path (C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional) properly.
But, in Both VS2019 and VS2017 installed machine it returns only VS2017 installation path (C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional) ,So we could not find out VS2019 installed or not in both VS (2019 & VS2017 ) installed machine.
我想通过编程方式单独了解VS2019的安装路径,即使我的机器有VS2017和VS2019。
I want to know VS2019 installed path alone by pro-grammatically even my machine has VS2017 and VS2019.
public string GetVS2017AndHigherInstallationPath()
{
try
{
string installedPath = string.Empty;
var query = GetQuery();
var query2 = (ISetupConfiguration2)query;
var e = query2.EnumAllInstances();
var helper = (ISetupHelper)query;
int fetched;
var instances = new ISetupInstance[1];
e.Next(1, instances, out fetched);
return instances[0].GetInstallationPath();
}
catch (Exception ex)
{
return string.Empty;
}
}
谢谢,
Vijay
推荐答案
这应该能够为您提供基于您的Visual Studio版本usecase,如果VS正在运行。
这篇关于如何通过C#程序检查我们机器上是否安装了VS2019 Preview?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!