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
15 changes: 2 additions & 13 deletions src/Tasks/Copy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -926,20 +926,9 @@ private bool DoCopyWithRetries(FileState sourceFileState, FileState destinationF
private static string GetLockedFileMessage(string file)
{
string message = string.Empty;

try
{
if (NativeMethodsShared.IsWindows && ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_4))
{
var processes = LockCheck.GetProcessesLockingFile(file);
message = !string.IsNullOrEmpty(processes)
? ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("Copy.FileLocked", processes)
: String.Empty;
}
}
catch (Exception)
if (NativeMethodsShared.IsWindows)
{
// Never throw if we can't get the processes locking the file.
message = LockCheck.GetLockedFileMessage(file);
}

return message;
Expand Down
8 changes: 7 additions & 1 deletion src/Tasks/GenerateManifestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,13 @@ private bool WriteManifest()
}
catch (Exception ex)
{
Log.LogErrorWithCodeFromResources("GenerateManifest.WriteOutputManifestFailed", OutputManifest.ItemSpec, ex.Message);
string lockedFileMessage = string.Empty;
if (NativeMethodsShared.IsWindows)
{
lockedFileMessage = LockCheck.GetLockedFileMessage(OutputManifest.ItemSpec);
}
Log.LogErrorWithCodeFromResources("GenerateManifest.WriteOutputManifestFailed", OutputManifest.ItemSpec, ex.Message, lockedFileMessage);

return false;
}

Expand Down
27 changes: 27 additions & 0 deletions src/Tasks/LockCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using Microsoft.Build.Framework;
using Microsoft.Build.Shared;

#nullable disable

Expand Down Expand Up @@ -244,6 +246,31 @@ internal static string GetProcessesLockingFile(string filePath)
return string.Join(", ", GetLockingProcessInfos(filePath).Select(p => $"{p.ApplicationName} ({p.ProcessId})"));
}

/// <summary>
/// Try to get a message to inform the user which processes have a lock on a given file.
/// </summary>
internal static string GetLockedFileMessage(string file)
{
string message = string.Empty;

try
{
if (ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_4))
{
var processes = GetProcessesLockingFile(file);
message = !string.IsNullOrEmpty(processes)
? ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("Task.FileLocked", processes)
: String.Empty;
}
}
catch (Exception)
{
// Never throw if we can't get the processes locking the file.
}

return message;
}

internal static IEnumerable<ProcessInfo> GetLockingProcessInfos(params string[] paths)
{
if (paths == null)
Expand Down
4 changes: 2 additions & 2 deletions src/Tasks/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@
<value>MSB3030: Could not copy the file "{0}" because it was not found.</value>
<comment>{StrBegin="MSB3030: "} LOCALIZATION: {0} is a number.</comment>
</data>
<data name="Copy.FileLocked">
<data name="Task.FileLocked">
<value>The file is locked by: "{0}"</value>
</data>

Expand Down Expand Up @@ -915,7 +915,7 @@
<comment>{StrBegin="MSB3183: "}</comment>
</data>
<data name="GenerateManifest.WriteOutputManifestFailed">
<value>MSB3173: Unable to write manifest '{0}'. {1}</value>
<value>MSB3173: Unable to write manifest '{0}'. {1} {2}</value>
<comment>{StrBegin="MSB3173: "}</comment>
</data>
<data name="GenerateManifest.InvalidRequestedExecutionLevel">
Expand Down
14 changes: 7 additions & 7 deletions src/Tasks/Resources/xlf/Strings.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions src/Tasks/Resources/xlf/Strings.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions src/Tasks/Resources/xlf/Strings.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions src/Tasks/Resources/xlf/Strings.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions src/Tasks/Resources/xlf/Strings.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions src/Tasks/Resources/xlf/Strings.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions src/Tasks/Resources/xlf/Strings.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading