Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port the changes from main - ApplyDotNetSdkEnvironmentVariables, AllowQueryAllRuntimeVersions #284

Merged
merged 7 commits into from
Mar 13, 2024
173 changes: 92 additions & 81 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,91 +1,102 @@
pool:
name: VSEngSS-MicroBuild2022-1ES
demands: msbuild

variables:
BuildConfiguration: 'Release'
BuildPlatform: ''
Codeql.Enabled: true

steps:
- task: MicroBuildSigningPlugin@1
inputs:
signType: '$(SignType)'
zipSources: true

- task: MSBuild@1
displayName: '/t:Pack'
inputs:
solution: MSBuildLocator.sln
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
msbuildArguments: '/t:Pack /restore -binaryLogger:$(Build.SourcesDirectory)\Pack.binlog'

- task: CopyFiles@2
displayName: 'Collect Symbols'
inputs:
SourceFolder: src/MSBuildLocator
Contents: '**\*.pdb'
TargetFolder: '$(Build.ArtifactStagingDirectory)/symbols'
CleanTargetFolder: true

- task: PublishSymbols@2
displayName: 'Enable Source Server'
inputs:
SymbolsFolder: '$(Build.ArtifactStagingDirectory)\symbols'
SearchPattern: '**/*.pdb'
SymbolServerType: TeamServices
- name: BuildPlatform
value: ''
- name: BuildConfiguration
value: 'Release'
- name: TeamName
value: 'MSBuildLocator'

- task: PublishBuildArtifacts@1
displayName: 'Upload Symbols Artifact'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)/symbols'
ArtifactName: Symbols
resources:
repositories:
- repository: CustomPipelineTemplates
type: git
name: 1ESPipelineTemplates/MicroBuildTemplate

- task: CopyFiles@2
displayName: 'Copy Bin to drop'
inputs:
SourceFolder: 'src\MSBuildLocator\bin\Release'
TargetFolder: '$(Build.ArtifactStagingDirectory)\bin'
extends:
template: azure-pipelines/MicroBuild.1ES.Official.yml@CustomPipelineTemplates
parameters:
pool:
name: VSEngSS-MicroBuild2022-1ES
demands:
- msbuild
sdl:
sourceAnalysisPool:
name: VSEngSS-MicroBuild2022-1ES
stages:
- stage: stage
jobs:
- job: job
templateContext:
outputs:
- output: pipelineArtifact
displayName: 'Upload Symbols Artifact'
targetPath: '$(Build.ArtifactStagingDirectory)/symbols'
artifactName: Symbols
- output: pipelineArtifact
displayName: 'Upload Bin to drop'
targetPath: '$(Build.ArtifactStagingDirectory)\bin'
artifactName: bin
- output: pipelineArtifact
displayName: 'Upload NuGet to drop'
targetPath: '$(Build.ArtifactStagingDirectory)\pkg'
artifactName: pkg
- output: pipelineArtifact
displayName: 'Upload MicroBuildOutputs to drop'
targetPath: '$(Build.StagingDirectory)\MicroBuild\Output'
artifactName: MicroBuildOutputs
continueOnError: true
- output: pipelineArtifact
displayName: 'Upload logs to drop'
targetPath: '$(Build.ArtifactStagingDirectory)\logs'
artifactName: logs
condition: succeededOrFailed()
steps:
- task: MicroBuildSigningPlugin@1
inputs:
signType: '$(SignType)'
zipSources: true

- task: PublishBuildArtifacts@1
displayName: 'Upload Bin to drop'
inputs:
PathToPublish: '$(Build.ArtifactStagingDirectory)\bin'
ArtifactName: bin
- task: MSBuild@1
displayName: '/t:Pack'
inputs:
solution: MSBuildLocator.sln
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
msbuildArguments: '/t:Pack /restore -binaryLogger:$(Build.SourcesDirectory)\Pack.binlog'

