Skip to content

Commit

Permalink
Merge branch 'main' into merge/vs17.9-to-main
Browse files Browse the repository at this point in the history
  • Loading branch information
JanKrivanek committed Jan 5, 2024
2 parents bb6fadf + 37033b4 commit 26b5d33
Show file tree
Hide file tree
Showing 101 changed files with 2,577 additions and 669 deletions.
5 changes: 2 additions & 3 deletions .vsts-dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ stages:
value: Products/$(System.TeamProject)/$(Build.Repository.Name)/$(Build.SourceBranchName)/$(Build.BuildNumber)

steps:
- task: NuGetToolInstaller@0
inputs:
versionSpec: '4.9.2'
- task: NuGetToolInstaller@1
displayName: 'Install NuGet.exe'

- task: NuGetCommand@2
displayName: Restore internal tools
Expand Down
241 changes: 160 additions & 81 deletions documentation/specs/project-cache.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions documentation/wiki/ChangeWaves.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ A wave of features is set to "rotate out" (i.e. become standard functionality) t
- [Target parameters will be unquoted](https://github.com/dotnet/msbuild/pull/9452), meaning the ';' symbol in the parameter target name will always be treated as separator
- [Change Version switch output to finish with a newline](https://github.com/dotnet/msbuild/pull/9485)
- [Load Microsoft.DotNet.MSBuildSdkResolver into default load context (MSBuild.exe only)](https://github.com/dotnet/msbuild/pull/9439)
- [Load NuGet.Frameworks into secondary AppDomain (MSBuild.exe only)](https://github.com/dotnet/msbuild/pull/9446)

### 17.8
- [[RAR] Don't do I/O on SDK-provided references](https://github.com/dotnet/msbuild/pull/8688)
Expand Down
2 changes: 0 additions & 2 deletions eng/SourceBuildPrebuiltBaseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

<UsageData>
<IgnorePatterns>
<UsagePattern IdentityGlob="Microsoft.SourceBuild.Intermediate.*/*" />

<!-- Baseline 7.0 dependencies until msbuild targets net8 and uses a net8 arcade, SBRP, etc.
These cannot be added to 7.0 SBRP, because they would are produced in the 7.0 build. -->
<UsagePattern IdentityGlob="System.Collections.Immutable/*8.0.0*" />
Expand Down
3 changes: 1 addition & 2 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the MIT license. See License.txt in the project root for full license information. -->
<Project>
<PropertyGroup>
<VersionPrefix>17.9.2</VersionPrefix>
<DotNetFinalVersionKind>release</DotNetFinalVersionKind>
<VersionPrefix>17.10.0</VersionPrefix>
<PackageValidationBaselineVersion>17.8.3</PackageValidationBaselineVersion>
<AssemblyVersion>15.1.0.0</AssemblyVersion>
<PreReleaseVersionLabel>preview</PreReleaseVersionLabel>
Expand Down
28 changes: 14 additions & 14 deletions src/Build.UnitTests/BinaryLogger_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,13 @@ public void UnusedEnvironmentVariablesDoNotAppearInBinaryLog()
</Project>";
TransientTestFolder logFolder = env.CreateFolder(createFolder: true);
TransientTestFile projectFile = env.CreateFile(logFolder, "myProj.proj", contents);
BinaryLogger logger = new();
logger.Parameters = _logFile;
RunnerUtilities.ExecMSBuild($"{projectFile.Path} -bl:{logger.Parameters}", out bool success);

RunnerUtilities.ExecMSBuild($"{projectFile.Path} -bl:{_logFile}", out bool success);
success.ShouldBeTrue();
RunnerUtilities.ExecMSBuild($"{logger.Parameters} -flp:logfile={Path.Combine(logFolder.Path, "logFile.log")};verbosity=diagnostic", out success);

RunnerUtilities.ExecMSBuild($"{_logFile} -flp:logfile={Path.Combine(logFolder.Path, "logFile.log")};verbosity=diagnostic", out success);
success.ShouldBeTrue();

string text = File.ReadAllText(Path.Combine(logFolder.Path, "logFile.log"));
text.ShouldContain("EnvVar2");
text.ShouldContain("value2");
Expand Down Expand Up @@ -230,10 +231,9 @@ private void AssemblyLoadsDuringTaskRun(string additionalEventText)
""";
TransientTestFolder logFolder = env.CreateFolder(createFolder: true);
TransientTestFile projectFile = env.CreateFile(logFolder, "myProj.proj", contents);
BinaryLogger logger = new();
logger.Parameters = _logFile;

env.SetEnvironmentVariable("MSBUILDNOINPROCNODE", "1");
RunnerUtilities.ExecMSBuild($"{projectFile.Path} -nr:False -bl:{logger.Parameters} -flp1:logfile={Path.Combine(logFolder.Path, "logFile.log")};verbosity=diagnostic -flp2:logfile={Path.Combine(logFolder.Path, "logFile2.log")};verbosity=normal", out bool success);
RunnerUtilities.ExecMSBuild($"{projectFile.Path} -nr:False -bl:{_logFile} -flp1:logfile={Path.Combine(logFolder.Path, "logFile.log")};verbosity=diagnostic -flp2:logfile={Path.Combine(logFolder.Path, "logFile2.log")};verbosity=normal", out bool success);
success.ShouldBeTrue();

string assemblyLoadedEventText =
Expand All @@ -245,7 +245,7 @@ private void AssemblyLoadsDuringTaskRun(string additionalEventText)
string text2 = File.ReadAllText(Path.Combine(logFolder.Path, "logFile2.log"));
text2.ShouldNotContain(assemblyLoadedEventText);
text2.ShouldNotContain(additionalEventText);
RunnerUtilities.ExecMSBuild($"{logger.Parameters} -flp1:logfile={Path.Combine(logFolder.Path, "logFile3.log")};verbosity=diagnostic -flp2:logfile={Path.Combine(logFolder.Path, "logFile4.log")};verbosity=normal", out success);
RunnerUtilities.ExecMSBuild($"{_logFile} -flp1:logfile={Path.Combine(logFolder.Path, "logFile3.log")};verbosity=diagnostic -flp2:logfile={Path.Combine(logFolder.Path, "logFile4.log")};verbosity=normal", out success);
success.ShouldBeTrue();
text = File.ReadAllText(Path.Combine(logFolder.Path, "logFile3.log"));
text.ShouldContain(assemblyLoadedEventText);
Expand Down Expand Up @@ -438,22 +438,22 @@ public void SuppressCommandOutputForNonDiagVerbosity()
<Exec Command='echo a'/>
</Target>
</Project>";
BinaryLogger logger = new();
logger.Parameters = _logFile;


TransientTestFolder testFolder = env.CreateFolder(createFolder: true);

TransientTestFile projectFile1 = env.CreateFile(testFolder, "testProject01.proj", contents);
string consoleOutput1 = RunnerUtilities.ExecMSBuild($"{projectFile1.Path} -bl:{logger.Parameters} -verbosity:diag -nologo", out bool success1);
string consoleOutput1 = RunnerUtilities.ExecMSBuild($"{projectFile1.Path} -bl:{_logFile} -verbosity:diag -nologo", out bool success1);
success1.ShouldBeTrue();
var expected1 = $"-nologo -bl:{logger.Parameters} -verbosity:diag {projectFile1.Path}";
var expected1 = $"-nologo -bl:{_logFile} -verbosity:diag {projectFile1.Path}";
consoleOutput1.ShouldContain(expected1);

foreach (var verbosity in new string[] { "q", "m", "n", "d" })
{
TransientTestFile projectFile2 = env.CreateFile(testFolder, $"testProject_{verbosity}.proj", contents);
string consoleOutput2 = RunnerUtilities.ExecMSBuild($"{projectFile2.Path} -bl:{logger.Parameters} -verbosity:{verbosity} -nologo", out bool success2);
string consoleOutput2 = RunnerUtilities.ExecMSBuild($"{projectFile2.Path} -bl:{_logFile} -verbosity:{verbosity} -nologo", out bool success2);
success2.ShouldBeTrue();
var expected2 = $"-nologo -bl:{logger.Parameters} -verbosity:{verbosity} {projectFile2.Path}";
var expected2 = $"-nologo -bl:{_logFile} -verbosity:{verbosity} {projectFile2.Path}";
consoleOutput2.ShouldNotContain(expected2);
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ public void ProjectCacheByVsScenarioIgnoresSlnDisabledProjects()
currentBuildEnvironment.Mode,
currentBuildEnvironment.CurrentMSBuildExePath,
currentBuildEnvironment.RunningTests,
currentBuildEnvironment.RunningInMSBuildExe,
runningInVisualStudio: true,
visualStudioPath: currentBuildEnvironment.VisualStudioInstallRootDirectory));

Expand Down Expand Up @@ -674,6 +675,7 @@ public void DesignTimeBuildsDuringVsScenarioShouldDisableTheCache()
currentBuildEnvironment.Mode,
currentBuildEnvironment.CurrentMSBuildExePath,
currentBuildEnvironment.RunningTests,
currentBuildEnvironment.RunningInMSBuildExe,
runningInVisualStudio: true,
visualStudioPath: currentBuildEnvironment.VisualStudioInstallRootDirectory));

Expand Down Expand Up @@ -1440,6 +1442,7 @@ public void ParallelStressTestForVsScenario(bool useSynchronousLogging, bool dis
currentBuildEnvironment.Mode,
currentBuildEnvironment.CurrentMSBuildExePath,
currentBuildEnvironment.RunningTests,
currentBuildEnvironment.RunningInMSBuildExe,
runningInVisualStudio: true,
visualStudioPath: currentBuildEnvironment.VisualStudioInstallRootDirectory));

Expand Down
3 changes: 2 additions & 1 deletion src/Build/BackEnd/BuildManager/BuildManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,7 @@ internal void ExecuteSubmission(BuildSubmission submission, bool allowMainThread
_projectCacheService.InitializePluginsForVsScenario(
ProjectCacheDescriptors.Values,
resolvedConfiguration,
submission.BuildRequestData.TargetNames,
_executionCancellationTokenSource.Token);
}

Expand Down Expand Up @@ -1953,7 +1954,7 @@ private void ExecuteGraphBuildScheduler(GraphBuildSubmission submission)

if (submission.BuildRequestData.GraphBuildOptions.Build)
{
_projectCacheService.InitializePluginsForGraph(projectGraph, _executionCancellationTokenSource.Token);
_projectCacheService.InitializePluginsForGraph(projectGraph, submission.BuildRequestData.TargetNames, _executionCancellationTokenSource.Token);

var targetListTask = projectGraph.GetTargetLists(submission.BuildRequestData.TargetNames);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private ProjectLoggingContext(
List<string> targets,
string toolsVersion,
PropertyDictionary<ProjectPropertyInstance> projectProperties,
ItemDictionary<ProjectItemInstance> projectItems,
IItemDictionary<ProjectItemInstance> projectItems,
BuildEventContext parentBuildEventContext,
int evaluationId,
int projectContextId)
Expand Down
13 changes: 13 additions & 0 deletions src/Build/BackEnd/Components/ProjectCache/CacheContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using Microsoft.Build.FileSystem;
using Microsoft.Build.Graph;
Expand All @@ -22,12 +23,23 @@ public class CacheContext
public IReadOnlyCollection<ProjectGraphEntryPoint>? GraphEntryPoints { get; }
public string? MSBuildExePath { get; }
public MSBuildFileSystemBase FileSystem { get; }
public IReadOnlyCollection<string> RequestedTargets { get; }

public CacheContext(
IReadOnlyDictionary<string, string> pluginSettings,
MSBuildFileSystemBase fileSystem,
ProjectGraph? graph = null,
IReadOnlyCollection<ProjectGraphEntryPoint>? graphEntryPoints = null)
: this(pluginSettings, fileSystem, requestedTargets: Array.Empty<string>(), graph, graphEntryPoints)
{
}

public CacheContext(
IReadOnlyDictionary<string, string> pluginSettings,
MSBuildFileSystemBase fileSystem,
IReadOnlyCollection<string> requestedTargets,
ProjectGraph? graph = null,
IReadOnlyCollection<ProjectGraphEntryPoint>? graphEntryPoints = null)
{
ErrorUtilities.VerifyThrow(
(graph != null) ^ (graphEntryPoints != null),
Expand All @@ -38,6 +50,7 @@ public CacheContext(
GraphEntryPoints = graphEntryPoints;
MSBuildExePath = BuildEnvironmentHelper.Instance.CurrentMSBuildExePath;
FileSystem = fileSystem;
RequestedTargets = requestedTargets;
}
}
}
21 changes: 16 additions & 5 deletions src/Build/BackEnd/Components/ProjectCache/ProjectCacheService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ public ProjectCacheService(
/// <summary>
/// Optimization which frontloads plugin initialization since we have an entire graph.
/// </summary>
public void InitializePluginsForGraph(ProjectGraph projectGraph, CancellationToken cancellationToken)
public void InitializePluginsForGraph(
ProjectGraph projectGraph,
ICollection<string> requestedTargets,
CancellationToken cancellationToken)
{
EnsureNotDisposed();

Expand All @@ -111,7 +114,7 @@ public void InitializePluginsForGraph(ProjectGraph projectGraph, CancellationTok
foreach (ProjectCacheDescriptor projectCacheDescriptor in GetProjectCacheDescriptors(node.ProjectInstance))
{
// Intentionally fire-and-forget to asynchronously initialize the plugin. Any exceptions will bubble up later when querying.
_ = GetProjectCachePluginAsync(projectCacheDescriptor, projectGraph, buildRequestConfiguration: null, cancellationToken)
_ = GetProjectCachePluginAsync(projectCacheDescriptor, projectGraph, buildRequestConfiguration: null, requestedTargets, cancellationToken)
.ContinueWith(t => { }, TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnFaulted);
}
});
Expand All @@ -122,6 +125,7 @@ public void InitializePluginsForGraph(ProjectGraph projectGraph, CancellationTok
public void InitializePluginsForVsScenario(
IEnumerable<ProjectCacheDescriptor> projectCacheDescriptors,
BuildRequestConfiguration buildRequestConfiguration,
ICollection<string> requestedTargets,
CancellationToken cancellationToken)
{
EnsureNotDisposed();
Expand All @@ -144,7 +148,7 @@ public void InitializePluginsForVsScenario(
projectCacheDescriptor =>
{
// Intentionally fire-and-forget to asynchronously initialize the plugin. Any exceptions will bubble up later when querying.
_ = GetProjectCachePluginAsync(projectCacheDescriptor, projectGraph: null, buildRequestConfiguration, cancellationToken)
_ = GetProjectCachePluginAsync(projectCacheDescriptor, projectGraph: null, buildRequestConfiguration, requestedTargets, cancellationToken)
.ContinueWith(t => { }, TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnFaulted);
});
},
Expand All @@ -155,12 +159,13 @@ private Task<ProjectCachePlugin> GetProjectCachePluginAsync(
ProjectCacheDescriptor projectCacheDescriptor,
ProjectGraph? projectGraph,
BuildRequestConfiguration? buildRequestConfiguration,
ICollection<string> requestedTargets,
CancellationToken cancellationToken)
=> _projectCachePlugins.GetOrAdd(
projectCacheDescriptor,
// The use of Lazy is because ConcurrentDictionary doesn't guarantee the value factory executes only once if there are multiple simultaneous callers,
// so this ensures that CreateAndInitializePluginAsync is only called exactly once.
descriptor => new Lazy<Task<ProjectCachePlugin>>(() => CreateAndInitializePluginAsync(descriptor, projectGraph, buildRequestConfiguration, cancellationToken)))
descriptor => new Lazy<Task<ProjectCachePlugin>>(() => CreateAndInitializePluginAsync(descriptor, projectGraph, buildRequestConfiguration, requestedTargets, cancellationToken)))
.Value;

private IEnumerable<ProjectCacheDescriptor> GetProjectCacheDescriptors(ProjectInstance projectInstance)
Expand Down Expand Up @@ -189,6 +194,7 @@ private async Task<ProjectCachePlugin> CreateAndInitializePluginAsync(
ProjectCacheDescriptor projectCacheDescriptor,
ProjectGraph? projectGraph,
BuildRequestConfiguration? buildRequestConfiguration,
ICollection<string> requestedTargets,
CancellationToken cancellationToken)
{
BuildEventContext buildEventContext = BuildEventContext.Invalid;
Expand Down Expand Up @@ -241,6 +247,9 @@ private async Task<ProjectCachePlugin> CreateAndInitializePluginAsync(
? GetGraphEntryPoints(buildRequestConfiguration)
: null;

// In practice, the underlying type of the ICollection is a List<string> so attempt to cast first
IReadOnlyList<string> requestedTargetsList = requestedTargets as List<string> ?? requestedTargets.ToList();

_loggingService.LogComment(buildEventContext, MessageImportance.High, "LoadingProjectCachePlugin", pluginTypeName);
MSBuildEventSource.Log.ProjectCacheBeginBuildStart(pluginTypeName);

Expand All @@ -250,6 +259,7 @@ await pluginInstance.BeginBuildAsync(
new CacheContext(
projectCacheDescriptor.PluginSettings,
DefaultMSBuildFileSystem.Instance,
requestedTargetsList,
projectGraph,
graphEntryPoints),
pluginLogger,
Expand Down Expand Up @@ -517,7 +527,8 @@ private async Task<CacheResult> GetCacheResultAsync(BuildRequestData buildReques
continue;
}

ProjectCachePlugin plugin = await GetProjectCachePluginAsync(projectCacheDescriptor, projectGraph: null, buildRequestConfiguration, cancellationToken);
ICollection<string> requestedTargetsList = buildRequestConfiguration.RequestedTargets as ICollection<string> ?? buildRequestConfiguration.RequestedTargets.ToList();
ProjectCachePlugin plugin = await GetProjectCachePluginAsync(projectCacheDescriptor, projectGraph: null, buildRequestConfiguration, requestedTargetsList, cancellationToken);
try
{
// Rethrow any initialization exception.
Expand Down
Loading

0 comments on commit 26b5d33

Please sign in to comment.