Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace Microsoft.DotNet.Workloads.Workload
#endif
internal static class VisualStudioWorkloads
{
private static readonly object s_guard = new();

private const int REGDB_E_CLASSNOTREG = unchecked((int)0x80040154);

/// <summary>
Expand Down Expand Up @@ -204,44 +206,50 @@ internal static IEnumerable<WorkloadId> WriteSDKInstallRecordsForVSWorkloads(IIn
/// <returns>A list of Visual Studio instances.</returns>
private static List<ISetupInstance> GetVisualStudioInstances()
{
List<ISetupInstance> vsInstances = new();

try
// The underlying COM API has a bug where-by it's not safe for concurrent calls. Until their
// bug fix is rolled out use a lock to ensure we don't concurrently access this API.
// https://dev.azure.com/devdiv/DevDiv/_workitems/edit/2241752/
lock (s_guard)
{
SetupConfiguration setupConfiguration = new();
ISetupConfiguration2 setupConfiguration2 = setupConfiguration;
IEnumSetupInstances setupInstances = setupConfiguration2.EnumInstances();
ISetupInstance[] instances = new ISetupInstance[1];
int fetched = 0;
List<ISetupInstance> vsInstances = new();

do
try
{
setupInstances.Next(1, instances, out fetched);
SetupConfiguration setupConfiguration = new();
ISetupConfiguration2 setupConfiguration2 = setupConfiguration;
IEnumSetupInstances setupInstances = setupConfiguration2.EnumInstances();
ISetupInstance[] instances = new ISetupInstance[1];
int fetched = 0;

if (fetched > 0)
do
{
ISetupInstance2 instance = (ISetupInstance2)instances[0];
setupInstances.Next(1, instances, out fetched);

// .NET Workloads only shipped in 17.0 and later and we should only look at IDE based SKUs
// such as community, professional, and enterprise.
if (Version.TryParse(instance.GetInstallationVersion(), out Version version) &&
version.Major >= 17 &&
s_visualStudioProducts.Contains(instance.GetProduct().GetId()))
if (fetched > 0)
{
vsInstances.Add(instances[0]);
ISetupInstance2 instance = (ISetupInstance2)instances[0];

// .NET Workloads only shipped in 17.0 and later and we should only look at IDE based SKUs
// such as community, professional, and enterprise.
if (Version.TryParse(instance.GetInstallationVersion(), out Version version) &&
version.Major >= 17 &&
s_visualStudioProducts.Contains(instance.GetProduct().GetId()))
{
vsInstances.Add(instances[0]);
}
}
}
while (fetched > 0);

}
catch (COMException e) when (e.ErrorCode == REGDB_E_CLASSNOTREG)
{
// Query API not registered, good indication there are no VS installations of 15.0 or later.
// Other exceptions are passed through since that likely points to a real error.
}
while (fetched > 0);

return vsInstances;
}
catch (COMException e) when (e.ErrorCode == REGDB_E_CLASSNOTREG)
{
// Query API not registered, good indication there are no VS installations of 15.0 or later.
// Other exceptions are passed through since that likely points to a real error.
}

return vsInstances;
}
}
}
3 changes: 3 additions & 0 deletions test/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@
<Using Include="Xunit.Abstractions" />
</ItemGroup>

<ItemGroup>
<Content Include="$(MSBuildThisFileDirectory)xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Project>
1 change: 0 additions & 1 deletion test/dotnet-new.Tests/dotnet-new.IntegrationTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ namespace Microsoft.DotNet.Cli.New.IntegrationTests

<ItemGroup>
<Content Include="TestTemplates\**\*" Exclude="TestTemplates\**\bin\**;TestTemplates\**\obj\**" CopyToOutputDirectory="PreserveNewest" />
<Content Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 0 additions & 5 deletions test/dotnet-new.Tests/xunit.runner.json

This file was deleted.

3 changes: 0 additions & 3 deletions test/dotnet-watch.Tests/dotnet-watch.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
<Compile Include="..\..\src\Tasks\Microsoft.NET.Build.Tasks.UnitTests\Mocks\MockBuildEngine.cs" Link="Utilities\MockBuildEngine.cs" />
<Compile Include="..\..\src\Tasks\Microsoft.NET.Build.Tasks.UnitTests\Mocks\MockTaskItem.cs" Link="Utilities\MockTaskItem.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(RepoRoot)\src\BuiltInTools\dotnet-watch\dotnet-watch.csproj" />
<ProjectReference Include="$(RepoRoot)\src\BuiltInTools\DotNetWatchTasks\DotNetWatchTasks.csproj" />
Expand Down
4 changes: 0 additions & 4 deletions test/dotnet.Tests/dotnet.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,6 @@
<PackageReference Include="Microsoft.DotNet.Installer.Windows.Security.TestData" GeneratePathProperty="true" />
</ItemGroup>

<ItemGroup>
<Content Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<!-- Global usings -->
<!-- See: https://learn.microsoft.com/dotnet/core/project-sdk/msbuild-props#using -->
<ItemGroup>
Expand Down
6 changes: 0 additions & 6 deletions test/dotnet.Tests/xunit.runner.json

This file was deleted.

File renamed without changes.
Loading