- task: CopyFiles@2
displayName: 'Copy NuGet to drop'
inputs:
SourceFolder: 'src\MSBuildLocator\bin\Release'
Contents: '*.nupkg'
TargetFolder: '$(Build.ArtifactStagingDirectory)\pkg'
- task: CopyFiles@2
displayName: 'Collect Symbols'
inputs:
SourceFolder: src/MSBuildLocator
Contents: '**\*.pdb'
TargetFolder: '$(Build.ArtifactStagingDirectory)\symbols'
CleanTargetFolder: true

- task: PublishBuildArtifacts@1
displayName: 'Upload NuGet to drop'
inputs:
PathToPublish: '$(Build.ArtifactStagingDirectory)\pkg'
ArtifactName: pkg
- task: PublishSymbols@2
displayName: 'Enable Source Server'
inputs:
SymbolsFolder: '$(Build.ArtifactStagingDirectory)\symbols'
SearchPattern: '**/*.pdb'
SymbolServerType: TeamServices

- task: PublishPipelineArtifact@1
displayName: 'Upload MicroBuildOutputs to drop'
inputs:
TargetPath: '$(Build.StagingDirectory)\MicroBuild\Output'
ArtifactName: MicroBuildOutputs
continueOnError: true
- task: CopyFiles@2
displayName: 'Copy Bin to drop'
inputs:
SourceFolder: 'src\MSBuildLocator\bin\Release'
TargetFolder: '$(Build.ArtifactStagingDirectory)\bin'

- task: CopyFiles@2
displayName: 'Copy logs to drop'
inputs:
Contents: '**\*.*log'
TargetFolder: '$(Build.ArtifactStagingDirectory)\logs'
- task: CopyFiles@2
displayName: 'Copy NuGet to drop'
inputs:
SourceFolder: 'src\MSBuildLocator\bin\Release'
Contents: '*.nupkg'
TargetFolder: '$(Build.ArtifactStagingDirectory)\pkg'

- task: PublishBuildArtifacts@1
displayName: 'Upload logs to drop'
inputs:
PathToPublish: '$(Build.ArtifactStagingDirectory)\logs'
ArtifactName: logs
condition: succeededOrFailed()
- task: CopyFiles@2
displayName: 'Copy logs to drop'
inputs:
Contents: '**\*.*log'
TargetFolder: '$(Build.ArtifactStagingDirectory)\logs'

- task: ms-vseng.MicroBuildTasks.521a94ea-9e68-468a-8167-6dcf361ea776.MicroBuildCleanup@1
displayName: 'Execute cleanup tasks'
- task: ms-vseng.MicroBuildTasks.521a94ea-9e68-468a-8167-6dcf361ea776.MicroBuildCleanup@1
displayName: 'Execute cleanup tasks'
6 changes: 3 additions & 3 deletions src/MSBuildLocator.Tests/Microsoft.Build.Locator.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Shouldly" Version="4.2.1" />
<PackageReference Include="xunit" Version="2.6.6" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7" />
</ItemGroup>

<ItemGroup>
Expand Down
36 changes: 26 additions & 10 deletions src/MSBuildLocator/MSBuildLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;

#if NETCOREAPP
using System.Runtime.Loader;
#else
using System.Diagnostics;
#endif

namespace Microsoft.Build.Locator
Expand Down Expand Up @@ -139,17 +140,16 @@ public static void RegisterInstance(VisualStudioInstance instance)
string nugetPath = Path.GetFullPath(Path.Combine(instance.MSBuildPath, "..", "..", "..", "Common7", "IDE", "CommonExtensions", "Microsoft", "NuGet"));
if (Directory.Exists(nugetPath))
{
RegisterMSBuildPath(new string[] { instance.MSBuildPath, nugetPath });
RegisterMSBuildPathsInternally(new string[] { instance.MSBuildPath, nugetPath });
}
else
{
RegisterMSBuildPath(instance.MSBuildPath);
RegisterMSBuildPathsInternally(new string[] { instance.MSBuildPath });
}
}

/// <summary>
/// Add assembly resolution for Microsoft.Build core dlls in the current AppDomain from the specified
/// path.
/// Add assembly resolution for Microsoft.Build core dlls in the current AppDomain from the specified path and register environment variables for it.
/// </summary>
/// <param name="msbuildPath">
/// Path to the directory containing a deployment of MSBuild binaries.
Expand All @@ -160,12 +160,15 @@ public static void RegisterInstance(VisualStudioInstance instance)
/// </param>
public static void RegisterMSBuildPath(string msbuildPath)
{
RegisterMSBuildPath(new string[] { msbuildPath });
#if NETCOREAPP
ApplyDotNetSdkEnvironmentVariables(msbuildPath);
#endif
RegisterMSBuildPathsInternally(new string[] { msbuildPath });
}

/// <summary>
/// Add assembly resolution for Microsoft.Build core dlls in the current AppDomain from the specified
/// path.
/// paths and register environment variables for the first path.
/// </summary>
/// <param name="msbuildSearchPaths">
/// Paths to directories containing a deployment of MSBuild binaries.
Expand All @@ -176,6 +179,17 @@ public static void RegisterMSBuildPath(string msbuildPath)
/// </param>
public static void RegisterMSBuildPath(string[] msbuildSearchPaths)
{
#if NETCOREAPP
if (msbuildSearchPaths.Any())
{
ApplyDotNetSdkEnvironmentVariables(msbuildSearchPaths.FirstOrDefault());
}
#endif
RegisterMSBuildPathsInternally(msbuildSearchPaths);
}

private static void RegisterMSBuildPathsInternally(string[] msbuildSearchPaths)
{
if (msbuildSearchPaths.Length < 1)
{
throw new ArgumentException("Must provide at least one search path to RegisterMSBuildPath.");
Expand Down Expand Up @@ -354,14 +368,16 @@ private static IEnumerable<VisualStudioInstance> GetInstances(VisualStudioInstan
if (devConsole != null)
yield return devConsole;

#if FEATURE_VISUALSTUDIOSETUP
#if FEATURE_VISUALSTUDIOSETUP
foreach (var instance in VisualStudioLocationHelper.GetInstances())
yield return instance;
#endif
#endif
#endif

#if NETCOREAPP
foreach (var dotnetSdk in DotNetSdkLocationHelper.GetInstances(options.WorkingDirectory, AllowQueryAllRuntimeVersions))
// AllowAllRuntimeVersions was added to VisualStudioInstanceQueryOptions for fulfilling Roslyn's needs. One of the properties will be removed in v2.0.
bool allowAllRuntimeVersions = AllowQueryAllRuntimeVersions || options.AllowAllRuntimeVersions;
foreach (var dotnetSdk in DotNetSdkLocationHelper.GetInstances(options.WorkingDirectory, allowAllRuntimeVersions))
yield return dotnetSdk;
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion src/MSBuildLocator/Microsoft.Build.Locator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)'=='net46'">
<PackageReference Include="Microsoft.VisualStudio.Setup.Configuration.Interop" Version="3.8.2112" PrivateAssets="all" />
<PackageReference Include="Microsoft.VisualStudio.Setup.Configuration.Interop" Version="3.9.2164" PrivateAssets="all" />
<PackageReference Include="Microsoft.VisualStudio.SDK.EmbedInteropTypes" Version="15.0.36" PrivateAssets="all" />
</ItemGroup>

Expand Down
10 changes: 10 additions & 0 deletions src/MSBuildLocator/VisualStudioInstanceQueryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ public class VisualStudioInstanceQueryOptions
/// </summary>
public DiscoveryType DiscoveryTypes { get; set; }

#if NETCOREAPP
/// <summary>
/// Allow discovery of .NET SDK versions that are unlikely to be successfully loaded in the current process.
/// </summary>
/// <remarks>
/// Defaults to <see langword="false"/>. Set this to <see langword="true"/> only if your application has special logic to handle loading an incompatible SDK, such as launching a new process with the target SDK's runtime.
/// </remarks.
public bool AllowAllRuntimeVersions { get; set; } = false;
#endif

/// <summary>
/// Working directory to use when querying for instances. Ensure it is the project directory to pick up the right global.json.
/// </summary>
Expand Down
Loading