diff --git a/Directory.Packages.props b/Directory.Packages.props index e787b62..676f884 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -19,6 +19,7 @@ + diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/BuildEngineTests.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/BuildEngineTests.cs index ae3e513..b7e111b 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/BuildEngineTests.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/BuildEngineTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/BuildOutputTests.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/BuildOutputTests.cs index e9ce09f..486591a 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/BuildOutputTests.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/BuildOutputTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -127,7 +127,7 @@ public void OverallResult(bool succeeded) [Fact] public void ResultsByProject() { - Dictionary projects = new Dictionary(StringComparer.OrdinalIgnoreCase) + Dictionary projects = new(StringComparer.OrdinalIgnoreCase) { { Path.Combine("DA920698", "E40D", "4D8F", "89D8", "B85D870C4214"), true }, { Path.Combine("53C78698", "F360", "491F", "8025", "B323782DD912"), false }, @@ -154,7 +154,7 @@ public void Warnings(string expectedMessage, string expectedCode) private BuildOutput GetProjectLoggerWithEvents(Action eventSourceActions) { - MockEventSource eventSource = new MockEventSource(); + MockEventSource eventSource = new(); BuildOutput buildOutput = BuildOutput.Create(); @@ -165,4 +165,4 @@ private BuildOutput GetProjectLoggerWithEvents(Action eventSour return buildOutput; } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/BuildTests.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/BuildTests.cs index a3a399a..2fa7f33 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/BuildTests.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/BuildTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -6,12 +6,12 @@ using Microsoft.Build.Execution; using Microsoft.Build.Framework; using Microsoft.Build.Logging; +using Microsoft.Build.Logging.StructuredLogger; using Shouldly; using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using Xunit; namespace Microsoft.Build.Utilities.ProjectCreation.UnitTests @@ -36,16 +36,88 @@ public void BasicBuild() result3.ShouldBeTrue(); } + [Fact] + public void BinaryLogContainsNuGetGeneratedFiles() + { + string binLogPath = Path.Combine(TestRootPath, "test.binlog"); + string projectPath = Path.Combine(TestRootPath, "ClassLibraryA", "ClassLibraryA.csproj"); + + using (PackageRepository.Create(TestRootPath) + .Package("PackageA", "1.0.0", out Package packageA) + .Library(TargetFramework)) + { + string projectExtensionsPath; + + using (ProjectCollection projectCollection = new ProjectCollection()) + { + projectCollection.RegisterLogger(new Logging.BinaryLogger + { + Parameters = $"LogFile={binLogPath}", + }); + + ProjectCreator.Templates.SdkCsproj( + path: projectPath, + targetFramework: TargetFramework, + projectCollection: projectCollection) + .ItemPackageReference(packageA) + .TryBuild(restore: true, out bool result, out BuildOutput buildOutput) + .TryGetPropertyValue("MSBuildProjectExtensionsPath", out projectExtensionsPath); + + result.ShouldBeTrue(buildOutput.GetConsoleLog()); + } + + Logging.StructuredLogger.Build binaryLog = BinaryLog.ReadBuild(binLogPath); + + binaryLog.SourceFiles.ShouldContain(i => i.FullPath.Equals(Path.Combine(projectExtensionsPath, "ClassLibraryA.csproj.nuget.g.props"))); + } + } + + [Fact] + public void BuildCanConsumePackageWithGeneratePathProperty() + { + string projectPath = Path.Combine(TestRootPath, "ClassLibraryA", "ClassLibraryA.csproj"); + + using (PackageRepository.Create(TestRootPath) + .Package("PackageB", "1.0", out Package packageB) + .Library(TargetFramework) + .Package("PackageA", "1.0.0", out Package packageA) + .Dependency(packageB, TargetFramework) + .Library(TargetFramework)) + { + string projectExtensionsPath; + + using ProjectCollection projectCollection = new ProjectCollection(); + + ProjectCreator.Templates.SdkCsproj( + path: projectPath, + targetFramework: TargetFramework, + projectCollection: projectCollection) + .ItemPackageReference( + packageA, + metadata: new Dictionary + { + ["GeneratePathProperty"] = bool.TrueString, + }) + .TryBuild(restore: true, out bool result, out BuildOutput buildOutput) + .TryGetPropertyValue("PkgPackageA", out string packagePath) + .TryGetPropertyValue("MSBuildProjectExtensionsPath", out projectExtensionsPath); + + result.ShouldBeTrue(buildOutput.GetConsoleLog()); + + packagePath.ShouldEndWith(Path.Combine(".nuget", "packages", "packagea", "1.0.0")); + } + } + [Fact] public void BuildOutputContainsOutOfProcMessages() { const int messageCount = 100; - List projects = new List(messageCount); + List projects = new(messageCount); for (int i = 0; i < messageCount; i++) { - FileInfo projectPath = new FileInfo(Path.Combine(TestRootPath, $"Project{i}", $"Project{i}.proj")); + FileInfo projectPath = new(Path.Combine(TestRootPath, $"Project{i}", $"Project{i}.proj")); projectPath.Directory!.Create(); @@ -112,7 +184,7 @@ public void BuildTargetOutputsTest() [Fact] public void BuildWithGlobalProperties() { - Dictionary globalProperties = new Dictionary + Dictionary globalProperties = new() { ["Property1"] = "D7BBABDFB2D142D3A75E0C1A33E33780", }; @@ -138,7 +210,7 @@ public void CanBuildLotsOfProjects() { int maxBuilds = Environment.ProcessorCount * 2; - List projects = new List(maxBuilds); + List projects = new(maxBuilds); for (int i = 0; i < maxBuilds; i++) { @@ -210,9 +282,9 @@ public void ProjectCollectionLoggersWork() string binLogPath = Path.Combine(TestRootPath, "test.binlog"); string fileLogPath = Path.Combine(TestRootPath, "test.log"); - using (ProjectCollection projectCollection = new ProjectCollection()) + using (ProjectCollection projectCollection = new()) { - projectCollection.RegisterLogger(new BinaryLogger + projectCollection.RegisterLogger(new Logging.BinaryLogger { Parameters = $"LogFile={binLogPath}", }); @@ -251,9 +323,9 @@ public void ProjectCollectionLoggersWorkWithRestore() string binLogPath = Path.Combine(TestRootPath, "test.binlog"); string fileLogPath = Path.Combine(TestRootPath, "test.log"); - using (ProjectCollection projectCollection = new ProjectCollection()) + using (ProjectCollection projectCollection = new()) { - projectCollection.RegisterLogger(new BinaryLogger + projectCollection.RegisterLogger(new Logging.BinaryLogger { Parameters = $"LogFile={binLogPath}", }); @@ -294,7 +366,7 @@ public void ProjectCollectionLoggersWorkWithRestore() [Fact] public void ProjectWithGlobalPropertiesUsedDuringBuild() { - ProjectCollection projectCollection = new ProjectCollection(new Dictionary + ProjectCollection projectCollection = new(new Dictionary { ["Property1"] = "F6EBAC88A10E453B9AF8FA656A574737", }); @@ -323,7 +395,7 @@ public void ProjectWithNoPathRestoreThrowsInvalidOperationException() [Fact] public void RestoreAndBuildUseDifferentGlobalPropertiesWhenGlobalPropertiesSpecified() { - Dictionary globalProperties = new Dictionary + Dictionary globalProperties = new() { ["Something"] = bool.TrueString, }; @@ -351,12 +423,12 @@ public void RestoreAndBuildUseDifferentGlobalPropertiesWhenGlobalPropertiesSpeci [Fact] public void RestoreAndBuildUseDifferentGlobalPropertiesWhenProjectCollectionSpecified() { - Dictionary globalProperties = new Dictionary + Dictionary globalProperties = new() { ["Something"] = bool.TrueString, }; - using ProjectCollection projectCollection = new ProjectCollection(globalProperties); + using ProjectCollection projectCollection = new(globalProperties); ProjectCreator.Create( path: GetTempFileName(".csproj"), @@ -397,7 +469,7 @@ public void RestoreTargetCanBeRun() [Fact] public void RestoreUsesGlobalPropertiesFromCreate() { - Dictionary globalProperties = new Dictionary + Dictionary globalProperties = new() { ["SomeGlobalProperty"] = "04BB4AFE8AE14B7A8E3511B5F2CD442B", }; @@ -416,4 +488,4 @@ public void RestoreUsesGlobalPropertiesFromCreate() buildOutput.MessageEvents.High.ShouldContain(i => i.Message == "04BB4AFE8AE14B7A8E3511B5F2CD442B" && i.Importance == MessageImportance.High, buildOutput.GetConsoleLog()); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/ChooseTests.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/ChooseTests.cs index 1fb5fab..5b40478 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/ChooseTests.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/ChooseTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -290,4 +290,4 @@ public void WhenPropertyThowsIfNoWhen() .ShouldBe("You must add a When before adding a When PropertyGroup."); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/ExtensibilityTests.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/ExtensibilityTests.cs index 83e7e1f..ae2e0c5 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/ExtensibilityTests.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/ExtensibilityTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -43,4 +43,4 @@ public void CustomTemplate() StringCompareShould.IgnoreLineEndings); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/ExtensionMethods.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/ExtensionMethods.cs index a3a4098..9dba285 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/ExtensionMethods.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/ExtensionMethods.cs @@ -1,10 +1,9 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. using Shouldly; using System.IO; -using System.Xml.Linq; namespace Microsoft.Build.Utilities.ProjectCreation.UnitTests { @@ -30,4 +29,4 @@ public static DirectoryInfo ShouldExist(this DirectoryInfo directoryInfo) return directoryInfo; } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/ImportTests.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/ImportTests.cs index ed248ae..a7de7bd 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/ImportTests.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/ImportTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -169,4 +169,4 @@ public void ImportWithConditionOnExistence() StringCompareShould.IgnoreLineEndings); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/ItemGroupTests.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/ItemGroupTests.cs index 049b8c2..8d616f0 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/ItemGroupTests.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/ItemGroupTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -55,4 +55,4 @@ public void ItemGroupSimple() StringCompareShould.IgnoreLineEndings); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/ItemTests.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/ItemTests.cs index 1fd916d..c5511f6 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/ItemTests.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/ItemTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -372,4 +372,4 @@ public void UpdateItem() StringCompareShould.IgnoreLineEndings); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/LegacyCsProjTests.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/LegacyCsProjTests.cs index 7a12f53..552dbeb 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/LegacyCsProjTests.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/LegacyCsProjTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/LinqTests.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/LinqTests.cs index 151c08d..3c21ce9 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/LinqTests.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/LinqTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -35,4 +35,4 @@ public void ForEachItems() StringCompareShould.IgnoreLineEndings); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/Microsoft.Build.Utilities.ProjectCreation.UnitTests.csproj b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/Microsoft.Build.Utilities.ProjectCreation.UnitTests.csproj index 76513a7..fbe4354 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/Microsoft.Build.Utilities.ProjectCreation.UnitTests.csproj +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/Microsoft.Build.Utilities.ProjectCreation.UnitTests.csproj @@ -8,6 +8,7 @@ + diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/MockEventSource.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/MockEventSource.cs index 634b87f..41d5e77 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/MockEventSource.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/MockEventSource.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -40,14 +40,14 @@ internal sealed class MockEventSource : IEventSource2 public void OnBuildFinished(bool succeeded, string? message = null, string? helpKeyword = null) { - BuildFinishedEventArgs args = new BuildFinishedEventArgs(message, helpKeyword, succeeded); + BuildFinishedEventArgs args = new(message, helpKeyword, succeeded); BuildFinished?.Invoke(this, args); OnAnyEventRaised(args); } public void OnErrorRaised(string message, string? code = null, string? file = null, int lineNumber = -1, int columnNumber = -1, int endLineNumber = -1, int endColumnNumber = -1, string? helpKeyword = null, string? senderName = null) { - BuildErrorEventArgs args = new BuildErrorEventArgs(null, code, file, lineNumber, columnNumber, endLineNumber, endColumnNumber, message, helpKeyword, senderName) + BuildErrorEventArgs args = new(null, code, file, lineNumber, columnNumber, endLineNumber, endColumnNumber, message, helpKeyword, senderName) { BuildEventContext = BuildEventContext.Invalid, }; @@ -58,7 +58,7 @@ public void OnErrorRaised(string message, string? code = null, string? file = nu public void OnMessageRaised(string message, MessageImportance importance = MessageImportance.Normal) { - BuildMessageEventArgs args = new BuildMessageEventArgs(message, null, null, importance) + BuildMessageEventArgs args = new(message, null, null, importance) { BuildEventContext = BuildEventContext.Invalid, }; @@ -69,7 +69,7 @@ public void OnMessageRaised(string message, MessageImportance importance = Messa public void OnProjectFinished(string projectFile, bool succeeded, string? message = null, string? helpKeyword = null) { - ProjectFinishedEventArgs args = new ProjectFinishedEventArgs(message, helpKeyword, projectFile, succeeded) + ProjectFinishedEventArgs args = new(message, helpKeyword, projectFile, succeeded) { BuildEventContext = BuildEventContext.Invalid, }; @@ -80,7 +80,7 @@ public void OnProjectFinished(string projectFile, bool succeeded, string? messag public void OnWarningRaised(string message, string? code = null, string? file = null, int lineNumber = -1, int columnNumber = -1, int endLineNumber = -1, int endColumnNumber = -1, string? helpKeyword = null, string? senderName = null) { - BuildWarningEventArgs args = new BuildWarningEventArgs(null, code, file, lineNumber, columnNumber, endLineNumber, endColumnNumber, message, helpKeyword, senderName) + BuildWarningEventArgs args = new(null, code, file, lineNumber, columnNumber, endLineNumber, endColumnNumber, message, helpKeyword, senderName) { BuildEventContext = BuildEventContext.Invalid, }; @@ -149,4 +149,4 @@ private void OnTelemetryLogged(TelemetryEventArgs e) TelemetryLogged?.Invoke(this, e); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/NuspecReaderTests.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/NuspecReaderTests.cs index fde770e..9e0aa25 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/NuspecReaderTests.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/NuspecReaderTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -26,7 +26,7 @@ public void LicenseExpressionIsNullForFileLicenses() "; - NuspecReader nuspec = new NuspecReader(contents); + NuspecReader nuspec = new(contents); nuspec.License.ShouldBe("LICENSE"); nuspec.LicenseExpression.ShouldBeNull(); @@ -53,10 +53,10 @@ public void ReaderCanParseKnownXmlNamespaces(string xmlns) "; - NuspecReader nuspec = new NuspecReader(contents); + NuspecReader nuspec = new(contents); nuspec.Id.ShouldBe("PackageL"); nuspec.Version.ShouldBe("16.4.60"); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageFeedTests/PackageFeedFileTests.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageFeedTests/PackageFeedFileTests.cs index c267318..d6c784b 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageFeedTests/PackageFeedFileTests.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageFeedTests/PackageFeedFileTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -55,7 +55,7 @@ public void FileCustom() { string fileName = $"{Guid.NewGuid():N}.txt"; - FileInfo sourceFileInfo = new FileInfo(Path.Combine(TestRootPath, fileName)); + FileInfo sourceFileInfo = new(Path.Combine(TestRootPath, fileName)); string relativePath = Path.Combine("tools", "net46", fileName); @@ -81,7 +81,7 @@ public void FileCustomDoesNotExist() { Should.Throw(() => { - FileInfo fileInfo = new FileInfo(Path.Combine(TestRootPath, "foo.txt")); + FileInfo fileInfo = new(Path.Combine(TestRootPath, "foo.txt")); PackageFeed.Create(FeedRootPath) .Package("PackageA", "1.0.0") @@ -162,4 +162,4 @@ private void VerifyContentFile(Package package, string relativePath, string expe } } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageFeedTests/PackageFeedLibraryTests.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageFeedTests/PackageFeedLibraryTests.cs index a8b81c1..44c34bd 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageFeedTests/PackageFeedLibraryTests.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageFeedTests/PackageFeedLibraryTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -117,4 +117,4 @@ private void ValidateAssembly(Package package, string filePath, string expectedA assembly.GetTypes().ShouldContain(i => string.Equals(i.FullName, expectedTypeFullName)); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageFeedTests/PackageFeedTemplatesTest.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageFeedTests/PackageFeedTemplatesTest.cs index 8421d70..2c96ff0 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageFeedTests/PackageFeedTemplatesTest.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageFeedTests/PackageFeedTemplatesTest.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -18,4 +18,4 @@ public void SinglePackageTemplate() package.Version.ShouldBe("1.0.0"); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageFeedTests/PackageFeedTestBase.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageFeedTests/PackageFeedTestBase.cs index a60252c..51ece2f 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageFeedTests/PackageFeedTestBase.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageFeedTests/PackageFeedTestBase.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -29,7 +29,7 @@ protected PackageFeedTestBase() return ReadFile(nupkg, filePath, (stream, archiveEntry) => { - using BinaryReader binaryReader = new BinaryReader(stream); + using BinaryReader binaryReader = new(stream); return binaryReader.ReadBytes((int)archiveEntry.Length); }); @@ -85,6 +85,11 @@ private protected NuspecReader GetNuspecReader(Package package) return new NuspecReader(GetNuspec(package)); } + private ZipArchive GetPackageArchive(string fullPath) + { + return new ZipArchive(File.OpenRead(fullPath), ZipArchiveMode.Read, leaveOpen: false); + } + private T? ReadFile(ZipArchive nupkg, string filePath, Func streamFunc) { ZipArchiveEntry? archiveEntry = nupkg.GetEntry(filePath); @@ -109,10 +114,5 @@ private T ReadFile(ZipArchive nupkg, Func fileFunc, Func? dependencies) = nuspec.DependencyGroups.ToList().ShouldHaveSingleItem(); + + targetFramework.ShouldBe("net45"); + + PackageDependency dependency = dependencies.ShouldHaveSingleItem(); + + dependency.Id.ShouldBe("PackageB"); + dependency.Version.ShouldBe("2.0.0"); + dependency.ExcludeAssets.ShouldBe("Build, Analyzers"); + } + [Fact] public void NuspecXmlSerializesCorrectly() { @@ -79,41 +114,6 @@ public void NuspecXmlSerializesCorrectly() StringCompareShould.IgnoreLineEndings); } - [Fact] - public void BasicPackageWithDependency() - { - using PackageFeed packageFeed = PackageFeed.Create(FeedRootPath) - .Package("PackageA", "1.0.0", out _, "John Smith", "Custom Description", developmentDependency: true) - .Library("net45") - .Dependency("net45", "PackageB", "2.0.0") - .Save(); - - Package packageA = packageFeed.Packages.ShouldHaveSingleItem(); - - packageA.Author.ShouldBe("John Smith"); - packageA.Description.ShouldBe("Custom Description"); - packageA.DevelopmentDependency.ShouldBeTrue(); - packageA.Id.ShouldBe("PackageA"); - packageA.Version.ShouldBe("1.0.0"); - - NuspecReader nuspec = GetNuspecReader(packageA); - - nuspec.Authors.ShouldBe("John Smith"); - nuspec.Description.ShouldBe("Custom Description"); - nuspec.Id.ShouldBe("PackageA"); - nuspec.Version.ShouldBe("1.0.0"); - - (string? targetFramework, System.Collections.Generic.IEnumerable? dependencies) = nuspec.DependencyGroups.ToList().ShouldHaveSingleItem(); - - targetFramework.ShouldBe("net45"); - - PackageDependency dependency = dependencies.ShouldHaveSingleItem(); - - dependency.Id.ShouldBe("PackageB"); - dependency.Version.ShouldBe("2.0.0"); - dependency.ExcludeAssets.ShouldBe("Build, Analyzers"); - } - [Fact] public void RestoreCanConsumePackage() { @@ -133,4 +133,4 @@ public void RestoreCanConsumePackage() result.ShouldBeTrue(buildOutput.GetConsoleLog()); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageRepositoryTests/BuildLogicTests.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageRepositoryTests/BuildLogicTests.cs index d409e73..f30c1fc 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageRepositoryTests/BuildLogicTests.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageRepositoryTests/BuildLogicTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -110,4 +110,4 @@ public void BuildTransitiveTest() File.Exists(buildTransitiveTargetsProject.FullPath).ShouldBeTrue(); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageRepositoryTests/DependencyTests.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageRepositoryTests/DependencyTests.cs index b76f220..aae1f5b 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageRepositoryTests/DependencyTests.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageRepositoryTests/DependencyTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -15,72 +15,68 @@ public class DependencyTests : TestBase [Fact] public void CanAddDependenciesToMultipleGroups() { - using (PackageRepository packageRepository = PackageRepository.Create(TestRootPath) + using PackageRepository packageRepository = PackageRepository.Create(TestRootPath) .Package("PackageA", "1.0.0", out Package package) .Dependency("PackageB", "1.0.0", "net45") .Dependency("PackageB", "1.0.0", "net46") - .Dependency("PackageB", "1.0.0", "netstandard2.0")) - { - ValidatePackageDependencies( - packageRepository, - package, - new List<(string? TargetFramework, IEnumerable? Dependencies)> - { + .Dependency("PackageB", "1.0.0", "netstandard2.0"); + ValidatePackageDependencies( + packageRepository, + package, + new List<(string? TargetFramework, IEnumerable? Dependencies)> + { ( "net45", new List { - new PackageDependency("PackageB", "1.0.0", "Build, Analyzers"), + new("PackageB", "1.0.0", "Build, Analyzers"), }), ( "net46", new List { - new PackageDependency("PackageB", "1.0.0", "Build, Analyzers"), + new("PackageB", "1.0.0", "Build, Analyzers"), }), ( "netstandard2.0", new List { - new PackageDependency("PackageB", "1.0.0", "Build, Analyzers"), + new("PackageB", "1.0.0", "Build, Analyzers"), }), - }); - } + }); } [Fact] public void CanAddMultipleDependenciesToSameGroup() { - using (PackageRepository packageRepository = PackageRepository.Create(TestRootPath) + using PackageRepository packageRepository = PackageRepository.Create(TestRootPath) .Package("PackageA", "1.0.0", out Package package) .Dependency("PackageB", "1.0.0", "net45") .Dependency("PackageC", "1.1.0", "net45") - .Dependency("PackageD", "1.2.0", "net45")) - { - ValidatePackageDependencies( - packageRepository, - package, - new List<(string? TargetFramework, IEnumerable? Dependencies)> - { + .Dependency("PackageD", "1.2.0", "net45"); + ValidatePackageDependencies( + packageRepository, + package, + new List<(string? TargetFramework, IEnumerable? Dependencies)> + { ( "net45", new List { - new PackageDependency("PackageB", "1.0.0", "Build, Analyzers"), - new PackageDependency("PackageC", "1.1.0", "Build, Analyzers"), - new PackageDependency("PackageD", "1.2.0", "Build, Analyzers"), + new("PackageB", "1.0.0", "Build, Analyzers"), + new("PackageC", "1.1.0", "Build, Analyzers"), + new("PackageD", "1.2.0", "Build, Analyzers"), }), - }); - } + }); } private void ValidatePackageDependencies(PackageRepository packageRepository, Package package, IEnumerable<(string? TargetFramework, IEnumerable? Dependencies)> expectedDependencyGroups) { - FileInfo nuspecFile = new FileInfo(packageRepository.GetManifestFilePath(package.Id, package.Version)); + FileInfo nuspecFile = new(packageRepository.GetManifestFilePath(package.Id, package.Version)); nuspecFile.ShouldExist(); - NuspecReader nuspec = new NuspecReader(nuspecFile); + NuspecReader nuspec = new(nuspecFile); foreach ((string? targetFramework, IEnumerable? dependencies) in expectedDependencyGroups) { @@ -103,4 +99,4 @@ private void ValidatePackageDependencies(PackageRepository packageRepository, Pa } } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageRepositoryTests/FeedTests.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageRepositoryTests/FeedTests.cs index 31d8cd0..de6b29d 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageRepositoryTests/FeedTests.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageRepositoryTests/FeedTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. /* @@ -77,4 +77,4 @@ private IEnumerable EnumeratePackageSourceUris(PackageRepository package } } } -*/ \ No newline at end of file +*/ diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageRepositoryTests/FileTests.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageRepositoryTests/FileTests.cs index 1095b1a..2f98413 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageRepositoryTests/FileTests.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageRepositoryTests/FileTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -16,16 +16,14 @@ public void CustomFileTest() string relativePath = Path.Combine("test", "foo.txt"); const string contents = "798D159A4ADE45B9896EDE89FBA39C60"; - FileInfo sourceFileInfo = new FileInfo(Path.Combine(TestRootPath, "something")); + FileInfo sourceFileInfo = new(Path.Combine(TestRootPath, "something")); File.WriteAllText(sourceFileInfo.FullName, contents); - using (PackageRepository packageRepository = PackageRepository.Create(TestRootPath) + using PackageRepository packageRepository = PackageRepository.Create(TestRootPath) .Package("PackageA", "1.0.0", out Package packageA) - .FileCustom(relativePath, sourceFileInfo)) - { - VerifyFileContents(packageRepository, packageA, relativePath, contents); - } + .FileCustom(relativePath, sourceFileInfo); + VerifyFileContents(packageRepository, packageA, relativePath, contents); } [Fact] @@ -34,12 +32,10 @@ public void TextFileTest() string relativePath = Path.Combine("test", "foo.txt"); const string contents = "FF6B25B727E04D9980DE3B5D7AE0FB6E"; - using (PackageRepository packageRepository = PackageRepository.Create(TestRootPath) + using PackageRepository packageRepository = PackageRepository.Create(TestRootPath) .Package("PackageA", "1.0.0", out Package packageA) - .FileText(relativePath, contents)) - { - VerifyFileContents(packageRepository, packageA, relativePath, contents); - } + .FileText(relativePath, contents); + VerifyFileContents(packageRepository, packageA, relativePath, contents); } private void VerifyFileContents(PackageRepository packageRepository, Package package, string relativePath, string contents) @@ -53,4 +49,4 @@ private void VerifyFileContents(PackageRepository packageRepository, Package pac File.ReadAllText(file.FullName).ShouldBe(contents); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageRepositoryTests/LibraryTests.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageRepositoryTests/LibraryTests.cs index e5f0005..1209261 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageRepositoryTests/LibraryTests.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageRepositoryTests/LibraryTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -15,12 +15,10 @@ public class LibraryTests : TestBase [Fact] public void BasicLibrary() { - using (PackageRepository packageRepository = PackageRepository.Create(TestRootPath) + using PackageRepository packageRepository = PackageRepository.Create(TestRootPath) .Package("PackageA", "1.0.0", out Package packageA) - .Library("net45")) - { - VerifyAssembly(packageRepository, packageA, "net45"); - } + .Library("net45"); + VerifyAssembly(packageRepository, packageA, "net45"); } [Fact] @@ -28,38 +26,32 @@ public void LibraryWithVersion() { const string assemblyVersion = "2.3.4.5"; - using (PackageRepository packageRepository = PackageRepository.Create(TestRootPath) + using PackageRepository packageRepository = PackageRepository.Create(TestRootPath) .Package("PackageA", "1.0.0", out Package packageA) - .Library("net45", assemblyVersion: assemblyVersion)) - { - VerifyAssembly(packageRepository, packageA, "net45", version: "2.3.4.5"); - } + .Library("net45", assemblyVersion: assemblyVersion); + VerifyAssembly(packageRepository, packageA, "net45", version: "2.3.4.5"); } [Fact] public void MultipleLibrariesMultipleTargetFrameworks() { - using (PackageRepository packageRepository = PackageRepository.Create(TestRootPath) + using PackageRepository packageRepository = PackageRepository.Create(TestRootPath) .Package("PackageA", "1.0.0", out Package packageA) .Library("net45") - .Library("netstandard2.0")) - { - VerifyAssembly(packageRepository, packageA, "net45"); - VerifyAssembly(packageRepository, packageA, "netstandard2.0"); - } + .Library("netstandard2.0"); + VerifyAssembly(packageRepository, packageA, "net45"); + VerifyAssembly(packageRepository, packageA, "netstandard2.0"); } [Fact] public void MultipleLibrariesSameTargetFramework() { - using (PackageRepository packageRepository = PackageRepository.Create(TestRootPath) + using PackageRepository packageRepository = PackageRepository.Create(TestRootPath) .Package("PackageA", "1.0.0", out Package packageA) .Library("net45", filename: null) - .Library("net45", filename: "CustomAssembly.dll")) - { - VerifyAssembly(packageRepository, packageA, "net45"); - VerifyAssembly(packageRepository, packageA, "net45", assemblyFileName: "CustomAssembly.dll"); - } + .Library("net45", filename: "CustomAssembly.dll"); + VerifyAssembly(packageRepository, packageA, "net45"); + VerifyAssembly(packageRepository, packageA, "net45", assemblyFileName: "CustomAssembly.dll"); } private void VerifyAssembly(PackageRepository packageRepository, Package package, string targetFramework, string? assemblyFileName = null, string? version = null) diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageRepositoryTests/RepositoryTests.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageRepositoryTests/RepositoryTests.cs index 138b657..1b3e6b8 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageRepositoryTests/RepositoryTests.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PackageRepositoryTests/RepositoryTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -17,25 +17,23 @@ public class RepositoryTests : TestBase [Fact] public void BasicPackage() { - using (PackageRepository packageRepository = PackageRepository.Create(TestRootPath) + using PackageRepository packageRepository = PackageRepository.Create(TestRootPath) .Package("PackageD", "1.2.3-beta", out Package package) - .Library("net45")) - { - package.ShouldNotBeNull(); + .Library("net45"); + package.ShouldNotBeNull(); - package.Id.ShouldBe("PackageD"); - package.Version.ShouldBe("1.2.3-beta"); + package.Id.ShouldBe("PackageD"); + package.Version.ShouldBe("1.2.3-beta"); - FileInfo nuspecFileInfo = new FileInfo(packageRepository.GetManifestFilePath(package.Id, package.Version)).ShouldExist(); + FileInfo nuspecFileInfo = new FileInfo(packageRepository.GetManifestFilePath(package.Id, package.Version)).ShouldExist(); - NuspecReader nuspec = new NuspecReader(nuspecFileInfo); + NuspecReader nuspec = new(nuspecFileInfo); - nuspec.Authors.ShouldBe("UserA"); - nuspec.Description.ShouldBe("Description"); - nuspec.DevelopmentDependency.ShouldBeFalse(); - nuspec.Id.ShouldBe("PackageD"); - nuspec.RequireLicenseAcceptance.ShouldBeFalse(); - } + nuspec.Authors.ShouldBe("UserA"); + nuspec.Description.ShouldBe("Description"); + nuspec.DevelopmentDependency.ShouldBeFalse(); + nuspec.Id.ShouldBe("PackageD"); + nuspec.RequireLicenseAcceptance.ShouldBeFalse(); } [Fact] @@ -59,43 +57,40 @@ public void BuildCanConsumePackage() } [Fact] - public void LocalFeedsAreAddedCorrectly() + public void CanCreatePackageFromNupkg() { - DirectoryInfo feed1 = Directory.CreateDirectory(Path.Combine(TestRootPath, "Feed1")); - DirectoryInfo feed2 = Directory.CreateDirectory(Path.Combine(TestRootPath, "Feed2")); + string feedRootPath = Path.Combine(TestRootPath, "Feed"); + string targetFramework = "netstandard2.0"; + string contentFileText = "b7e41f28-0e3e-4824-90d3-025da699630e"; - using (PackageRepository.Create(TestRootPath, new Uri(feed1.FullName), new Uri(feed2.FullName))) + // Create a .nupkg to use as a source + using (PackageFeed.Create(feedRootPath) + .Package("PackageA", "1.2.3", out Package originalPackage, "John Smith", "Custom Description", developmentDependency: true) + .Library(targetFramework) + .ContentFileText("file.txt", contentFileText, targetFramework) + .Save()) { - FileInfo nuGetConfig = new FileInfo(Path.Combine(TestRootPath, "NuGet.config")); - - nuGetConfig.ShouldExist(); - - XDocument xmlDocument = XDocument.Load(nuGetConfig.FullName); - - XElement? packageSourcesElement = xmlDocument - .Element("configuration")? - .Element("packageSources"); - - packageSourcesElement.ShouldNotBeNull(); - - IEnumerator enumerator = packageSourcesElement.Elements().GetEnumerator(); + originalPackage.FullPath.ShouldNotBeNull(); - for (int i = 0; i < 3; i++) + using (PackageRepository.Create(TestRootPath) + .Package(new FileInfo(originalPackage.FullPath), out Package newPackage)) { - enumerator.MoveNext().ShouldBeTrue(); - - XElement element = enumerator.Current; + newPackage.Author.ShouldBe("John Smith"); + newPackage.Description.ShouldBe("Custom Description"); + newPackage.DevelopmentDependency.ShouldBeTrue(); + newPackage.Id.ShouldBe("PackageA"); + newPackage.Version.ShouldBe("1.2.3"); - if (i == 0) - { - element.Name.ShouldBe("clear"); - continue; - } + newPackage.FullPath.ShouldNotBeNullOrEmpty(); + DirectoryInfo? baseDir = new FileInfo(newPackage.FullPath).Directory; + baseDir.ShouldNotBeNull().ShouldExist(); - element.Name.ShouldBe("add"); - element.Attribute("key")?.Value.ShouldBe($"Local{i}"); + new FileInfo(Path.Combine(baseDir.FullName, "lib", targetFramework, $"{newPackage.Id}.dll")) + .ShouldExist(); - element.Attribute("value")?.Value.ShouldBe(i == 1 ? feed1.FullName : feed2.FullName); + new FileInfo(Path.Combine(baseDir.FullName, "contentFiles", "any", targetFramework, "file.txt")) + .ShouldExist() + .ReadAsText().ShouldBe(contentFileText); } } } @@ -103,7 +98,7 @@ public void LocalFeedsAreAddedCorrectly() [Fact] public void CanSetAllPackageProperties() { - using (PackageRepository packageRepository = PackageRepository.Create(TestRootPath) + using PackageRepository packageRepository = PackageRepository.Create(TestRootPath) .Package( id: "PackageD", version: "1.2.3", @@ -130,141 +125,138 @@ public void CanSetAllPackageProperties() serviceable: true, summary: "Summary of PackageD", tags: "Tag1 Tag2 Tag3", - title: "Title of PackageD")) + title: "Title of PackageD"); + package.ShouldNotBeNull(); + + package.Id.ShouldBe("PackageD"); + package.Version.ShouldBe("1.2.3"); + + FileInfo nuspecFileInfo = new FileInfo(packageRepository.GetManifestFilePath(package.Id, package.Version)).ShouldExist(); + + NuspecReader nuspec = new(nuspecFileInfo); + + nuspec.Authors.ShouldBe("UserA;UserB"); + nuspec.Copyright.ShouldBe("Copyright 2000"); + nuspec.Description.ShouldBe("Custom description"); + nuspec.DevelopmentDependency.ShouldBeTrue(); + nuspec.Icon.ShouldBe(Path.Combine("some", "icon.jpg")); + nuspec.IconUrl.ShouldBe("https://icon.invalid/url"); + nuspec.Id.ShouldBe("PackageD"); + nuspec.Language.ShouldBe("Pig latin"); + nuspec.License.ShouldBe("MIT"); + nuspec.LicenseExpression.ShouldBe("MIT"); + nuspec.LicenseType.ShouldBe("expression"); + nuspec.LicenseUrl.ShouldBe("https://license.invalid/url"); + nuspec.LicenseVersion.ShouldBe("1.0.0"); + nuspec.Owners.ShouldBe("Owner1;Owner2"); + nuspec.PackageTypes.ShouldBe(new[] { "Dependency", "DotnetCliTool" }); + nuspec.ProjectUrl.ShouldBe("https://project.invalid/url"); + nuspec.ReleaseNotes.ShouldBe("Release notes for PackageD"); + nuspec.RepositoryBranch.ShouldBe("Branch1000"); + nuspec.RepositoryCommit.ShouldBe("Commit14"); + nuspec.RepositoryType.ShouldBe("Git"); + nuspec.RepositoryUrl.ShouldBe("https://repository.invalid/url"); + nuspec.RequireLicenseAcceptance.ShouldBeTrue(); + nuspec.Serviceable.ShouldBeTrue(); + nuspec.Summary.ShouldBe("Summary of PackageD"); + nuspec.Tags.ShouldBe("Tag1 Tag2 Tag3"); + nuspec.Title.ShouldBe("Title of PackageD"); + } + + [Fact] + public void CanUseNuGetSdkResolver() + { + using ProjectCollection projectCollection = new(); + BuildOutput buildOutput = BuildOutput.Create(); + + projectCollection.RegisterLogger(buildOutput); + + using (PackageRepository.Create(TestRootPath) + .Package("Foo.Bar", "1.2.3", out Package package) + .FileText(Path.Combine("Sdk", "Sdk.props"), "") + .FileText(Path.Combine("Sdk", "Sdk.targets"), "")) { - package.ShouldNotBeNull(); - - package.Id.ShouldBe("PackageD"); - package.Version.ShouldBe("1.2.3"); - - FileInfo nuspecFileInfo = new FileInfo(packageRepository.GetManifestFilePath(package.Id, package.Version)).ShouldExist(); - - NuspecReader nuspec = new NuspecReader(nuspecFileInfo); - - nuspec.Authors.ShouldBe("UserA;UserB"); - nuspec.Copyright.ShouldBe("Copyright 2000"); - nuspec.Description.ShouldBe("Custom description"); - nuspec.DevelopmentDependency.ShouldBeTrue(); - nuspec.Icon.ShouldBe(Path.Combine("some", "icon.jpg")); - nuspec.IconUrl.ShouldBe("https://icon.invalid/url"); - nuspec.Id.ShouldBe("PackageD"); - nuspec.Language.ShouldBe("Pig latin"); - nuspec.License.ShouldBe("MIT"); - nuspec.LicenseExpression.ShouldBe("MIT"); - nuspec.LicenseType.ShouldBe("expression"); - nuspec.LicenseUrl.ShouldBe("https://license.invalid/url"); - nuspec.LicenseVersion.ShouldBe("1.0.0"); - nuspec.Owners.ShouldBe("Owner1;Owner2"); - nuspec.PackageTypes.ShouldBe(new[] { "Dependency", "DotnetCliTool" }); - nuspec.ProjectUrl.ShouldBe("https://project.invalid/url"); - nuspec.ReleaseNotes.ShouldBe("Release notes for PackageD"); - nuspec.RepositoryBranch.ShouldBe("Branch1000"); - nuspec.RepositoryCommit.ShouldBe("Commit14"); - nuspec.RepositoryType.ShouldBe("Git"); - nuspec.RepositoryUrl.ShouldBe("https://repository.invalid/url"); - nuspec.RequireLicenseAcceptance.ShouldBeTrue(); - nuspec.Serviceable.ShouldBeTrue(); - nuspec.Summary.ShouldBe("Summary of PackageD"); - nuspec.Tags.ShouldBe("Tag1 Tag2 Tag3"); - nuspec.Title.ShouldBe("Title of PackageD"); + ProjectCreator projectCreator = ProjectCreator + .Create( + sdk: $"{package.Id}/{package.Version}", + projectCollection: projectCollection) + .Save(GetTempFileName(".csproj")); + + try + { + Project unused = projectCreator.Project; + } + catch (Exception e) + { + throw new Exception(buildOutput.GetConsoleLog(), e); + } } } [Fact] public void LicenseExpressionPackagePropertiesCanBeNull() { - using (PackageRepository packageRepository = PackageRepository.Create(TestRootPath) + using PackageRepository packageRepository = PackageRepository.Create(TestRootPath) .Package( id: "PackageD", version: "1.2.3", out Package package, licenseUrl: "https://license.invalid/url", licenseExpression: null, - licenseVersion: null)) - { - package.ShouldNotBeNull(); + licenseVersion: null); + package.ShouldNotBeNull(); - FileInfo nuspecFileInfo = new FileInfo(packageRepository.GetManifestFilePath(package.Id, package.Version)).ShouldExist(); + FileInfo nuspecFileInfo = new FileInfo(packageRepository.GetManifestFilePath(package.Id, package.Version)).ShouldExist(); - NuspecReader nuspec = new NuspecReader(nuspecFileInfo); + NuspecReader nuspec = new(nuspecFileInfo); - nuspec.License.ShouldBeNull(); - nuspec.LicenseExpression.ShouldBeNull(); - nuspec.LicenseType.ShouldBeNull(); - nuspec.LicenseUrl.ShouldBe("https://license.invalid/url"); - nuspec.LicenseVersion.ShouldBeNull(); - } + nuspec.License.ShouldBeNull(); + nuspec.LicenseExpression.ShouldBeNull(); + nuspec.LicenseType.ShouldBeNull(); + nuspec.LicenseUrl.ShouldBe("https://license.invalid/url"); + nuspec.LicenseVersion.ShouldBeNull(); } [Fact] - public void CanUseNuGetSdkResolver() + public void LocalFeedsAreAddedCorrectly() { - using (ProjectCollection projectCollection = new ProjectCollection()) + DirectoryInfo feed1 = Directory.CreateDirectory(Path.Combine(TestRootPath, "Feed1")); + DirectoryInfo feed2 = Directory.CreateDirectory(Path.Combine(TestRootPath, "Feed2")); + + using (PackageRepository.Create(TestRootPath, new Uri(feed1.FullName), new Uri(feed2.FullName))) { - BuildOutput buildOutput = BuildOutput.Create(); + FileInfo nuGetConfig = new(Path.Combine(TestRootPath, "NuGet.config")); - projectCollection.RegisterLogger(buildOutput); + nuGetConfig.ShouldExist(); - using (PackageRepository.Create(TestRootPath) - .Package("Foo.Bar", "1.2.3", out Package package) - .FileText(Path.Combine("Sdk", "Sdk.props"), "") - .FileText(Path.Combine("Sdk", "Sdk.targets"), "")) - { - ProjectCreator projectCreator = ProjectCreator - .Create( - sdk: $"{package.Id}/{package.Version}", - projectCollection: projectCollection) - .Save(GetTempFileName(".csproj")); + XDocument xmlDocument = XDocument.Load(nuGetConfig.FullName); - try - { - Project unused = projectCreator.Project; - } - catch (Exception e) - { - throw new Exception(buildOutput.GetConsoleLog(), e); - } - } - } - } + XElement? packageSourcesElement = xmlDocument + .Element("configuration")? + .Element("packageSources"); - [Fact] - public void CanCreatePackageFromNupkg() - { - string feedRootPath = Path.Combine(TestRootPath, "Feed"); - string targetFramework = "netstandard2.0"; - string contentFileText = "b7e41f28-0e3e-4824-90d3-025da699630e"; + packageSourcesElement.ShouldNotBeNull(); - // Create a .nupkg to use as a source - using (PackageFeed.Create(feedRootPath) - .Package("PackageA", "1.2.3", out Package originalPackage, "John Smith", "Custom Description", developmentDependency: true) - .Library(targetFramework) - .ContentFileText("file.txt", contentFileText, targetFramework) - .Save()) - { - originalPackage.FullPath.ShouldNotBeNull(); + IEnumerator enumerator = packageSourcesElement.Elements().GetEnumerator(); - using (PackageRepository.Create(TestRootPath) - .Package(new FileInfo(originalPackage.FullPath), out Package newPackage)) + for (int i = 0; i < 3; i++) { - newPackage.Author.ShouldBe("John Smith"); - newPackage.Description.ShouldBe("Custom Description"); - newPackage.DevelopmentDependency.ShouldBeTrue(); - newPackage.Id.ShouldBe("PackageA"); - newPackage.Version.ShouldBe("1.2.3"); + enumerator.MoveNext().ShouldBeTrue(); - newPackage.FullPath.ShouldNotBeNullOrEmpty(); - DirectoryInfo? baseDir = new FileInfo(newPackage.FullPath).Directory; - baseDir.ShouldNotBeNull().ShouldExist(); + XElement element = enumerator.Current; - new FileInfo(Path.Combine(baseDir.FullName, "lib", targetFramework, $"{newPackage.Id}.dll")) - .ShouldExist(); + if (i == 0) + { + element.Name.ShouldBe("clear"); + continue; + } - new FileInfo(Path.Combine(baseDir.FullName, "contentFiles", "any", targetFramework, "file.txt")) - .ShouldExist() - .ReadAsText().ShouldBe(contentFileText); + element.Name.ShouldBe("add"); + element.Attribute("key")?.Value.ShouldBe($"Local{i}"); + + element.Attribute("value")?.Value.ShouldBe(i == 1 ? feed1.FullName : feed2.FullName); } } } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/ProjectTests.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/ProjectTests.cs index 65ae721..7940188 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/ProjectTests.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/ProjectTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -26,7 +26,7 @@ public void ProjectInstanceGetsCorrectObject() [Fact] public void ProjectIsReEvaluated() { - ProjectCollection projectCollection = new ProjectCollection(); + ProjectCollection projectCollection = new(); ProjectCreator creator = ProjectCreator.Create(projectCollection: projectCollection); @@ -59,7 +59,7 @@ public void ProjectWithGlobalProperties() [Fact] public void ProjectWithGlobalPropertiesFromProjectCollection() { - ProjectCollection projectCollection = new ProjectCollection(new Dictionary + ProjectCollection projectCollection = new(new Dictionary { ["Property1"] = "5DFF776EBCFF4173B0E14160C2191402", }); @@ -105,7 +105,7 @@ public void TryGetProjectWithGlobalProperties() [Fact] public void TryGetProjectWithProjectCollection() { - ProjectCollection expectedProjectCollection = new ProjectCollection(new Dictionary + ProjectCollection expectedProjectCollection = new(new Dictionary { ["Foo"] = "CF3478738DC04B3C9358FE0D23456BCD", }); @@ -128,4 +128,4 @@ public void TryGetProjectWithToolsVersion() .ShouldStartWith("The tools version \"624491E368E24CE38F51D9D620685809\" is unrecognized. Available tools versions are"); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/Properties/AssemblyInfo.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/Properties/AssemblyInfo.cs index ea6daed..ea457b6 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/Properties/AssemblyInfo.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/Properties/AssemblyInfo.cs @@ -1,8 +1,8 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. using System.Diagnostics.CodeAnalysis; [assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented", Justification = "Reviewed.")] -[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA0001:ElementsMustBeDocumented", Justification = "Reviewed.")] \ No newline at end of file +[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA0001:ElementsMustBeDocumented", Justification = "Reviewed.")] diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PropertyTests.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PropertyTests.cs index fd73579..7301646 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PropertyTests.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/PropertyTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -107,4 +107,4 @@ public void TryGetPropertyValueSimple() property2.ShouldBe("60F55FB14D2E44B2BA4EC91488D9FF8F"); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/SdkCsprojTests.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/SdkCsprojTests.cs index 123cad2..5b9ffb4 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/SdkCsprojTests.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/SdkCsprojTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -51,6 +51,18 @@ public void Default() StringCompareShould.IgnoreLineEndings); } + [Fact] + public void TargetFrameworksNullDoesNothing() + { + ProjectCreator.Templates.SdkCsproj( + targetFrameworks: null) + .Xml + .ShouldBe( + $@" +", + StringCompareShould.IgnoreLineEndings); + } + [Fact] public void TargetFrameworksWithMultipleValues() { @@ -85,20 +97,8 @@ public void TargetFrameworksWithSingleValue() 8A683D24C9CE489C804C79897BC1A44C -", - StringCompareShould.IgnoreLineEndings); - } - - [Fact] - public void TargetFrameworksNullDoesNothing() - { - ProjectCreator.Templates.SdkCsproj( - targetFrameworks: null) - .Xml - .ShouldBe( - $@" ", StringCompareShould.IgnoreLineEndings); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/SdkTests.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/SdkTests.cs index d3e8afb..28540cf 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/SdkTests.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/SdkTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -57,4 +57,4 @@ public void SdkWithVersion() StringCompareShould.IgnoreLineEndings); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/SolutionTests.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/SolutionTests.cs index 461675d..be8aac8 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/SolutionTests.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/SolutionTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/Suppressions.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/Suppressions.cs index 3e15c89..619190f 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/Suppressions.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/Suppressions.cs @@ -1,5 +1,5 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1652:Enable XML documentation output", Justification = "Unit tests.")] \ No newline at end of file +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1652:Enable XML documentation output", Justification = "Unit tests.")] diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/TargetTests.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/TargetTests.cs index ea16bcc..df03e85 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/TargetTests.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/TargetTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -139,4 +139,4 @@ public void TargetWithOnError() StringCompareShould.IgnoreLineEndings); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/TaskTests.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/TaskTests.cs index a8be425..318a69f 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/TaskTests.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/TaskTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -163,4 +163,4 @@ public void TaskWarningSimple() StringCompareShould.IgnoreLineEndings); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/TestBase.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/TestBase.cs index 66255ff..078da65 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/TestBase.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/TestBase.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/TestOnlyExtensionMethods.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/TestOnlyExtensionMethods.cs index 23e1633..716b5b9 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/TestOnlyExtensionMethods.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/TestOnlyExtensionMethods.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -20,4 +20,4 @@ public static ProjectCreator TestingOnlyTemplate(this ProjectCreatorTemplates te .Import(param1!, param2); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/UsingTaskTests.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/UsingTaskTests.cs index 4f216a3..e7b40b7 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/UsingTaskTests.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/UsingTaskTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -93,27 +93,6 @@ public void UsingTaskComplexParameters() StringCompareShould.IgnoreLineEndings); } - [Theory] - [InlineData("""Log.LogMessage(MessageImportance.High, "Hello from an inline task created by Roslyn!");""")] - [InlineData("""""")] - public void UsingTaskInlineFragmentSimple(string code) - { - ProjectCreator.Create(projectFileOptions: NewProjectFileOptions.None) - .UsingTaskRoslynCodeTaskFactory("MySample", code) - .Xml - .ShouldBe( - $""" - - - - - - - - """, - StringCompareShould.IgnoreLineEndings); - } - [Fact] public void UsingTaskInlineFragmentComplex() { @@ -165,6 +144,27 @@ public void UsingTaskInlineFragmentComplex() StringCompareShould.IgnoreLineEndings); } + [Theory] + [InlineData("""Log.LogMessage(MessageImportance.High, "Hello from an inline task created by Roslyn!");""")] + [InlineData("""""")] + public void UsingTaskInlineFragmentSimple(string code) + { + ProjectCreator.Create(projectFileOptions: NewProjectFileOptions.None) + .UsingTaskRoslynCodeTaskFactory("MySample", code) + .Xml + .ShouldBe( + $""" + + + + + + + + """, + StringCompareShould.IgnoreLineEndings); + } + [Fact] public void UsingTaskInlineSource() { @@ -235,4 +235,4 @@ public void UsingTaskThrowsIfParameterBeforeUsingTask() .Message.ShouldBe(Strings.ErrorUsingTaskParameterRequiresUsingTask); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/AssemblyCreator.cs b/src/Microsoft.Build.Utilities.ProjectCreation/AssemblyCreator.cs index 56b9ea8..6c1ff02 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/AssemblyCreator.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/AssemblyCreator.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -28,7 +28,7 @@ internal static class AssemblyCreator /// A that represents the assembly. public static MemoryStream Create(string name, string @namespace, string className, string assemblyVersion, string targetFramework) { - MemoryStream stream = new MemoryStream(); + MemoryStream stream = new(); Create(stream, name, @namespace, className, assemblyVersion, targetFramework); @@ -90,4 +90,4 @@ private static void CreateAssembly(Stream stream, string name, string code, IEnu } } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/BuildEngine.cs b/src/Microsoft.Build.Utilities.ProjectCreation/BuildEngine.cs index babb511..0601a4c 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/BuildEngine.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/BuildEngine.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -56,4 +56,4 @@ public bool BuildProjectFile(string projectFileName, string[] targetNames, IDict /// public void LogWarningEvent(BuildWarningEventArgs e) => Add(e); } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/BuildEventArgsCollection.cs b/src/Microsoft.Build.Utilities.ProjectCreation/BuildEventArgsCollection.cs index 5dc719b..c31a285 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/BuildEventArgsCollection.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/BuildEventArgsCollection.cs @@ -2,14 +2,11 @@ // // Licensed under the MIT license. -using Microsoft.Build.Evaluation; using Microsoft.Build.Framework; -using Microsoft.Build.Logging; using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; -using System.Text; namespace Microsoft.Build.Utilities.ProjectCreation { @@ -21,32 +18,32 @@ public abstract class BuildEventArgsCollection : IDisposable /// /// Stores all build events. /// - private readonly ConcurrentQueue _allEvents = new ConcurrentQueue(); + private readonly ConcurrentQueue _allEvents = new(); /// /// Stores the errors that were logged. /// - private readonly List _errorEvents = new List(); + private readonly List _errorEvents = new(); /// /// Stores the messages that were logged. /// - private readonly List _messageEvents = new List(50); + private readonly List _messageEvents = new(50); /// /// Stores the warnings that were logged. /// - private readonly List _warningEvents = new List(); + private readonly List _warningEvents = new(); /// - /// Stores the last console output. + /// Stores the parameters used to generate the last console output for cache invalidation. /// - private string? _lastConsoleOutput = null; + private (LoggerVerbosity Verbosity, bool ShowSummary, bool PerformanceSummary, bool ErrorsOnly, bool WarningsOnly, bool ShowItemAndPropertyList, bool ShowCommandLine, bool ShowTimestamp, bool ShowEventId) _lastConsoleLogParameters; /// - /// Stores the parameters used to generate the last console output for cache invalidation. + /// Stores the last console output. /// - private (LoggerVerbosity Verbosity, bool ShowSummary, bool PerformanceSummary, bool ErrorsOnly, bool WarningsOnly, bool ShowItemAndPropertyList, bool ShowCommandLine, bool ShowTimestamp, bool ShowEventId) _lastConsoleLogParameters; + private string? _lastConsoleOutput = null; /// /// Initializes a new instance of the class. @@ -162,4 +159,4 @@ protected void Add(BuildEventArgs buildEventArgs) } } } -} +} \ No newline at end of file diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/BuildHost.cs b/src/Microsoft.Build.Utilities.ProjectCreation/BuildHost.cs index 3be8a1a..85779a6 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/BuildHost.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/BuildHost.cs @@ -1,10 +1,9 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. using Microsoft.Build.Evaluation; using Microsoft.Build.Execution; -using Microsoft.Build.Framework; using System; using System.Collections.Generic; @@ -32,7 +31,7 @@ public static bool Restore( BuildRequestDataFlags buildRequestDataFlags = BuildRequestDataFlags.ClearCachesAfterBuild | BuildRequestDataFlags.SkipNonexistentTargets | BuildRequestDataFlags.IgnoreMissingEmptyAndInvalidImports; - return BuildProjectFromFullPath(projectFullPath, ["Restore"], restoreGlobalProperties, [.. projectCollection.Loggers, buildOutput], buildRequestDataFlags, out targetOutputs); + return BuildProjectFromFullPath(projectFullPath, ["Restore"], restoreGlobalProperties, buildRequestDataFlags, out targetOutputs); } public static bool TryBuild( @@ -100,7 +99,7 @@ private static bool Build( } } - return BuildProjectFromFullPath(projectFullPath, targets, globalProperties, [.. projectCollection.Loggers, buildOutput], BuildRequestDataFlags.None, out targetOutputs); + return BuildProjectFromFullPath(projectFullPath, targets, globalProperties, BuildRequestDataFlags.None, out targetOutputs); } private static bool Build( @@ -113,61 +112,32 @@ private static bool Build( { targetOutputs = null; - return BuildProjectFromProjectInstance(projectInstance, targets, globalProperties, [.. projectCollection.Loggers, buildOutput], BuildRequestDataFlags.None, out targetOutputs); - } - - private static bool BuildProjectFromProjectInstance( - ProjectInstance projectInstance, - string[] targets, - IDictionary? globalProperties, - IEnumerable loggers, - BuildRequestDataFlags buildRequestDataFlags, - out IDictionary? targetOutputs) - { - targetOutputs = null; - - BuildResult buildResult = BuildManagerHost.Build( - projectInstance, - targets, - globalProperties ?? EmptyGlobalProperties, - loggers, - buildRequestDataFlags); - - if (buildResult.Exception != null) - { - throw buildResult.Exception; - } - - targetOutputs = buildResult.ResultsByTarget; - - return buildResult.OverallResult == BuildResultCode.Success; + return BuildProjectFromProjectInstance(projectInstance, targets, globalProperties, BuildRequestDataFlags.None, out targetOutputs); } private static bool BuildProjectFromFullPath( string projectFullPath, string[] targets, IDictionary? globalProperties, - IEnumerable loggers, BuildRequestDataFlags buildRequestDataFlags, out IDictionary? targetOutputs) { targetOutputs = null; - BuildResult buildResult = BuildManagerHost.Build( + BuildResult? buildResult = BuildManagerHost.Build( projectFullPath, targets, GetGlobalProperties(globalProperties), - loggers, buildRequestDataFlags); - if (buildResult.Exception != null) + if (buildResult?.Exception != null) { throw buildResult.Exception; } - targetOutputs = buildResult.ResultsByTarget; + targetOutputs = buildResult?.ResultsByTarget; - return buildResult.OverallResult == BuildResultCode.Success; + return buildResult?.OverallResult == BuildResultCode.Success; #if NET8_0 IDictionary @@ -195,5 +165,30 @@ private static bool BuildProjectFromFullPath( #endif } } + + private static bool BuildProjectFromProjectInstance( + ProjectInstance projectInstance, + string[] targets, + IDictionary? globalProperties, + BuildRequestDataFlags buildRequestDataFlags, + out IDictionary? targetOutputs) + { + targetOutputs = null; + + BuildResult? buildResult = BuildManagerHost.Build( + projectInstance, + targets, + globalProperties ?? EmptyGlobalProperties, + buildRequestDataFlags); + + if (buildResult?.Exception != null) + { + throw buildResult.Exception; + } + + targetOutputs = buildResult?.ResultsByTarget; + + return buildResult?.OverallResult == BuildResultCode.Success; + } } } diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/BuildManagerHost.cs b/src/Microsoft.Build.Utilities.ProjectCreation/BuildManagerHost.cs index 4d8bb1f..9dac0a7 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/BuildManagerHost.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/BuildManagerHost.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -6,9 +6,6 @@ using Microsoft.Build.Framework; using System; using System.Collections.Generic; -using System.IO; -using System.Reflection; -using System.Runtime.InteropServices; namespace Microsoft.Build.Utilities.ProjectCreation { @@ -17,7 +14,21 @@ namespace Microsoft.Build.Utilities.ProjectCreation /// internal static class BuildManagerHost { - private static readonly object LockObject = new object(); + public static readonly object LockObject = new(); + + public static void BeginBuild(IEnumerable loggers) + { + BuildParameters buildParameters = new() + { + EnableNodeReuse = false, + MaxNodeCount = Environment.ProcessorCount, + ResetCaches = true, + Loggers = loggers, + LogTaskInputs = true, + }; + + BuildManager.DefaultBuildManager.BeginBuild(buildParameters); + } /// /// Executes a build for the specified project. @@ -25,7 +36,6 @@ internal static class BuildManagerHost /// The full path to the project. /// An optional list of targets to execute. /// An optional containing global properties to use when building. - /// An containing items to use. /// The to use. /// A containing details about the result of the build. public static BuildResult Build( @@ -36,10 +46,9 @@ public static BuildResult Build( #else IDictionary globalProperties, #endif - IEnumerable loggers, BuildRequestDataFlags buildRequestDataFlags) { - BuildRequestData buildRequestData = new BuildRequestData( + BuildRequestData buildRequestData = new( projectFullPath, #if NET8_0 globalProperties ?? new Dictionary(), @@ -51,7 +60,7 @@ public static BuildResult Build( hostServices: null, buildRequestDataFlags); - return Build(buildRequestData, loggers); + return Build(buildRequestData); } /// @@ -60,52 +69,36 @@ public static BuildResult Build( /// A representing the project. /// An optional list of targets to execute. /// An optional containing global properties to use when building. - /// An containing items to use. /// The to use. /// A containing details about the result of the build. - public static BuildResult Build(ProjectInstance projectInstance, string[] targets, IDictionary globalProperties, IEnumerable loggers, BuildRequestDataFlags buildRequestDataFlags) + public static BuildResult Build(ProjectInstance projectInstance, string[] targets, IDictionary globalProperties, BuildRequestDataFlags buildRequestDataFlags) { - BuildRequestData buildRequestData = new BuildRequestData( + BuildRequestData buildRequestData = new( projectInstance, targets ?? Array.Empty(), hostServices: null, buildRequestDataFlags); - return Build(buildRequestData, loggers); + return Build(buildRequestData); } - private static BuildResult Build(BuildRequestData buildRequestData, IEnumerable loggers) + public static void EndBuild() { - lock (LockObject) - { - BuildParameters buildParameters = new BuildParameters - { - EnableNodeReuse = false, - MaxNodeCount = Environment.ProcessorCount, - ResetCaches = true, - Loggers = loggers, - }; - - BuildManager.DefaultBuildManager.BeginBuild(buildParameters); - - try - { - BuildSubmission buildSubmission = BuildManager.DefaultBuildManager.PendBuildRequest(buildRequestData); + BuildManager.DefaultBuildManager.EndBuild(); + } - BuildResult buildResult = buildSubmission.Execute(); + private static BuildResult Build(BuildRequestData buildRequestData) + { + BuildSubmission buildSubmission = BuildManager.DefaultBuildManager.PendBuildRequest(buildRequestData); - if (buildResult.Exception != null) - { - throw buildResult.Exception; - } + BuildResult buildResult = buildSubmission.Execute(); - return buildResult; - } - finally - { - BuildManager.DefaultBuildManager.EndBuild(); - } + if (buildResult.Exception != null) + { + throw buildResult.Exception; } + + return buildResult; } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/BuildMessageCollection.cs b/src/Microsoft.Build.Utilities.ProjectCreation/BuildMessageCollection.cs index cbcf124..6c65004 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/BuildMessageCollection.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/BuildMessageCollection.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -56,4 +56,4 @@ IEnumerator IEnumerable.GetEnumerator() return GetEnumerator(); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/BuildMessageEventArgsCollection.cs b/src/Microsoft.Build.Utilities.ProjectCreation/BuildMessageEventArgsCollection.cs index e3e3cc2..1a096ee 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/BuildMessageEventArgsCollection.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/BuildMessageEventArgsCollection.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -56,4 +56,4 @@ IEnumerator IEnumerable.GetEnumerator() return GetEnumerator(); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/BuildOutput.cs b/src/Microsoft.Build.Utilities.ProjectCreation/BuildOutput.cs index 4303b42..f6d3f84 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/BuildOutput.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/BuildOutput.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -17,7 +17,7 @@ public sealed class BuildOutput : BuildEventArgsCollection, ILogger /// /// Stores the results by project. /// - private readonly ConcurrentDictionary _resultsByProject = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); + private readonly ConcurrentDictionary _resultsByProject = new(StringComparer.OrdinalIgnoreCase); /// /// Stores the that were logged when the build finished. @@ -104,4 +104,4 @@ private void OnProjectFinished(object sender, ProjectFinishedEventArgs e) } } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/ConsoleLoggerStringBuilder.cs b/src/Microsoft.Build.Utilities.ProjectCreation/ConsoleLoggerStringBuilder.cs index 050a720..a4da915 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/ConsoleLoggerStringBuilder.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/ConsoleLoggerStringBuilder.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -24,7 +24,7 @@ private ConsoleLoggerStringBuilder(StringBuilder stringBuilder) internal static string GetConsoleLogAsString(IReadOnlyCollection events, LoggerVerbosity verbosity = LoggerVerbosity.Normal, bool showSummary = true, bool performanceSummary = false, bool errorsOnly = false, bool warningsOnly = false, bool showItemAndPropertyList = true, bool showCommandLine = false, bool showTimestamp = false, bool showEventId = false) { - StringBuilder stringBuilder = new StringBuilder(events.Count * (int)verbosity * 100); + StringBuilder stringBuilder = new(events.Count * (int)verbosity * 100); ConsoleLoggerStringBuilder consoleLoggerStringBuilder = new(stringBuilder); @@ -97,9 +97,9 @@ private void OnWrite(string message) private string ReplayEventsAndGetLogString(IReadOnlyCollection events, LoggerVerbosity verbosity = LoggerVerbosity.Normal, bool showSummary = true, bool performanceSummary = false, bool errorsOnly = false, bool warningsOnly = false, bool showItemAndPropertyList = true, bool showCommandLine = false, bool showTimestamp = false, bool showEventId = false) { - ReplayEventSource eventSource = new ReplayEventSource(); + ReplayEventSource eventSource = new(); - ConsoleLogger logger = new ConsoleLogger(verbosity, OnWrite, OnColorSet, OnColorReset) + ConsoleLogger logger = new(verbosity, OnWrite, OnColorSet, OnColorReset) { Parameters = GetLoggerParameters(showSummary, performanceSummary, errorsOnly, warningsOnly, showItemAndPropertyList, showCommandLine, showTimestamp, showEventId), }; diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/ExtensionMethods.cs b/src/Microsoft.Build.Utilities.ProjectCreation/ExtensionMethods.cs index 9b2706a..bac9cf4 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/ExtensionMethods.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/ExtensionMethods.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -94,6 +94,12 @@ internal static ZipArchiveEntry CreateEntryFromStream(this ZipArchive archive, s return entry; } + internal static string ReadAsText(this FileInfo file) + { + using StreamReader reader = file.OpenText(); + return reader.ReadToEnd(); + } + internal static void WriteAttributeStringIfNotNull(this XmlWriter writer, string localName, string? value) { if (!string.IsNullOrEmpty(value)) @@ -125,11 +131,5 @@ internal static void WriteElementStringIfNotNull(this XmlWriter writer, string l writer.WriteElementString(localName, value.Value ? "true" : "false"); } } - - internal static string ReadAsText(this FileInfo file) - { - using StreamReader reader = file.OpenText(); - return reader.ReadToEnd(); - } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/MSBuildAssemblyResolver.cs b/src/Microsoft.Build.Utilities.ProjectCreation/MSBuildAssemblyResolver.cs index 4f33229..4ae4e6c 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/MSBuildAssemblyResolver.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/MSBuildAssemblyResolver.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -20,9 +20,9 @@ public static partial class MSBuildAssemblyResolver { private static readonly string[] AssemblyExtensions = { ".dll", ".exe" }; - private static readonly Dictionary> LoadedAssemblies = new Dictionary>(StringComparer.OrdinalIgnoreCase); + private static readonly Dictionary> LoadedAssemblies = new(StringComparer.OrdinalIgnoreCase); - private static readonly Lazy RegisterLazy = new Lazy(() => + private static readonly Lazy RegisterLazy = new(() => { Environment.SetEnvironmentVariable("MSBUILD_EXE_PATH", MSBuildExePath); Environment.SetEnvironmentVariable("MSBuildExtensionsPath", DotNetSdksPath); @@ -91,4 +91,4 @@ public static partial class MSBuildAssemblyResolver } } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/MSBuildAssemblyResolver.netcore.cs b/src/Microsoft.Build.Utilities.ProjectCreation/MSBuildAssemblyResolver.netcore.cs index 221de7b..9b1cb78 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/MSBuildAssemblyResolver.netcore.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/MSBuildAssemblyResolver.netcore.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -17,11 +17,11 @@ namespace Microsoft.Build.Utilities.ProjectCreation /// public static partial class MSBuildAssemblyResolver { - private static readonly Regex DotNetListSdksRegex = new Regex("^(?(?\\d+\\.\\d+\\.\\d{3,4})(?[-\\.\\w]*)) \\[(?.*)\\]\\r?$", RegexOptions.Multiline); + private static readonly Regex DotNetListSdksRegex = new("^(?(?\\d+\\.\\d+\\.\\d{3,4})(?[-\\.\\w]*)) \\[(?.*)\\]\\r?$", RegexOptions.Multiline); - private static readonly Lazy DotNetSdksPathLazy = new Lazy(GetDotNetBasePath); + private static readonly Lazy DotNetSdksPathLazy = new(GetDotNetBasePath); - private static readonly Lazy<(string[]? SearchPaths, string? MSBuildExePath)> MSBuildDirectoryLazy = new Lazy<(string[]?, string?)>( + private static readonly Lazy<(string[]? SearchPaths, string? MSBuildExePath)> MSBuildDirectoryLazy = new( () => { if (!string.IsNullOrWhiteSpace(DotNetSdksPath)) @@ -46,7 +46,7 @@ public static partial class MSBuildAssemblyResolver private static string? GetDotNetBasePath() { - using Process process = new Process + using Process process = new() { EnableRaisingEvents = true, StartInfo = new ProcessStartInfo @@ -114,4 +114,4 @@ public static partial class MSBuildAssemblyResolver } } } -#endif \ No newline at end of file +#endif diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/MSBuildAssemblyResolver.netframework.cs b/src/Microsoft.Build.Utilities.ProjectCreation/MSBuildAssemblyResolver.netframework.cs index e500b57..d021070 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/MSBuildAssemblyResolver.netframework.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/MSBuildAssemblyResolver.netframework.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -16,9 +16,9 @@ namespace Microsoft.Build.Utilities.ProjectCreation /// public static partial class MSBuildAssemblyResolver { - private static readonly Lazy DotNetSdksPathLazy = new Lazy(() => null); + private static readonly Lazy DotNetSdksPathLazy = new(() => null); - private static readonly Lazy<(string[]? SearchPaths, string? MSBuildExePath)> MSBuildDirectoryLazy = new Lazy<(string[]?, string?)>( + private static readonly Lazy<(string[]? SearchPaths, string? MSBuildExePath)> MSBuildDirectoryLazy = new( () => { string? msbuildBinPath = null; @@ -129,4 +129,4 @@ private static string GetMSBuildVersionDirectory(string version) } } } -#endif \ No newline at end of file +#endif diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/MSBuildTestBase.cs b/src/Microsoft.Build.Utilities.ProjectCreation/MSBuildTestBase.cs index 279015e..0e0ce84 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/MSBuildTestBase.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/MSBuildTestBase.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -18,4 +18,4 @@ static MSBuildTestBase() MSBuildAssemblyResolver.Register(); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/NuspecReader.cs b/src/Microsoft.Build.Utilities.ProjectCreation/NuspecReader.cs index 0184d1a..ece4785 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/NuspecReader.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/NuspecReader.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -15,7 +15,7 @@ namespace Microsoft.Build.Utilities.ProjectCreation internal class NuspecReader { private readonly XDocument _document; - private readonly XmlNamespaceManager _namespaceManager = new XmlNamespaceManager(new NameTable()); + private readonly XmlNamespaceManager _namespaceManager = new(new NameTable()); public NuspecReader(string contents) { @@ -139,6 +139,11 @@ private static string GetNamespace(XDocument document) return namespaces.Values.Single(); } + private string? GetAttribute(string elementName, string attributeName) + { + return _document.XPathSelectElement($"//ns:package/ns:metadata/ns:{elementName}", _namespaceManager)?.Attribute(attributeName)?.Value; + } + private IEnumerable GetContentFiles() { foreach (XElement file in _document.XPathSelectElements("//ns:package/ns:metadata/ns:contentFiles/ns:files", _namespaceManager)) @@ -171,10 +176,5 @@ private IEnumerable GetDependencies(IEnumerable dep { return _document.XPathSelectElement($"//ns:package/ns:metadata/ns:{name}", _namespaceManager)?.Value; } - - private string? GetAttribute(string elementName, string attributeName) - { - return _document.XPathSelectElement($"//ns:package/ns:metadata/ns:{elementName}", _namespaceManager)?.Attribute(attributeName)?.Value; - } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/Package.cs b/src/Microsoft.Build.Utilities.ProjectCreation/Package.cs index 75ee890..1063df6 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/Package.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/Package.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -15,13 +15,13 @@ namespace Microsoft.Build.Utilities.ProjectCreation /// public class Package : IComparer, IEqualityComparer, IComparable { - private readonly HashSet _contentFiles = new HashSet(); + private readonly HashSet _contentFiles = new(); - private readonly Dictionary> _dependencies = new Dictionary>(); + private readonly Dictionary> _dependencies = new(); - private readonly Dictionary> _files = new Dictionary>(StringComparer.OrdinalIgnoreCase); + private readonly Dictionary> _files = new(StringComparer.OrdinalIgnoreCase); - private readonly HashSet _targetFrameworks = new HashSet(); + private readonly HashSet _targetFrameworks = new(); /// /// Initializes a new instance of the class. @@ -557,4 +557,4 @@ internal void WriteNuspec(Stream stream) writer.Flush(); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/PackageContentFileEntry.cs b/src/Microsoft.Build.Utilities.ProjectCreation/PackageContentFileEntry.cs index 85c1162..2cf4b73 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/PackageContentFileEntry.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/PackageContentFileEntry.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -51,4 +51,4 @@ internal PackageContentFileEntry(string? buildAction = null, string? copyToOutpu /// public string? Include { get; set; } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/PackageDependency.cs b/src/Microsoft.Build.Utilities.ProjectCreation/PackageDependency.cs index d62e110..a60f0fb 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/PackageDependency.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/PackageDependency.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -137,4 +137,4 @@ private IncludeFlags GetIncludeFlags(string? assets) return includeFlags; } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.BuildLogic.cs b/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.BuildLogic.cs index 3e37748..b0fc44a 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.BuildLogic.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.BuildLogic.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.Dependency.cs b/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.Dependency.cs index 4495a3e..88cd4a0 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.Dependency.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.Dependency.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.File.cs b/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.File.cs index f2de9aa..bd7e553 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.File.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.File.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -80,4 +80,4 @@ private PackageFeed File(string relativePath, Func streamFunc) return this; } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.Items.cs b/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.Items.cs index 74a8307..867b296 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.Items.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.Items.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -24,4 +24,4 @@ public ProjectCreator ItemPackageReference(Package package, string? includeAsset return ItemPackageReference(package.Id, package.Version, includeAssets, excludeAssets, privateAssets, metadata, condition, label); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.Library.cs b/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.Library.cs index e34279f..e150ede 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.Library.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.Library.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.Linq.cs b/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.Linq.cs index 9efb106..22c679e 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.Linq.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.Linq.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -29,4 +29,4 @@ public PackageFeed ForEach(IEnumerable source, Action acti return this; } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.Package.cs b/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.Package.cs index e3b4d82..1143a79 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.Package.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.Package.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -9,7 +9,7 @@ namespace Microsoft.Build.Utilities.ProjectCreation { public partial class PackageFeed { - private readonly HashSet _packages = new HashSet(); + private readonly HashSet _packages = new(); private Package? _lastPackage; diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.Templates.cs b/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.Templates.cs index 50c816a..a23a192 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.Templates.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.Templates.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -11,4 +11,4 @@ public partial class PackageFeed /// public static PackageFeedTemplates Templates { get; } = new PackageFeedTemplates(); } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.cs b/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.cs index 7631ea0..267fc3f 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeed.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -23,12 +23,6 @@ private PackageFeed(DirectoryInfo rootPath) _rootPath.Create(); } - /// - /// Converts the current to a . - /// - /// The to convert. - public static implicit operator Uri(PackageFeed packageFeed) => new Uri(packageFeed._rootPath.FullName); - /// /// Creates a new instance at the specified path. /// @@ -61,6 +55,12 @@ public static PackageFeed Create(string rootPath) return new PackageFeed(Directory.CreateDirectory(rootPath)); } + /// + /// Converts the current to a . + /// + /// The to convert. + public static implicit operator Uri(PackageFeed packageFeed) => new(packageFeed._rootPath.FullName); + /// public void Dispose() { @@ -86,23 +86,17 @@ public PackageFeed Save() using (FileStream fileStream = System.IO.File.OpenWrite(package.FullPath)) { - using (ZipArchive nupkg = new ZipArchive(fileStream, ZipArchiveMode.Create)) + using ZipArchive nupkg = new(fileStream, ZipArchiveMode.Create); + foreach (KeyValuePair> file in package.Files) { - foreach (KeyValuePair> file in package.Files) - { - using (Stream? stream = file.Value()) - { - ZipArchiveEntry? entry = nupkg.CreateEntryFromStream(file.Key, stream); - } - } - - ZipArchiveEntry? nuspec = nupkg.CreateEntry($"{package.Id.ToLowerInvariant()}.nuspec"); - - using (Stream nuspecStream = nuspec.Open()) - { - package.WriteNuspec(nuspecStream); - } + using Stream? stream = file.Value(); + ZipArchiveEntry? entry = nupkg.CreateEntryFromStream(file.Key, stream); } + + ZipArchiveEntry? nuspec = nupkg.CreateEntry($"{package.Id.ToLowerInvariant()}.nuspec"); + + using Stream nuspecStream = nuspec.Open(); + package.WriteNuspec(nuspecStream); } package.Saved = true; @@ -111,4 +105,4 @@ public PackageFeed Save() return this; } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeedTemplates.cs b/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeedTemplates.cs index 3fabbe1..bf694b8 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeedTemplates.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/PackageFeedTemplates.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/PackageRepository.BuildLogic.cs b/src/Microsoft.Build.Utilities.ProjectCreation/PackageRepository.BuildLogic.cs index 7982f83..6ce26bf 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/PackageRepository.BuildLogic.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/PackageRepository.BuildLogic.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -312,4 +312,4 @@ private void CreateBuildFile(string extension, string folderName, Action - /// Adds a text file to the package. - /// - /// The relative path of the text file within the package. - /// The contents of the text file. - /// The current . - public PackageRepository FileText(string relativePath, string contents) - { - return File(relativePath, file => System.IO.File.WriteAllText(file.FullName, contents)); - } - /// /// Adds a custom file to the package. /// @@ -47,6 +36,17 @@ public PackageRepository FileCustom(string relativePath, FileInfo sourceFileInfo return File(relativePath, destinationFileInfo => sourceFileInfo.CopyTo(destinationFileInfo.FullName)); } + /// + /// Adds a text file to the package. + /// + /// The relative path of the text file within the package. + /// The contents of the text file. + /// The current . + public PackageRepository FileText(string relativePath, string contents) + { + return File(relativePath, file => System.IO.File.WriteAllText(file.FullName, contents)); + } + private PackageRepository File(string relativePath, Action writeAction) { if (LastPackage == null) @@ -54,7 +54,7 @@ private PackageRepository File(string relativePath, Action writeAction throw new InvalidOperationException(Strings.ErrorWhenAddingLibraryRequiresPackage); } - FileInfo fileInfo = new FileInfo(Path.Combine(LastPackage.Directory!, relativePath)); + FileInfo fileInfo = new(Path.Combine(LastPackage.Directory!, relativePath)); if (fileInfo.Exists) { @@ -73,4 +73,4 @@ private PackageRepository File(string relativePath, Action writeAction return this; } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/PackageRepository.Library.cs b/src/Microsoft.Build.Utilities.ProjectCreation/PackageRepository.Library.cs index 3f5e340..4762796 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/PackageRepository.Library.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/PackageRepository.Library.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -48,10 +48,8 @@ public PackageRepository Library(string targetFramework, string? filename = null { fileInfo.Directory!.Create(); - using (Stream stream = System.IO.File.Create(fileInfo.FullName)) - { - AssemblyCreator.Create(stream, Path.GetFileNameWithoutExtension(filename), @namespace!, className!, assemblyVersion, targetFramework); - } + using Stream stream = System.IO.File.Create(fileInfo.FullName); + AssemblyCreator.Create(stream, Path.GetFileNameWithoutExtension(filename), @namespace!, className!, assemblyVersion, targetFramework); }); } } diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/PackageRepository.Package.cs b/src/Microsoft.Build.Utilities.ProjectCreation/PackageRepository.Package.cs index 044ac47..f346b61 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/PackageRepository.Package.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/PackageRepository.Package.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -12,7 +12,7 @@ namespace Microsoft.Build.Utilities.ProjectCreation { public partial class PackageRepository { - private readonly HashSet _packages = new HashSet(); + private readonly HashSet _packages = new(); /// /// Gets the current packages in the repository. @@ -61,12 +61,12 @@ public PackageRepository Package(FileInfo nupkg, out Package package) throw new FileNotFoundException("The specified .nupkg file does not exist", nupkg.FullName); } - using ZipArchive zip = new ZipArchive(System.IO.File.OpenRead(nupkg.FullName), ZipArchiveMode.Read, leaveOpen: false); + using ZipArchive zip = new(System.IO.File.OpenRead(nupkg.FullName), ZipArchiveMode.Read, leaveOpen: false); ZipArchiveEntry? nuspecEntry = zip.Entries.SingleOrDefault(entry => entry.Name.EndsWith(".nuspec", StringComparison.OrdinalIgnoreCase)) ?? throw new InvalidOperationException($"The .nupkg file '{nupkg.FullName}' does not contain a .nuspec file"); - using StreamReader nuspecStream = new StreamReader(nuspecEntry.Open()); + using StreamReader nuspecStream = new(nuspecEntry.Open()); - NuspecReader reader = new NuspecReader(nuspecStream.ReadToEnd()); + NuspecReader reader = new(nuspecStream.ReadToEnd()); Package( id: reader.Id ?? throw new InvalidOperationException($"The .nupkg file '{nupkg.FullName}' does not contain an ID"), @@ -277,7 +277,7 @@ public PackageRepository Package( using (TextWriter? writer = System.IO.File.CreateText(Path.Combine(directory.FullName, ".nupkg.metadata"))) { writer.WriteLine( -@"{ +@"{ ""version"": 2, ""contentHash"": """" }"); @@ -290,11 +290,9 @@ private void SavePackageManifest() { if (LastPackage != null) { - using (Stream? stream = System.IO.File.OpenWrite(GetManifestFilePath(LastPackage.Id, LastPackage.Version))) - { - LastPackage.WriteNuspec(stream); - } + using Stream? stream = System.IO.File.OpenWrite(GetManifestFilePath(LastPackage.Id, LastPackage.Version)); + LastPackage.WriteNuspec(stream); } } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/PackageRepository.cs b/src/Microsoft.Build.Utilities.ProjectCreation/PackageRepository.cs index c2e6102..1d5fc3f 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/PackageRepository.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/PackageRepository.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -25,45 +25,43 @@ private PackageRepository(string rootPath, IEnumerable? feeds = null) NuGetConfigPath = Path.Combine(rootPath, "NuGet.config"); - XmlWriterSettings settings = new XmlWriterSettings + XmlWriterSettings settings = new() { Indent = true, OmitXmlDeclaration = true, }; - using (XmlWriter? writer = XmlWriter.Create(NuGetConfigPath, settings)) - { - writer.WriteStartElement("configuration"); + using XmlWriter? writer = XmlWriter.Create(NuGetConfigPath, settings); + writer.WriteStartElement("configuration"); - writer.WriteStartElement("config"); - writer.WriteStartElement("add"); - writer.WriteAttributeString("key", "globalPackagesFolder"); - writer.WriteAttributeString("value", GlobalPackagesFolder); - writer.WriteEndElement(); // - writer.WriteEndElement(); // + writer.WriteStartElement("config"); + writer.WriteStartElement("add"); + writer.WriteAttributeString("key", "globalPackagesFolder"); + writer.WriteAttributeString("value", GlobalPackagesFolder); + writer.WriteEndElement(); // + writer.WriteEndElement(); // - writer.WriteStartElement("packageSources"); - writer.WriteElementString("clear", string.Empty); + writer.WriteStartElement("packageSources"); + writer.WriteElementString("clear", string.Empty); - if (feeds != null) - { - int i = 1; + if (feeds != null) + { + int i = 1; - foreach (Uri? feed in feeds.Where(i => i != null)) - { - string feedName = feed.IsFile ? $"Local{i++}" : feed.Host; + foreach (Uri? feed in feeds.Where(i => i != null)) + { + string feedName = feed.IsFile ? $"Local{i++}" : feed.Host; - writer.WriteStartElement("add"); - writer.WriteAttributeString("key", feedName); - writer.WriteAttributeString("value", feed.IsFile ? feed.LocalPath : feed.ToString()); - writer.WriteEndElement(); - } + writer.WriteStartElement("add"); + writer.WriteAttributeString("key", feedName); + writer.WriteAttributeString("value", feed.IsFile ? feed.LocalPath : feed.ToString()); + writer.WriteEndElement(); } + } - writer.WriteEndElement(); // + writer.WriteEndElement(); // - writer.WriteEndElement(); // - } + writer.WriteEndElement(); // } /// @@ -82,7 +80,7 @@ private PackageRepository(string rootPath, IEnumerable? feeds = null) /// The root directory to create a package repository directory in. /// Optional feeds to include in the configuration. /// A object that is used to construct an NuGet package repository. - public static PackageRepository Create(string rootPath, params Uri[] feeds) => new PackageRepository(rootPath, feeds); + public static PackageRepository Create(string rootPath, params Uri[] feeds) => new(rootPath, feeds); /// public void Dispose() @@ -90,4 +88,4 @@ public void Dispose() Environment.SetEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesGlobalFolderBackup); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Build.cs b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Build.cs index a1779a4..e759d28 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Build.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Build.cs @@ -1,10 +1,10 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. using Microsoft.Build.Evaluation; using Microsoft.Build.Execution; -using System; +using Microsoft.Build.Framework; using System.Collections.Generic; using System.Linq; @@ -57,17 +57,9 @@ public ProjectCreator TryBuild(bool restore, string target, out bool result) /// The current . public ProjectCreator TryBuild(bool restore, string target, IDictionary? globalProperties, out bool result) { - if (restore) - { - TryRestore(out result); - - if (!result) - { - return this; - } - } + BuildOutput buildOutput = BuildOutput.Create(); - result = Build([target], globalProperties, out _, out _); + result = Build(restore: false, [target], globalProperties, buildOutput, out _); return this; } @@ -169,17 +161,9 @@ public ProjectCreator TryBuild(bool restore, out bool result) /// The current . public ProjectCreator TryBuild(bool restore, IDictionary? globalProperties, out bool result) { - if (restore) - { - TryRestore(out result); + BuildOutput buildOutput = BuildOutput.Create(); - if (!result) - { - return this; - } - } - - result = Build(null, globalProperties: globalProperties, out _, out _); + result = Build(restore: false, targets: null, globalProperties, buildOutput, out _); return this; } @@ -476,7 +460,21 @@ public ProjectCreator TryRestore(IDictionary? globalProperties, { buildOutput = BuildOutput.Create(); - result = Restore(globalProperties, buildOutput, out targetOutputs); + IEnumerable loggers = [.. ProjectCollection.Loggers, buildOutput]; + + lock (BuildManagerHost.LockObject) + { + BuildManagerHost.BeginBuild(loggers); + + try + { + result = Restore(globalProperties, buildOutput, out targetOutputs); + } + finally + { + BuildManagerHost.EndBuild(); + } + } return this; } @@ -492,32 +490,44 @@ private bool Build(bool restore, string[]? targets, IDictionary? { targetOutputs = null; - if (restore) + lock (BuildManagerHost.LockObject) { - if (!Restore(globalProperties, buildOutput, out targetOutputs)) + BuildManagerHost.BeginBuild([.. ProjectCollection.Loggers, buildOutput]); + + try { - return false; - } - } + if (restore) + { + if (!Restore(globalProperties, buildOutput, out targetOutputs)) + { + return false; + } + } - ProjectInstance projectInstance; + ProjectInstance projectInstance; - if (globalProperties != null) - { - TryGetProject(out Project project, globalProperties); + if (globalProperties != null) + { + TryGetProject(out Project project, globalProperties); - projectInstance = project.CreateProjectInstance(); - } - else - { - projectInstance = ProjectInstance; - } + projectInstance = project.CreateProjectInstance(); + } + else + { + projectInstance = ProjectInstance; + } - bool result = BuildHost.TryBuild(projectInstance, ProjectCollection, buildOutput, out targetOutputs, targets: targets); + bool result = BuildHost.TryBuild(projectInstance, ProjectCollection, buildOutput, out targetOutputs, targets: targets); - ResetProjectInstance(); + ResetProjectInstance(); - return result; + return result; + } + finally + { + BuildManagerHost.EndBuild(); + } + } } private bool Restore(IDictionary? globalProperties, BuildOutput buildOutput, out IDictionary? targetOutputs) diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Choose.cs b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Choose.cs index 29944ed..0ad789d 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Choose.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Choose.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -302,4 +302,4 @@ public ProjectCreator WhenPropertyGroup(string? condition = null, string? label return this; } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Conversions.cs b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Conversions.cs index 447b320..023e3a2 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Conversions.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Conversions.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -65,4 +65,4 @@ public static implicit operator XDocument(ProjectCreator creator) return XDocument.Parse(creator.Xml); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Imports.cs b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Imports.cs index f2e7057..34bfb97 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Imports.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Imports.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -98,4 +98,4 @@ public ProjectCreator ImportSdk(string project, string name, string? version = n return Import(project, condition, name, version, label: label); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.ItemGroups.cs b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.ItemGroups.cs index 75e7b6f..9d19402 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.ItemGroups.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.ItemGroups.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -66,4 +66,4 @@ protected ProjectItemGroupElement ItemGroup(ProjectElementContainer parent, stri return itemGroup; } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Items.cs b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Items.cs index 80776c4..5d49083 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Items.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Items.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -455,4 +455,4 @@ private ProjectCreator Item( return this; } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Linq.cs b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Linq.cs index 6624ff4..abb5328 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Linq.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Linq.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Project.cs b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Project.cs index c6ff893..50f8802 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Project.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Project.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -132,4 +132,4 @@ internal void ResetProjectInstance() _projectInstance = null; } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Properties.cs b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Properties.cs index e8ba1df..ecc1aaf 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Properties.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Properties.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -86,4 +86,4 @@ private ProjectCreator Property(ProjectPropertyGroupElement propertyGroup, strin return this; } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.PropertyGroups.cs b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.PropertyGroups.cs index 99c3c6d..9669e5a 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.PropertyGroups.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.PropertyGroups.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -66,4 +66,4 @@ protected ProjectPropertyGroupElement PropertyGroup(ProjectElementContainer pare return propertyGroup; } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Sdk.cs b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Sdk.cs index a717974..a05f3af 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Sdk.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Sdk.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -19,4 +19,4 @@ public ProjectCreator Sdk(string name, string? version = null) return this; } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Targets.cs b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Targets.cs index 1c4c452..f298543 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Targets.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Targets.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -187,4 +187,4 @@ public ProjectCreator TargetPropertyGroup(string? condition = null, string? labe return this; } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Tasks.cs b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Tasks.cs index 80479e0..5b2ac30 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Tasks.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Tasks.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -173,4 +173,4 @@ public ProjectCreator TaskWarning(string text, string? code = null, string? file label: label); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Templates.cs b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Templates.cs index 02aa92b..1acfa30 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Templates.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Templates.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -11,4 +11,4 @@ public partial class ProjectCreator /// public static ProjectCreatorTemplates Templates { get; } = new ProjectCreatorTemplates(); } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.UsingTasks.cs b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.UsingTasks.cs index 0688f4c..e699e40 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.UsingTasks.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.UsingTasks.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -217,4 +217,4 @@ public ProjectCreator UsingTaskRoslynCodeTaskFactory( return this; } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.cs b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.cs index f965c80..01dc3bc 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreatorConstants.cs b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreatorConstants.cs index 963d53d..23faeed 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreatorConstants.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreatorConstants.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -24,4 +24,4 @@ public static class ProjectCreatorConstants /// public const string SdkCsprojDefaultTargetFramework = "netstandard2.0"; } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreatorException.cs b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreatorException.cs index 33a615b..7763a36 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreatorException.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreatorException.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -30,4 +30,4 @@ public ProjectCreatorException(string message, Exception innerException) { } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreatorTemplates/LegacyCsproj.cs b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreatorTemplates/LegacyCsproj.cs index 76059b9..586ecd6 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreatorTemplates/LegacyCsproj.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreatorTemplates/LegacyCsproj.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -107,4 +107,4 @@ public ProjectCreator LegacyCsproj( .Import(@"$(MSBuildToolsPath)\Microsoft.CSharp.targets"); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreatorTemplates/LogsMessage.cs b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreatorTemplates/LogsMessage.cs index f133c3a..bf96412 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreatorTemplates/LogsMessage.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreatorTemplates/LogsMessage.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreatorTemplates/SdkCsproj.cs b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreatorTemplates/SdkCsproj.cs index efb5fdd..cf142cd 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreatorTemplates/SdkCsproj.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreatorTemplates/SdkCsproj.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -99,4 +99,4 @@ public ProjectCreator SdkCsproj( .CustomAction(projectCreator); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/Properties/AssemblyInfo.cs b/src/Microsoft.Build.Utilities.ProjectCreation/Properties/AssemblyInfo.cs index cfc06c5..4bb50a7 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/Properties/AssemblyInfo.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/Properties/AssemblyInfo.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jeff Kluge. All rights reserved. +// Copyright (c) Jeff Kluge. All rights reserved. // // Licensed under the MIT license. @@ -6,4 +6,4 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Microsoft.Build.Utilities.ProjectCreation.UnitTests, PublicKey=00240000048000009400000006020000002400005253413100040000010001009d49923c182b255cf69ba155c3e5b2684b0f4794bd19129d7e693ac4609a70fa1791fff5353094ce6ab1be77e12278085b719bb11f74dbd282bb96b2647fab2497da04fa9f5a882089abb5c5fafa70b3f20a58265554e31602ec352b1e2e49831ff7afce904629911ebc39e22f8e06ec69dca2e68a4baa8a883965b2e992a7b4")] -[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1629:DocumentationTextMustEndWithAPeriod", Justification = "Reviewed.")] \ No newline at end of file +[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1629:DocumentationTextMustEndWithAPeriod", Justification = "Reviewed.")] diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/SemVersion.cs b/src/Microsoft.Build.Utilities.ProjectCreation/SemVersion.cs index 4040d8d..a729ee1 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/SemVersion.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/SemVersion.cs @@ -1,4 +1,4 @@ -#pragma warning disable SA1636 // File header copyright text should match +#pragma warning disable SA1636 // File header copyright text should match #pragma warning disable SA1642 // Constructor summary documentation should begin with standard text #pragma warning disable CS8604 // Possible null reference argument. #pragma warning disable SA1503 // Braces should not be omitted @@ -53,7 +53,7 @@ internal sealed class SemVersion : IComparable, IComparable, ISerial { private static readonly Regex ParseEx = - new Regex(@"^(?\d+)" + + new(@"^(?\d+)" + @"(?>\.(?\d+))?" + @"(?>\.(?\d+))?" + @"(?>\-(?
[0-9A-Za-z\-\.]+))?" +
@@ -620,4 +620,4 @@ public static int GetDigits(int n)
 #pragma warning restore SA1117 // Parameters should be on same line or separate lines
 #pragma warning restore SA1201 // Elements should appear in the correct order
 #pragma warning restore CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes).
-#pragma warning restore SA1407 // Arithmetic expressions should declare precedence
\ No newline at end of file
+#pragma warning restore SA1407 // Arithmetic expressions should declare precedence
diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/SolutionCreator.Build.cs b/src/Microsoft.Build.Utilities.ProjectCreation/SolutionCreator.Build.cs
index e9a6e64..7b9359e 100644
--- a/src/Microsoft.Build.Utilities.ProjectCreation/SolutionCreator.Build.cs
+++ b/src/Microsoft.Build.Utilities.ProjectCreation/SolutionCreator.Build.cs
@@ -1,4 +1,4 @@
-// Copyright (c) Jeff Kluge. All rights reserved.
+// Copyright (c) Jeff Kluge. All rights reserved.
 //
 // Licensed under the MIT license.
 
@@ -56,17 +56,9 @@ public SolutionCreator TryBuild(bool restore, string target, out bool result)
         /// The current .
         public SolutionCreator TryBuild(bool restore, string target, IDictionary? globalProperties, out bool result)
         {
-            if (restore)
-            {
-                TryRestore(out result);
-
-                if (!result)
-                {
-                    return this;
-                }
-            }
+            BuildOutput buildOutput = BuildOutput.Create();
 
-            result = Build([target], globalProperties, out _, out _);
+            result = Build(restore, [target], globalProperties, buildOutput, out _);
 
             return this;
         }
@@ -168,17 +160,9 @@ public SolutionCreator TryBuild(bool restore, out bool result)
         /// The current .
         public SolutionCreator TryBuild(bool restore, IDictionary? globalProperties, out bool result)
         {
-            if (restore)
-            {
-                TryRestore(out result);
-
-                if (!result)
-                {
-                    return this;
-                }
-            }
+            BuildOutput buildOutput = BuildOutput.Create();
 
-            result = Build(null, globalProperties: globalProperties, out _, out _);
+            result = Build(restore, targets: null, globalProperties: globalProperties, buildOutput, out _);
 
             return this;
         }
@@ -491,21 +475,33 @@ private bool Build(bool restore, string[]? targets, IDictionary?
         {
             targetOutputs = null;
 
-            if (restore)
+            lock (BuildManagerHost.LockObject)
             {
-                if (!Restore(globalProperties, buildOutput, out targetOutputs))
+                BuildManagerHost.BeginBuild([.. ProjectCollection.Loggers, buildOutput]);
+
+                try
                 {
-                    return false;
+                    if (restore)
+                    {
+                        if (!Restore(globalProperties, buildOutput, out targetOutputs))
+                        {
+                            return false;
+                        }
+                    }
+                    else
+                    {
+                        Save();
+                    }
+
+                    bool result = BuildHost.TryBuild(FullPath, ProjectCollection, buildOutput, out targetOutputs, targets: targets);
+
+                    return result;
+                }
+                finally
+                {
+                    BuildManagerHost.EndBuild();
                 }
             }
-            else
-            {
-                Save();
-            }
-
-            bool result = BuildHost.TryBuild(FullPath, ProjectCollection, buildOutput, out targetOutputs, targets: targets);
-
-            return result;
         }
 
         private bool Restore(IDictionary? globalProperties, BuildOutput buildOutput, out IDictionary? targetOutputs)
diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/SolutionCreator.Templates.cs b/src/Microsoft.Build.Utilities.ProjectCreation/SolutionCreator.Templates.cs
index 60fb569..1ee3837 100644
--- a/src/Microsoft.Build.Utilities.ProjectCreation/SolutionCreator.Templates.cs
+++ b/src/Microsoft.Build.Utilities.ProjectCreation/SolutionCreator.Templates.cs
@@ -1,4 +1,4 @@
-// Copyright (c) Jeff Kluge. All rights reserved.
+// Copyright (c) Jeff Kluge. All rights reserved.
 //
 // Licensed under the MIT license.
 
diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/SolutionCreator.cs b/src/Microsoft.Build.Utilities.ProjectCreation/SolutionCreator.cs
index df15aaf..9566016 100644
--- a/src/Microsoft.Build.Utilities.ProjectCreation/SolutionCreator.cs
+++ b/src/Microsoft.Build.Utilities.ProjectCreation/SolutionCreator.cs
@@ -1,4 +1,4 @@
-// Copyright (c) Jeff Kluge. All rights reserved.
+// Copyright (c) Jeff Kluge. All rights reserved.
 //
 // Licensed under the MIT license.
 
diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/SolutionCreatorTemplates/DotNet.cs b/src/Microsoft.Build.Utilities.ProjectCreation/SolutionCreatorTemplates/DotNet.cs
index 4d5c63a..13e5cb5 100644
--- a/src/Microsoft.Build.Utilities.ProjectCreation/SolutionCreatorTemplates/DotNet.cs
+++ b/src/Microsoft.Build.Utilities.ProjectCreation/SolutionCreatorTemplates/DotNet.cs
@@ -1,4 +1,4 @@
-// Copyright (c) Jeff Kluge. All rights reserved.
+// Copyright (c) Jeff Kluge. All rights reserved.
 //
 // Licensed under the MIT license.
 
diff --git a/src/Shared/GlobalSuppressions.cs b/src/Shared/GlobalSuppressions.cs
index a02b9b5..e7f30e2 100644
--- a/src/Shared/GlobalSuppressions.cs
+++ b/src/Shared/GlobalSuppressions.cs
@@ -1,4 +1,4 @@
-// Copyright (c) Jeff Kluge. All rights reserved.
+// Copyright (c) Jeff Kluge. All rights reserved.
 //
 // Licensed under the MIT license.
 
@@ -8,4 +8,4 @@
 [assembly: SuppressMessage("StyleCop.CSharp.NamingRules", "SA1309:FieldNamesMustNotBeginWithUnderscore", Justification = "Reviewed.")]
 [assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1101:PrefixLocalCallsWithThis", Justification = "Reviewed.")]
 [assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1118:ParameterMustNotSpanMultipleLines", Justification = "Reviewed.")]
-[assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1121:UseBuiltInTypeAlias", Justification = "Reviewed.")]
\ No newline at end of file
+[assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1121:UseBuiltInTypeAlias", Justification = "Reviewed.")]
diff --git a/src/Shared/stylecop.json b/src/Shared/stylecop.json
index 0829cfa..4eeb69f 100644
--- a/src/Shared/stylecop.json
+++ b/src/Shared/stylecop.json
@@ -1,6 +1,5 @@
 {
-  "$schema":
-    "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
+  "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
   "settings": {
     "orderingRules": {
       "usingDirectivesPlacement": "outsideNamespace",