Skip to content

Commit d5ac662

Browse files
authored
Resolve ide0040, ide0051, ide0052, ide0350 warnings (#11740)
1 parent 1c829aa commit d5ac662

34 files changed

+113
-176
lines changed

Diff for: src/Build/BackEnd/BuildManager/BuildManager.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2426,7 +2426,7 @@ private void HandleResourceRequest(int node, ResourceRequest request)
24262426
{
24272427
// Resource request requires a response and may be blocking. Our continuation is effectively a callback
24282428
// to be called once at least one core becomes available.
2429-
_scheduler!.RequestCores(request.GlobalRequestId, request.NumCores, request.IsBlocking).ContinueWith((Task<int> task) =>
2429+
_scheduler!.RequestCores(request.GlobalRequestId, request.NumCores, request.IsBlocking).ContinueWith((task) =>
24302430
{
24312431
var response = new ResourceResponse(request.GlobalRequestId, task.Result);
24322432
_nodeManager!.SendData(node, response);

Diff for: src/Build/BackEnd/Components/Communications/NodeProviderOutOfProcBase.cs

-17
Original file line numberDiff line numberDiff line change
@@ -881,23 +881,6 @@ public async Task WaitForExitAsync(ILoggingService loggingService)
881881
_process.KillTree(timeoutMilliseconds: 5000);
882882
}
883883

884-
#if FEATURE_APM
885-
/// <summary>
886-
/// Completes the asynchronous packet write to the node.
887-
/// </summary>
888-
private void PacketWriteComplete(IAsyncResult result)
889-
{
890-
try
891-
{
892-
_serverToClientStream.EndWrite(result);
893-
}
894-
catch (IOException)
895-
{
896-
// Do nothing here because any exception will be caught by the async read handler
897-
}
898-
}
899-
#endif
900-
901884
private bool ProcessHeaderBytesRead(int bytesRead)
902885
{
903886
if (bytesRead != _headerByte.Length)

Diff for: src/Build/BackEnd/Components/RequestBuilder/RequestBuilder.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ public int RequestCores(object monitorLockObject, int requestedCores, bool waitF
497497
// a queue of pending requests.
498498
ResourceResponse responseObject = null;
499499
using AutoResetEvent responseEvent = new AutoResetEvent(false);
500-
_pendingResourceRequests.Enqueue((ResourceResponse response) =>
500+
_pendingResourceRequests.Enqueue((response) =>
501501
{
502502
responseObject = response;
503503
responseEvent.Set();

Diff for: src/Build/BackEnd/Components/RequestBuilder/TargetEntry.cs

+19-34
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,6 @@ internal class TargetEntry : IEquatable<TargetEntry>
148148
/// </summary>
149149
private bool _isExecuting;
150150

151-
/// <summary>
152-
/// The current task builder.
153-
/// </summary>
154-
private ITaskBuilder _currentTaskBuilder;
155-
156151
/// <summary>
157152
/// The constructor.
158153
/// </summary>
@@ -816,46 +811,36 @@ private async ValueTask<WorkUnitResult> ProcessBucket(ITaskBuilder taskBuilder,
816811
WorkUnitActionCode finalActionCode = WorkUnitActionCode.Continue;
817812
WorkUnitResult lastResult = new WorkUnitResult(WorkUnitResultCode.Success, WorkUnitActionCode.Continue, null);
818813

819-
try
814+
int currentTask = 0;
815+
816+
// Walk through all of the tasks and execute them in order.
817+
for (; (currentTask < _target.Children.Count) && !_cancellationToken.IsCancellationRequested; ++currentTask)
820818
{
821-
// Grab the task builder so if cancel is called it will have something to operate on.
822-
_currentTaskBuilder = taskBuilder;
819+
ProjectTargetInstanceChild targetChildInstance = _target.Children[currentTask];
823820

824-
int currentTask = 0;
821+
// Execute the task.
822+
lastResult = await taskBuilder.ExecuteTask(targetLoggingContext, _requestEntry, _targetBuilderCallback, targetChildInstance, mode, lookupForInference, lookupForExecution, _cancellationToken);
825823

826-
// Walk through all of the tasks and execute them in order.
827-
for (; (currentTask < _target.Children.Count) && !_cancellationToken.IsCancellationRequested; ++currentTask)
824+
if (lastResult.ResultCode == WorkUnitResultCode.Failed)
828825
{
829-
ProjectTargetInstanceChild targetChildInstance = _target.Children[currentTask];
830-
831-
// Execute the task.
832-
lastResult = await taskBuilder.ExecuteTask(targetLoggingContext, _requestEntry, _targetBuilderCallback, targetChildInstance, mode, lookupForInference, lookupForExecution, _cancellationToken);
833-
834-
if (lastResult.ResultCode == WorkUnitResultCode.Failed)
835-
{
836-
aggregatedTaskResult = WorkUnitResultCode.Failed;
837-
}
838-
else if (lastResult.ResultCode == WorkUnitResultCode.Success && aggregatedTaskResult != WorkUnitResultCode.Failed)
839-
{
840-
aggregatedTaskResult = WorkUnitResultCode.Success;
841-
}
842-
843-
if (lastResult.ActionCode == WorkUnitActionCode.Stop)
844-
{
845-
finalActionCode = WorkUnitActionCode.Stop;
846-
break;
847-
}
826+
aggregatedTaskResult = WorkUnitResultCode.Failed;
827+
}
828+
else if (lastResult.ResultCode == WorkUnitResultCode.Success && aggregatedTaskResult != WorkUnitResultCode.Failed)
829+
{
830+
aggregatedTaskResult = WorkUnitResultCode.Success;
848831
}
849832

850-
if (_cancellationToken.IsCancellationRequested)
833+
if (lastResult.ActionCode == WorkUnitActionCode.Stop)
851834
{
852-
aggregatedTaskResult = WorkUnitResultCode.Canceled;
853835
finalActionCode = WorkUnitActionCode.Stop;
836+
break;
854837
}
855838
}
856-
finally
839+
840+
if (_cancellationToken.IsCancellationRequested)
857841
{
858-
_currentTaskBuilder = null;
842+
aggregatedTaskResult = WorkUnitResultCode.Canceled;
843+
finalActionCode = WorkUnitActionCode.Stop;
859844
}
860845

861846
return new WorkUnitResult(aggregatedTaskResult, finalActionCode, lastResult.Exception);

Diff for: src/Build/BackEnd/Components/Scheduler/Scheduler.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ public Task<int> RequestCores(int requestId, int requestedCores, bool waitForCor
579579
return Task.FromResult(0);
580580
}
581581

582-
Func<int, int> grantCores = (int availableCores) =>
582+
Func<int, int> grantCores = (availableCores) =>
583583
{
584584
int grantedCores = Math.Min(requestedCores, availableCores);
585585
if (grantedCores > 0)
@@ -599,7 +599,7 @@ public Task<int> RequestCores(int requestId, int requestedCores, bool waitForCor
599599
// We have no cores to grant at the moment, queue up the request.
600600
TaskCompletionSource<int> completionSource = new TaskCompletionSource<int>();
601601
_pendingRequestCoresCallbacks.Enqueue(completionSource);
602-
return completionSource.Task.ContinueWith((Task<int> task) => grantCores(task.Result), TaskContinuationOptions.ExecuteSynchronously);
602+
return completionSource.Task.ContinueWith((task) => grantCores(task.Result), TaskContinuationOptions.ExecuteSynchronously);
603603
}
604604
}
605605

Diff for: src/Build/BackEnd/Components/Scheduler/SchedulingPlan.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public void WritePlan(int submissionId, ILoggingService loggingService, BuildEve
111111
RecursiveAccumulateConfigurationTimes(rootRequest, accumulatedTimeByConfiguration);
112112

113113
List<KeyValuePair<int, double>> configurationsInOrder = new(accumulatedTimeByConfiguration);
114-
configurationsInOrder.Sort((KeyValuePair<int, double> l, KeyValuePair<int, double> r) => Comparer<int>.Default.Compare(l.Key, r.Key));
114+
configurationsInOrder.Sort((l, r) => Comparer<int>.Default.Compare(l.Key, r.Key));
115115
foreach (KeyValuePair<int, double> configuration in configurationsInOrder)
116116
{
117117
file.WriteLine(String.Format(CultureInfo.InvariantCulture, "{0} {1} {2}", configuration.Key, configuration.Value, _configCache[configuration.Key].ProjectFullPath));

Diff for: src/Build/BuildCheck/Infrastructure/BuildCheckBuildEventHandler.cs

+14-14
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,25 @@ internal BuildCheckBuildEventHandler(
2828

2929
_eventHandlersFull = new()
3030
{
31-
{ typeof(BuildSubmissionStartedEventArgs), (BuildEventArgs e) => HandleBuildSubmissionStartedEvent((BuildSubmissionStartedEventArgs)e) },
32-
{ typeof(ProjectEvaluationFinishedEventArgs), (BuildEventArgs e) => HandleProjectEvaluationFinishedEvent((ProjectEvaluationFinishedEventArgs)e) },
33-
{ typeof(ProjectEvaluationStartedEventArgs), (BuildEventArgs e) => HandleProjectEvaluationStartedEvent((ProjectEvaluationStartedEventArgs)e) },
34-
{ typeof(EnvironmentVariableReadEventArgs), (BuildEventArgs e) => HandleEnvironmentVariableReadEvent((EnvironmentVariableReadEventArgs)e) },
35-
{ typeof(ProjectStartedEventArgs), (BuildEventArgs e) => HandleProjectStartedRequest((ProjectStartedEventArgs)e) },
36-
{ typeof(ProjectFinishedEventArgs), (BuildEventArgs e) => HandleProjectFinishedRequest((ProjectFinishedEventArgs)e) },
37-
{ typeof(BuildCheckTracingEventArgs), (BuildEventArgs e) => HandleBuildCheckTracingEvent((BuildCheckTracingEventArgs)e) },
38-
{ typeof(BuildCheckAcquisitionEventArgs), (BuildEventArgs e) => HandleBuildCheckAcquisitionEvent((BuildCheckAcquisitionEventArgs)e) },
39-
{ typeof(TaskStartedEventArgs), (BuildEventArgs e) => HandleTaskStartedEvent((TaskStartedEventArgs)e) },
40-
{ typeof(TaskFinishedEventArgs), (BuildEventArgs e) => HandleTaskFinishedEvent((TaskFinishedEventArgs)e) },
41-
{ typeof(TaskParameterEventArgs), (BuildEventArgs e) => HandleTaskParameterEvent((TaskParameterEventArgs)e) },
42-
{ typeof(BuildFinishedEventArgs), (BuildEventArgs e) => HandleBuildFinishedEvent((BuildFinishedEventArgs)e) },
43-
{ typeof(ProjectImportedEventArgs), (BuildEventArgs e) => HandleProjectImportedEvent((ProjectImportedEventArgs)e) },
31+
{ typeof(BuildSubmissionStartedEventArgs), (e) => HandleBuildSubmissionStartedEvent((BuildSubmissionStartedEventArgs)e) },
32+
{ typeof(ProjectEvaluationFinishedEventArgs), (e) => HandleProjectEvaluationFinishedEvent((ProjectEvaluationFinishedEventArgs)e) },
33+
{ typeof(ProjectEvaluationStartedEventArgs), (e) => HandleProjectEvaluationStartedEvent((ProjectEvaluationStartedEventArgs)e) },
34+
{ typeof(EnvironmentVariableReadEventArgs), (e) => HandleEnvironmentVariableReadEvent((EnvironmentVariableReadEventArgs)e) },
35+
{ typeof(ProjectStartedEventArgs), (e) => HandleProjectStartedRequest((ProjectStartedEventArgs)e) },
36+
{ typeof(ProjectFinishedEventArgs), (e) => HandleProjectFinishedRequest((ProjectFinishedEventArgs)e) },
37+
{ typeof(BuildCheckTracingEventArgs), (e) => HandleBuildCheckTracingEvent((BuildCheckTracingEventArgs)e) },
38+
{ typeof(BuildCheckAcquisitionEventArgs), (e) => HandleBuildCheckAcquisitionEvent((BuildCheckAcquisitionEventArgs)e) },
39+
{ typeof(TaskStartedEventArgs), (e) => HandleTaskStartedEvent((TaskStartedEventArgs)e) },
40+
{ typeof(TaskFinishedEventArgs), (e) => HandleTaskFinishedEvent((TaskFinishedEventArgs)e) },
41+
{ typeof(TaskParameterEventArgs), (e) => HandleTaskParameterEvent((TaskParameterEventArgs)e) },
42+
{ typeof(BuildFinishedEventArgs), (e) => HandleBuildFinishedEvent((BuildFinishedEventArgs)e) },
43+
{ typeof(ProjectImportedEventArgs), (e) => HandleProjectImportedEvent((ProjectImportedEventArgs)e) },
4444
};
4545

4646
// During restore we'll wait only for restore to be done.
4747
_eventHandlersRestore = new()
4848
{
49-
{ typeof(BuildSubmissionStartedEventArgs), (BuildEventArgs e) => HandleBuildSubmissionStartedEvent((BuildSubmissionStartedEventArgs)e) },
49+
{ typeof(BuildSubmissionStartedEventArgs), (e) => HandleBuildSubmissionStartedEvent((BuildSubmissionStartedEventArgs)e) },
5050
};
5151

5252
_eventHandlers = _eventHandlersFull;

Diff for: src/Build/BuildCheck/Infrastructure/BuildCheckConnectorLogger.cs

-4
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,11 @@ namespace Microsoft.Build.Experimental.BuildCheck.Infrastructure;
1616
internal sealed class BuildCheckConnectorLogger : ILogger
1717
{
1818
private readonly BuildCheckBuildEventHandler _eventHandler;
19-
private readonly IBuildCheckManager _buildCheckManager;
20-
private readonly ICheckContextFactory _checkContextFactory;
2119

2220
internal BuildCheckConnectorLogger(
2321
ICheckContextFactory checkContextFactory,
2422
IBuildCheckManager buildCheckManager)
2523
{
26-
_buildCheckManager = buildCheckManager;
27-
_checkContextFactory = checkContextFactory;
2824
_eventHandler = new BuildCheckBuildEventHandler(checkContextFactory, buildCheckManager);
2925
}
3026

Diff for: src/Build/BuildCheck/OM/BuildCheckDataContext.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ public abstract class CheckData(string projectFilePath, int? projectConfiguratio
1616
{
1717
private string? _projectFileDirectory;
1818
// The id is going to be used in future revision
19-
#pragma warning disable CA1823
19+
#pragma warning disable CA1823, IDE0052
2020
private int? _projectConfigurationId = projectConfigurationId;
21-
#pragma warning restore CA1823
21+
#pragma warning restore CA1823, IDE0052
2222

2323
/// <summary>
2424
/// Full path to the project file being built.

Diff for: src/Build/Definition/Project.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3815,7 +3815,7 @@ internal void Initialize(IDictionary<string, string> globalProperties, string to
38153815

38163816
// Cause the project to be actually loaded into the collection, and register for
38173817
// rename notifications so we can subsequently update the collection.
3818-
_renameHandler = (string oldFullPath) => ProjectCollection.OnAfterRenameLoadedProject(oldFullPath, Owner);
3818+
_renameHandler = (oldFullPath) => ProjectCollection.OnAfterRenameLoadedProject(oldFullPath, Owner);
38193819

38203820
Xml.OnAfterProjectRename += _renameHandler;
38213821
Xml.OnProjectXmlChanged += ProjectRootElement_ProjectXmlChangedHandler;

Diff for: src/Build/Definition/ToolsetReader.cs

-6
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ namespace Microsoft.Build.Evaluation
2727
/// </summary>
2828
internal abstract class ToolsetReader
2929
{
30-
/// <summary>
31-
/// The global properties used to read the toolset.
32-
/// </summary>
33-
private PropertyDictionary<ProjectPropertyInstance> _globalProperties;
34-
3530
/// <summary>
3631
/// The environment properties used to read the toolset.
3732
/// </summary>
@@ -45,7 +40,6 @@ protected ToolsetReader(
4540
PropertyDictionary<ProjectPropertyInstance> globalProperties)
4641
{
4742
_environmentProperties = environmentProperties;
48-
_globalProperties = globalProperties;
4943
}
5044

5145
/// <summary>

Diff for: src/Build/Evaluation/LazyItemEvaluator.OrderedItemDataCollection.cs

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ internal Builder(ImmutableList<ItemData>.Builder listBuilder)
4141

4242
#region IEnumerable implementation
4343

44-
private ImmutableList<ItemData>.Enumerator GetEnumerator() => _listBuilder.GetEnumerator();
4544
IEnumerator<ItemData> IEnumerable<ItemData>.GetEnumerator() => _listBuilder.GetEnumerator();
4645

4746
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => _listBuilder.GetEnumerator();

Diff for: src/Build/Graph/GraphBuilder.cs

+2
Original file line numberDiff line numberDiff line change
@@ -662,8 +662,10 @@ public void AddOrUpdateEdge((ProjectGraphNode node, ProjectGraphNode reference)
662662
{
663663
ReferenceItems.AddOrUpdate(
664664
key,
665+
#pragma warning disable IDE0350
665666
addValueFactory: static ((ProjectGraphNode node, ProjectGraphNode reference) key, ProjectItemInstance referenceItem) => referenceItem,
666667
updateValueFactory: static ((ProjectGraphNode node, ProjectGraphNode reference) key, ProjectItemInstance existingItem, ProjectItemInstance newItem) =>
668+
#pragma warning restore IDE0350
667669
{
668670
string existingTargetsMetadata = existingItem.GetMetadataValue(ItemMetadataNames.ProjectReferenceTargetsMetadataName);
669671
string newTargetsMetadata = newItem.GetMetadataValue(ItemMetadataNames.ProjectReferenceTargetsMetadataName);

Diff for: src/Build/Instance/ImmutableProjectCollections/ImmutableItemDictionary.cs

-2
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,11 @@ public ICollection<T> GetItems(string itemType)
175175

176176
private sealed class ListConverter : ICollection<T>
177177
{
178-
private readonly string _itemType;
179178
private readonly ICollection<TCached> _list;
180179
private readonly Func<TCached, T?> _getInstance;
181180

182181
public ListConverter(string itemType, ICollection<TCached> list, Func<TCached, T?> getInstance)
183182
{
184-
_itemType = itemType;
185183
_list = list;
186184
_getInstance = getInstance;
187185
}

Diff for: src/Build/Instance/ProjectItemInstance.cs

+2
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,7 @@ public void ImportMetadata(IEnumerable<KeyValuePair<string, string>> metadata)
10851085
_directMetadata.ImportProperties(metadata.Select(kvp => new ProjectMetadataInstance(kvp.Key, kvp.Value, allowItemSpecModifiers: true)));
10861086
}
10871087

1088+
#if FEATURE_APPDOMAIN
10881089
/// <summary>
10891090
/// Used to return metadata from another AppDomain. Can't use yield return because the
10901091
/// generated state machine is not marked as [Serializable], so we need to allocate.
@@ -1106,6 +1107,7 @@ private IEnumerable<KeyValuePair<string, string>> EnumerateMetadataEager(ICopyOn
11061107
// Probably better to send the raw array across the wire even if it's another allocation.
11071108
return result.ToArray();
11081109
}
1110+
#endif
11091111

11101112
private IEnumerable<KeyValuePair<string, string>> EnumerateMetadata(ICopyOnWritePropertyDictionary<ProjectMetadataInstance> list)
11111113
{

Diff for: src/Build/Logging/ParallelLogger/ParallelConsoleLogger.cs

-16
Original file line numberDiff line numberDiff line change
@@ -1401,22 +1401,6 @@ private void WriteMessageAligned(string message, bool prefixAlreadyWritten, int
14011401
}
14021402
}
14031403

1404-
/// <summary>
1405-
/// Write message taking into account whether or not the prefix (timestamp and key) have already been written on the line
1406-
/// </summary>
1407-
private void WriteBasedOnPrefix(string nonNullMessage, bool prefixAlreadyWritten, int adjustedPrefixWidth)
1408-
{
1409-
if (prefixAlreadyWritten)
1410-
{
1411-
WriteHandler(nonNullMessage + Environment.NewLine);
1412-
}
1413-
else
1414-
{
1415-
// No prefix info has been written, indent the line to the proper location
1416-
WriteHandler(IndentString(nonNullMessage, adjustedPrefixWidth));
1417-
}
1418-
}
1419-
14201404
/// <summary>
14211405
/// Will display the target started event which was deferred until the first visible message for the target is ready to be displayed
14221406
/// </summary>

Diff for: src/MSBuild/MSBuildClientApp.cs

-23
Original file line numberDiff line numberDiff line change
@@ -97,28 +97,5 @@ public static MSBuildApp.ExitType Execute(
9797

9898
return MSBuildApp.ExitType.MSBuildClientFailure;
9999
}
100-
101-
// Copied from NodeProviderOutOfProcBase.cs
102-
#if RUNTIME_TYPE_NETCORE
103-
private static string? CurrentHost;
104-
private static string GetCurrentHost()
105-
{
106-
if (CurrentHost == null)
107-
{
108-
string dotnetExe = Path.Combine(FileUtilities.GetFolderAbove(BuildEnvironmentHelper.Instance.CurrentMSBuildToolsDirectory, 2),
109-
NativeMethodsShared.IsWindows ? "dotnet.exe" : "dotnet");
110-
if (File.Exists(dotnetExe))
111-
{
112-
CurrentHost = dotnetExe;
113-
}
114-
else
115-
{
116-
CurrentHost = EnvironmentUtilities.ProcessPath ?? throw new InvalidOperationException("Failed to retrieve process executable.");
117-
}
118-
}
119-
120-
return CurrentHost;
121-
}
122-
#endif
123100
}
124101
}

Diff for: src/MSBuild/XMake.cs

+2
Original file line numberDiff line numberDiff line change
@@ -4526,6 +4526,7 @@ private static void ReplayBinaryLog(
45264526
}
45274527
}
45284528

4529+
#if FEATURE_XML_SCHEMA_VALIDATION
45294530
/// <summary>
45304531
/// Figures out if the project needs to be validated against a schema.
45314532
/// </summary>
@@ -4546,6 +4547,7 @@ private static string ProcessValidateSwitch(string[] parameters)
45464547

45474548
return schemaFile;
45484549
}
4550+
#endif
45494551

45504552
/// <summary>
45514553
/// Given an invalid ToolsVersion string and the collection of valid toolsets,

Diff for: src/Shared/AssemblyNameExtension.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -989,8 +989,8 @@ public void Translate(ITranslator translator)
989989

990990
// TODO: consider some kind of protection against infinite loop during serialization, hint: pre serialize check for cycle in graph
991991
translator.TranslateHashSet(ref remappedFrom,
992-
(ITranslator t) => new AssemblyNameExtension(t),
993-
(int capacity) => CreateRemappedFrom());
992+
(t) => new AssemblyNameExtension(t),
993+
(capacity) => CreateRemappedFrom());
994994
}
995995
}
996996
}

0 commit comments

Comments
 (0)