From fe47e42e7dfb5a09d10f74075701cd974c0f723d Mon Sep 17 00:00:00 2001 From: jnm2 Date: Thu, 2 Jan 2020 22:11:13 -0500 Subject: [PATCH 1/2] Skip copying documentation file when target already exists --- .../AnnotatorBuildTask.cs | 9 ++++++++- .../WindowsErrorCode.cs | 13 +++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 TunnelVisionLabs.ReferenceAssemblyAnnotator/WindowsErrorCode.cs diff --git a/TunnelVisionLabs.ReferenceAssemblyAnnotator/AnnotatorBuildTask.cs b/TunnelVisionLabs.ReferenceAssemblyAnnotator/AnnotatorBuildTask.cs index 20f6c71..3258d0e 100644 --- a/TunnelVisionLabs.ReferenceAssemblyAnnotator/AnnotatorBuildTask.cs +++ b/TunnelVisionLabs.ReferenceAssemblyAnnotator/AnnotatorBuildTask.cs @@ -104,7 +104,14 @@ public override bool Execute() string targetDocumentation = Path.ChangeExtension(outputAssembly, ".xml"); if (File.Exists(sourceDocumentation)) { - File.Copy(sourceDocumentation, targetDocumentation); + try + { + File.Copy(sourceDocumentation, targetDocumentation); + } + catch (IOException ex) when ((WindowsErrorCode)ex.HResult == WindowsErrorCode.FileExists) + { + } + GeneratedDocumentationFiles = new[] { new TaskItem(targetDocumentation) }; } else diff --git a/TunnelVisionLabs.ReferenceAssemblyAnnotator/WindowsErrorCode.cs b/TunnelVisionLabs.ReferenceAssemblyAnnotator/WindowsErrorCode.cs new file mode 100644 index 0000000..64e8d7d --- /dev/null +++ b/TunnelVisionLabs.ReferenceAssemblyAnnotator/WindowsErrorCode.cs @@ -0,0 +1,13 @@ +// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +namespace TunnelVisionLabs.ReferenceAssemblyAnnotator +{ + internal enum WindowsErrorCode : ushort + { + /// + /// https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499-#error_file_exists + /// + FileExists = 80, + } +} From 890b1174b6546b3373c734c45d231f3b1289b753 Mon Sep 17 00:00:00 2001 From: Joseph Musser Date: Fri, 3 Jan 2020 13:11:52 -0500 Subject: [PATCH 2/2] Avoid letting an exception be thrown when possible Co-Authored-By: Sam Harwell --- .../AnnotatorBuildTask.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TunnelVisionLabs.ReferenceAssemblyAnnotator/AnnotatorBuildTask.cs b/TunnelVisionLabs.ReferenceAssemblyAnnotator/AnnotatorBuildTask.cs index 3258d0e..04bbdb6 100644 --- a/TunnelVisionLabs.ReferenceAssemblyAnnotator/AnnotatorBuildTask.cs +++ b/TunnelVisionLabs.ReferenceAssemblyAnnotator/AnnotatorBuildTask.cs @@ -102,7 +102,7 @@ public override bool Execute() string sourceDocumentation = Path.ChangeExtension(unannotatedReferenceAssembly, ".xml"); string targetDocumentation = Path.ChangeExtension(outputAssembly, ".xml"); - if (File.Exists(sourceDocumentation)) + if (File.Exists(sourceDocumentation) && !File.Exists(targetDocumentation)) { try {