Skip to content

Commit 9dd25ae

Browse files
authored
Simplify PackageRepository.FileCustom (#275)
Call the private File helper in FileCustom and remove a small amount of duplicate logic
1 parent 84ba234 commit 9dd25ae

File tree

1 file changed

+1
-17
lines changed

1 file changed

+1
-17
lines changed

src/Microsoft.Build.Utilities.ProjectCreation/PackageRepository.File.cs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,7 @@ public PackageRepository FileCustom(string relativePath, FileInfo sourceFileInfo
4444
throw new InvalidOperationException(Strings.ErrorWhenAddingLibraryRequiresPackage);
4545
}
4646

47-
FileInfo destinationFileInfo = new FileInfo(Path.Combine(LastPackage.Directory!, relativePath));
48-
49-
if (destinationFileInfo.Exists)
50-
{
51-
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Strings.ErrorFileAlreadyCreated, relativePath));
52-
}
53-
54-
if (destinationFileInfo.Directory == null)
55-
{
56-
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Strings.ErrorFilePathMustBeInADirectory, relativePath));
57-
}
58-
59-
destinationFileInfo.Directory.Create();
60-
61-
sourceFileInfo.CopyTo(destinationFileInfo.FullName);
62-
63-
return this;
47+
return File(relativePath, destinationFileInfo => sourceFileInfo.CopyTo(destinationFileInfo.FullName));
6448
}
6549

6650
private PackageRepository File(string relativePath, Action<FileInfo> writeAction)

0 commit comments

Comments
 (0)