diff --git a/Sources/ThirdPartyLibraries.Npm.Test/Internal/NpmRootTest.cs b/Sources/ThirdPartyLibraries.Npm.Test/Internal/NpmRootTest.cs index 9be30dbc..05897a6d 100644 --- a/Sources/ThirdPartyLibraries.Npm.Test/Internal/NpmRootTest.cs +++ b/Sources/ThirdPartyLibraries.Npm.Test/Internal/NpmRootTest.cs @@ -13,8 +13,5 @@ public void Resolve() Console.WriteLine(actual); actual.ShouldNotBeNull(); - - Path.GetDirectoryName(actual).ShouldNotBeNullOrWhiteSpace(); - Assert.That(Path.GetDirectoryName(actual), Does.Exist.IgnoreFiles); } } \ No newline at end of file diff --git a/Sources/ThirdPartyLibraries.NuGet.Test/Internal/ProjectAssetsParserTest.cs b/Sources/ThirdPartyLibraries.NuGet.Test/Internal/ProjectAssetsParserTest.cs index 21489f2a..8c6b461b 100644 --- a/Sources/ThirdPartyLibraries.NuGet.Test/Internal/ProjectAssetsParserTest.cs +++ b/Sources/ThirdPartyLibraries.NuGet.Test/Internal/ProjectAssetsParserTest.cs @@ -6,62 +6,10 @@ namespace ThirdPartyLibraries.NuGet.Internal; [TestFixture] public class ProjectAssetsParserTest { - [Test] - public void GetTargetFrameworks() - { - var actual = CreateSut("project").GetTargetFrameworks(); - - actual.ShouldBe(new[] { "net452", "netcoreapp2.2", "net472" }, ignoreOrder: true); - } - - [Test] - public void GetNet452References() - { - var actual = CreateSut("project").GetReferences("net452").ToList(); - - actual.Count.ShouldBe(1); - - actual[0].Package.Name.ShouldBe("StyleCop.Analyzers"); - actual[0].Package.Version.ShouldBe("1.1.118"); - } - - [Test] - public void GetNetCore22References() - { - var actual = CreateSut("project").GetReferences("netcoreapp2.2").ToList(); - - actual.Count.ShouldBe(11); - actual[2].Package.Name.ShouldBe("System.Configuration.ConfigurationManager"); - actual[2].Package.Version.ShouldBe("4.5.0"); - - var dependencies = actual[2].Dependencies; - dependencies.Count.ShouldBe(2); - - dependencies[0].Name.ShouldBe("System.Security.Cryptography.ProtectedData"); - dependencies[0].Version.ShouldBe("4.5.0"); - - dependencies[1].Name.ShouldBe("System.Security.Permissions"); - dependencies[1].Version.ShouldBe("4.5.0"); - } - - [Test] - public void GetNet472References() - { - var actual = CreateSut("project").GetReferences("net472").ToList(); - - actual.ShouldBeEmpty(); - } - - [Test] - public void GetProjectName() - { - CreateSut("project").GetProjectName().ShouldBe("Company.Name.Project"); - } - [Test] public void InvalidReference() { - var sut = CreateSut("invalid-project"); + var sut = CreateSut(); var ex = Assert.Throws(() => sut.GetReferences("netcoreapp3.1")); @@ -72,6 +20,12 @@ public void InvalidReference() ex.Message.ShouldContain("StyleCop.Analyzers"); } + [Test] + public void GetPackageSourcesNotFound() + { + CreateSut().GetPackageSources().ShouldBeEmpty(); + } + [Test] [TestCase("netcoreapp2.2", ".NETCoreApp,Version=v2.2")] [TestCase("netstandard1.3", ".NETStandard,Version=v1.3")] @@ -90,28 +44,10 @@ public void MapTargetFrameworkProjFormatToNuGetFormat(string projFormat, string ProjectAssetsParser.MapTargetFrameworkProjFormatToNuGetFormat(projFormat).ShouldBe(expected); } - [Test] - public void GetPackageSources() - { - CreateSut("project").GetPackageSources().ShouldBe( - [ - new Uri(@"C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\", UriKind.Absolute), - new Uri(@"https://api.nuget.org/v3/index.json", UriKind.Absolute) - ]); - } - - [Test] - public void GetPackageSourcesNotFound() - { - CreateSut("invalid-project").GetPackageSources().ShouldBeEmpty(); - } - - private static ProjectAssetsParser CreateSut(string fileName) + private static ProjectAssetsParser CreateSut() { - var resourceName = $"ProjectAssetsParserTest.{fileName}.assets.json"; - using (var stream = TempFile.OpenResource(typeof(ProjectAssetsParserTest), resourceName)) - { - return ProjectAssetsParser.FromStream(stream); - } + var resourceName = "ProjectAssetsParserTest.invalid-project.assets.json"; + using var stream = TempFile.OpenResource(typeof(ProjectAssetsParserTest), resourceName); + return ProjectAssetsParser.FromStream(stream); } } \ No newline at end of file diff --git a/Sources/ThirdPartyLibraries.NuGet.Test/Internal/ProjectAssetsParserTest.project.assets.json b/Sources/ThirdPartyLibraries.NuGet.Test/Internal/ProjectAssetsParserTest.project.assets.json deleted file mode 100644 index 49828736..00000000 --- a/Sources/ThirdPartyLibraries.NuGet.Test/Internal/ProjectAssetsParserTest.project.assets.json +++ /dev/null @@ -1,495 +0,0 @@ -{ - "version": 3, - "targets": { - ".NETCoreApp,Version=v2.2": { - "Microsoft.NETCore.App/2.2.0": { - "type": "package", - "dependencies": { - "Microsoft.NETCore.DotNetHostPolicy": "2.2.0", - "Microsoft.NETCore.Platforms": "2.2.0", - "Microsoft.NETCore.Targets": "2.0.0", - "NETStandard.Library": "2.0.3" - }, - "compile": { - "ref/netcoreapp2.2/Microsoft.CSharp.dll": {}, - "ref/netcoreapp2.2/Microsoft.VisualBasic.dll": {}, - "ref/netcoreapp2.2/Microsoft.Win32.Primitives.dll": {}, - "ref/netcoreapp2.2/System.AppContext.dll": {}, - "ref/netcoreapp2.2/System.Buffers.dll": {}, - "ref/netcoreapp2.2/System.Collections.Concurrent.dll": {}, - "ref/netcoreapp2.2/System.Collections.Immutable.dll": {}, - "ref/netcoreapp2.2/System.Collections.NonGeneric.dll": {}, - "ref/netcoreapp2.2/System.Collections.Specialized.dll": {}, - "ref/netcoreapp2.2/System.Collections.dll": {}, - "ref/netcoreapp2.2/System.ComponentModel.Annotations.dll": {}, - "ref/netcoreapp2.2/System.ComponentModel.DataAnnotations.dll": {}, - "ref/netcoreapp2.2/System.ComponentModel.EventBasedAsync.dll": {}, - "ref/netcoreapp2.2/System.ComponentModel.Primitives.dll": {}, - "ref/netcoreapp2.2/System.ComponentModel.TypeConverter.dll": {}, - "ref/netcoreapp2.2/System.ComponentModel.dll": {}, - "ref/netcoreapp2.2/System.Configuration.dll": {}, - "ref/netcoreapp2.2/System.Console.dll": {}, - "ref/netcoreapp2.2/System.Core.dll": {}, - "ref/netcoreapp2.2/System.Data.Common.dll": {}, - "ref/netcoreapp2.2/System.Data.dll": {}, - "ref/netcoreapp2.2/System.Diagnostics.Contracts.dll": {}, - "ref/netcoreapp2.2/System.Diagnostics.Debug.dll": {}, - "ref/netcoreapp2.2/System.Diagnostics.DiagnosticSource.dll": {}, - "ref/netcoreapp2.2/System.Diagnostics.FileVersionInfo.dll": {}, - "ref/netcoreapp2.2/System.Diagnostics.Process.dll": {}, - "ref/netcoreapp2.2/System.Diagnostics.StackTrace.dll": {}, - "ref/netcoreapp2.2/System.Diagnostics.TextWriterTraceListener.dll": {}, - "ref/netcoreapp2.2/System.Diagnostics.Tools.dll": {}, - "ref/netcoreapp2.2/System.Diagnostics.TraceSource.dll": {}, - "ref/netcoreapp2.2/System.Diagnostics.Tracing.dll": {}, - "ref/netcoreapp2.2/System.Drawing.Primitives.dll": {}, - "ref/netcoreapp2.2/System.Drawing.dll": {}, - "ref/netcoreapp2.2/System.Dynamic.Runtime.dll": {}, - "ref/netcoreapp2.2/System.Globalization.Calendars.dll": {}, - "ref/netcoreapp2.2/System.Globalization.Extensions.dll": {}, - "ref/netcoreapp2.2/System.Globalization.dll": {}, - "ref/netcoreapp2.2/System.IO.Compression.Brotli.dll": {}, - "ref/netcoreapp2.2/System.IO.Compression.FileSystem.dll": {}, - "ref/netcoreapp2.2/System.IO.Compression.ZipFile.dll": {}, - "ref/netcoreapp2.2/System.IO.Compression.dll": {}, - "ref/netcoreapp2.2/System.IO.FileSystem.DriveInfo.dll": {}, - "ref/netcoreapp2.2/System.IO.FileSystem.Primitives.dll": {}, - "ref/netcoreapp2.2/System.IO.FileSystem.Watcher.dll": {}, - "ref/netcoreapp2.2/System.IO.FileSystem.dll": {}, - "ref/netcoreapp2.2/System.IO.IsolatedStorage.dll": {}, - "ref/netcoreapp2.2/System.IO.MemoryMappedFiles.dll": {}, - "ref/netcoreapp2.2/System.IO.Pipes.dll": {}, - "ref/netcoreapp2.2/System.IO.UnmanagedMemoryStream.dll": {}, - "ref/netcoreapp2.2/System.IO.dll": {}, - "ref/netcoreapp2.2/System.Linq.Expressions.dll": {}, - "ref/netcoreapp2.2/System.Linq.Parallel.dll": {}, - "ref/netcoreapp2.2/System.Linq.Queryable.dll": {}, - "ref/netcoreapp2.2/System.Linq.dll": {}, - "ref/netcoreapp2.2/System.Memory.dll": {}, - "ref/netcoreapp2.2/System.Net.Http.dll": {}, - "ref/netcoreapp2.2/System.Net.HttpListener.dll": {}, - "ref/netcoreapp2.2/System.Net.Mail.dll": {}, - "ref/netcoreapp2.2/System.Net.NameResolution.dll": {}, - "ref/netcoreapp2.2/System.Net.NetworkInformation.dll": {}, - "ref/netcoreapp2.2/System.Net.Ping.dll": {}, - "ref/netcoreapp2.2/System.Net.Primitives.dll": {}, - "ref/netcoreapp2.2/System.Net.Requests.dll": {}, - "ref/netcoreapp2.2/System.Net.Security.dll": {}, - "ref/netcoreapp2.2/System.Net.ServicePoint.dll": {}, - "ref/netcoreapp2.2/System.Net.Sockets.dll": {}, - "ref/netcoreapp2.2/System.Net.WebClient.dll": {}, - "ref/netcoreapp2.2/System.Net.WebHeaderCollection.dll": {}, - "ref/netcoreapp2.2/System.Net.WebProxy.dll": {}, - "ref/netcoreapp2.2/System.Net.WebSockets.Client.dll": {}, - "ref/netcoreapp2.2/System.Net.WebSockets.dll": {}, - "ref/netcoreapp2.2/System.Net.dll": {}, - "ref/netcoreapp2.2/System.Numerics.Vectors.dll": {}, - "ref/netcoreapp2.2/System.Numerics.dll": {}, - "ref/netcoreapp2.2/System.ObjectModel.dll": {}, - "ref/netcoreapp2.2/System.Reflection.DispatchProxy.dll": {}, - "ref/netcoreapp2.2/System.Reflection.Emit.ILGeneration.dll": {}, - "ref/netcoreapp2.2/System.Reflection.Emit.Lightweight.dll": {}, - "ref/netcoreapp2.2/System.Reflection.Emit.dll": {}, - "ref/netcoreapp2.2/System.Reflection.Extensions.dll": {}, - "ref/netcoreapp2.2/System.Reflection.Metadata.dll": {}, - "ref/netcoreapp2.2/System.Reflection.Primitives.dll": {}, - "ref/netcoreapp2.2/System.Reflection.TypeExtensions.dll": {}, - "ref/netcoreapp2.2/System.Reflection.dll": {}, - "ref/netcoreapp2.2/System.Resources.Reader.dll": {}, - "ref/netcoreapp2.2/System.Resources.ResourceManager.dll": {}, - "ref/netcoreapp2.2/System.Resources.Writer.dll": {}, - "ref/netcoreapp2.2/System.Runtime.CompilerServices.VisualC.dll": {}, - "ref/netcoreapp2.2/System.Runtime.Extensions.dll": {}, - "ref/netcoreapp2.2/System.Runtime.Handles.dll": {}, - "ref/netcoreapp2.2/System.Runtime.InteropServices.RuntimeInformation.dll": {}, - "ref/netcoreapp2.2/System.Runtime.InteropServices.WindowsRuntime.dll": {}, - "ref/netcoreapp2.2/System.Runtime.InteropServices.dll": {}, - "ref/netcoreapp2.2/System.Runtime.Loader.dll": {}, - "ref/netcoreapp2.2/System.Runtime.Numerics.dll": {}, - "ref/netcoreapp2.2/System.Runtime.Serialization.Formatters.dll": {}, - "ref/netcoreapp2.2/System.Runtime.Serialization.Json.dll": {}, - "ref/netcoreapp2.2/System.Runtime.Serialization.Primitives.dll": {}, - "ref/netcoreapp2.2/System.Runtime.Serialization.Xml.dll": {}, - "ref/netcoreapp2.2/System.Runtime.Serialization.dll": {}, - "ref/netcoreapp2.2/System.Runtime.dll": {}, - "ref/netcoreapp2.2/System.Security.Claims.dll": {}, - "ref/netcoreapp2.2/System.Security.Cryptography.Algorithms.dll": {}, - "ref/netcoreapp2.2/System.Security.Cryptography.Csp.dll": {}, - "ref/netcoreapp2.2/System.Security.Cryptography.Encoding.dll": {}, - "ref/netcoreapp2.2/System.Security.Cryptography.Primitives.dll": {}, - "ref/netcoreapp2.2/System.Security.Cryptography.X509Certificates.dll": {}, - "ref/netcoreapp2.2/System.Security.Principal.dll": {}, - "ref/netcoreapp2.2/System.Security.SecureString.dll": {}, - "ref/netcoreapp2.2/System.Security.dll": {}, - "ref/netcoreapp2.2/System.ServiceModel.Web.dll": {}, - "ref/netcoreapp2.2/System.ServiceProcess.dll": {}, - "ref/netcoreapp2.2/System.Text.Encoding.Extensions.dll": {}, - "ref/netcoreapp2.2/System.Text.Encoding.dll": {}, - "ref/netcoreapp2.2/System.Text.RegularExpressions.dll": {}, - "ref/netcoreapp2.2/System.Threading.Overlapped.dll": {}, - "ref/netcoreapp2.2/System.Threading.Tasks.Dataflow.dll": {}, - "ref/netcoreapp2.2/System.Threading.Tasks.Extensions.dll": {}, - "ref/netcoreapp2.2/System.Threading.Tasks.Parallel.dll": {}, - "ref/netcoreapp2.2/System.Threading.Tasks.dll": {}, - "ref/netcoreapp2.2/System.Threading.Thread.dll": {}, - "ref/netcoreapp2.2/System.Threading.ThreadPool.dll": {}, - "ref/netcoreapp2.2/System.Threading.Timer.dll": {}, - "ref/netcoreapp2.2/System.Threading.dll": {}, - "ref/netcoreapp2.2/System.Transactions.Local.dll": {}, - "ref/netcoreapp2.2/System.Transactions.dll": {}, - "ref/netcoreapp2.2/System.ValueTuple.dll": {}, - "ref/netcoreapp2.2/System.Web.HttpUtility.dll": {}, - "ref/netcoreapp2.2/System.Web.dll": {}, - "ref/netcoreapp2.2/System.Windows.dll": {}, - "ref/netcoreapp2.2/System.Xml.Linq.dll": {}, - "ref/netcoreapp2.2/System.Xml.ReaderWriter.dll": {}, - "ref/netcoreapp2.2/System.Xml.Serialization.dll": {}, - "ref/netcoreapp2.2/System.Xml.XDocument.dll": {}, - "ref/netcoreapp2.2/System.Xml.XPath.XDocument.dll": {}, - "ref/netcoreapp2.2/System.Xml.XPath.dll": {}, - "ref/netcoreapp2.2/System.Xml.XmlDocument.dll": {}, - "ref/netcoreapp2.2/System.Xml.XmlSerializer.dll": {}, - "ref/netcoreapp2.2/System.Xml.dll": {}, - "ref/netcoreapp2.2/System.dll": {}, - "ref/netcoreapp2.2/WindowsBase.dll": {}, - "ref/netcoreapp2.2/mscorlib.dll": {}, - "ref/netcoreapp2.2/netstandard.dll": {} - }, - "build": { - "build/netcoreapp2.2/Microsoft.NETCore.App.props": {}, - "build/netcoreapp2.2/Microsoft.NETCore.App.targets": {} - } - }, - "Microsoft.NETCore.DotNetAppHost/2.2.0": { - "type": "package" - }, - "Microsoft.NETCore.DotNetHostPolicy/2.2.0": { - "type": "package", - "dependencies": { - "Microsoft.NETCore.DotNetHostResolver": "2.2.0" - } - }, - "Microsoft.NETCore.DotNetHostResolver/2.2.0": { - "type": "package", - "dependencies": { - "Microsoft.NETCore.DotNetAppHost": "2.2.0" - } - }, - "Microsoft.NETCore.Platforms/2.2.0": { - "type": "package", - "compile": { - "lib/netstandard1.0/_._": {} - }, - "runtime": { - "lib/netstandard1.0/_._": {} - } - }, - "Microsoft.NETCore.Targets/2.0.0": { - "type": "package", - "compile": { - "lib/netstandard1.0/_._": {} - }, - "runtime": { - "lib/netstandard1.0/_._": {} - } - }, - "Microsoft.Win32.Registry/4.5.0": { - "type": "package", - "dependencies": { - "System.Security.AccessControl": "4.5.0", - "System.Security.Principal.Windows": "4.5.0" - }, - "compile": { - "ref/netstandard2.0/_._": {} - }, - "runtime": { - "lib/netstandard2.0/Microsoft.Win32.Registry.dll": {} - }, - "runtimeTargets": { - "runtimes/unix/lib/netstandard2.0/Microsoft.Win32.Registry.dll": { - "assetType": "runtime", - "rid": "unix" - }, - "runtimes/win/lib/netstandard2.0/Microsoft.Win32.Registry.dll": { - "assetType": "runtime", - "rid": "win" - } - } - }, - "NETStandard.Library/2.0.3": { - "type": "package", - "dependencies": { - "Microsoft.NETCore.Platforms": "1.1.0" - }, - "compile": { - "lib/netstandard1.0/_._": {} - }, - "runtime": { - "lib/netstandard1.0/_._": {} - }, - "build": { - "build/netstandard2.0/NETStandard.Library.targets": {} - } - }, - "runtime.native.System.Data.SqlClient.sni/4.5.0": { - "type": "package", - "dependencies": { - "runtime.win-arm64.runtime.native.System.Data.SqlClient.sni": "4.4.0", - "runtime.win-x64.runtime.native.System.Data.SqlClient.sni": "4.4.0", - "runtime.win-x86.runtime.native.System.Data.SqlClient.sni": "4.4.0" - } - }, - "runtime.win-arm64.runtime.native.System.Data.SqlClient.sni/4.4.0": { - "type": "package", - "runtimeTargets": { - "runtimes/win-arm64/native/sni.dll": { - "assetType": "native", - "rid": "win-arm64" - } - } - }, - "runtime.win-x64.runtime.native.System.Data.SqlClient.sni/4.4.0": { - "type": "package", - "runtimeTargets": { - "runtimes/win-x64/native/sni.dll": { - "assetType": "native", - "rid": "win-x64" - } - } - }, - "runtime.win-x86.runtime.native.System.Data.SqlClient.sni/4.4.0": { - "type": "package", - "runtimeTargets": { - "runtimes/win-x86/native/sni.dll": { - "assetType": "native", - "rid": "win-x86" - } - } - }, - "StyleCop.Analyzers/1.1.118": { - "type": "package" - }, - "System.Configuration.ConfigurationManager/4.5.0": { - "type": "package", - "dependencies": { - "System.Security.Cryptography.ProtectedData": "4.5.0", - "System.Security.Permissions": "4.5.0" - }, - "compile": { - "ref/netstandard2.0/System.Configuration.ConfigurationManager.dll": {} - }, - "runtime": { - "lib/netstandard2.0/System.Configuration.ConfigurationManager.dll": {} - } - }, - "System.Data.SqlClient/4.6.0": { - "type": "package", - "dependencies": { - "Microsoft.Win32.Registry": "4.5.0", - "System.Security.Principal.Windows": "4.5.0", - "System.Text.Encoding.CodePages": "4.5.0", - "runtime.native.System.Data.SqlClient.sni": "4.5.0" - }, - "compile": { - "ref/netcoreapp2.1/System.Data.SqlClient.dll": {} - }, - "runtime": { - "lib/netcoreapp2.1/System.Data.SqlClient.dll": {} - }, - "runtimeTargets": { - "runtimes/unix/lib/netcoreapp2.1/System.Data.SqlClient.dll": { - "assetType": "runtime", - "rid": "unix" - }, - "runtimes/win/lib/netcoreapp2.1/System.Data.SqlClient.dll": { - "assetType": "runtime", - "rid": "win" - } - } - }, - "System.Runtime.CompilerServices.Unsafe/4.5.0": { - "type": "package", - "compile": { - "ref/netstandard2.0/_._": {} - }, - "runtime": { - "lib/netcoreapp2.0/System.Runtime.CompilerServices.Unsafe.dll": {} - } - }, - "System.Security.AccessControl/4.5.0": { - "type": "package", - "dependencies": { - "Microsoft.NETCore.Platforms": "2.0.0", - "System.Security.Principal.Windows": "4.5.0" - }, - "compile": { - "ref/netstandard2.0/System.Security.AccessControl.dll": {} - }, - "runtime": { - "lib/netstandard2.0/System.Security.AccessControl.dll": {} - }, - "runtimeTargets": { - "runtimes/win/lib/netcoreapp2.0/System.Security.AccessControl.dll": { - "assetType": "runtime", - "rid": "win" - } - } - }, - "System.Security.Cryptography.ProtectedData/4.5.0": { - "type": "package", - "compile": { - "ref/netstandard2.0/_._": {} - }, - "runtime": { - "lib/netstandard2.0/System.Security.Cryptography.ProtectedData.dll": {} - }, - "runtimeTargets": { - "runtimes/win/lib/netstandard2.0/System.Security.Cryptography.ProtectedData.dll": { - "assetType": "runtime", - "rid": "win" - } - } - }, - "System.Security.Permissions/4.5.0": { - "type": "package", - "dependencies": { - "System.Security.AccessControl": "4.5.0" - }, - "compile": { - "ref/netstandard2.0/System.Security.Permissions.dll": {} - }, - "runtime": { - "lib/netstandard2.0/System.Security.Permissions.dll": {} - } - }, - "System.Security.Principal.Windows/4.5.0": { - "type": "package", - "dependencies": { - "Microsoft.NETCore.Platforms": "2.0.0" - }, - "compile": { - "ref/netstandard2.0/System.Security.Principal.Windows.dll": {} - }, - "runtime": { - "lib/netstandard2.0/System.Security.Principal.Windows.dll": {} - }, - "runtimeTargets": { - "runtimes/unix/lib/netcoreapp2.0/System.Security.Principal.Windows.dll": { - "assetType": "runtime", - "rid": "unix" - }, - "runtimes/win/lib/netcoreapp2.0/System.Security.Principal.Windows.dll": { - "assetType": "runtime", - "rid": "win" - } - } - }, - "System.Text.Encoding.CodePages/4.5.0": { - "type": "package", - "dependencies": { - "Microsoft.NETCore.Platforms": "2.0.0", - "System.Runtime.CompilerServices.Unsafe": "4.5.0" - }, - "compile": { - "ref/netstandard2.0/_._": {} - }, - "runtime": { - "lib/netstandard2.0/System.Text.Encoding.CodePages.dll": {} - }, - "runtimeTargets": { - "runtimes/win/lib/netcoreapp2.0/System.Text.Encoding.CodePages.dll": { - "assetType": "runtime", - "rid": "win" - } - } - } - }, - ".NETFramework,Version=v4.5.2": { - "StyleCop.Analyzers/1.1.118": { - "type": "package" - } - }, - ".NETFramework,Version=v4.7.2": {} - }, - "projectFileDependencyGroups": { - ".NETCoreApp,Version=v2.2": [ - "Microsoft.NETCore.App >= 2.2.0", - "StyleCop.Analyzers >= 1.1.118", - "System.Configuration.ConfigurationManager >= 4.5.0", - "System.Data.SqlClient >= 4.6.0" - ], - ".NETFramework,Version=v4.5.2": [ - "StyleCop.Analyzers >= 1.1.118" - ] - }, - "project": { - "version": "1.0.0", - "restore": { - "projectName": "Company.Name.Project", - "originalTargetFrameworks": [ - "net452", - "netcoreapp2.2" - ], - "sources": { - "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {}, - "https://api.nuget.org/v3/index.json": {} - }, - "frameworks": { - "netcoreapp2.2": { - "projectReferences": {} - }, - "net452": { - "projectReferences": {} - } - }, - "warningProperties": { - "allWarningsAsErrors": true, - "noWarn": [ - "NU5125" - ] - } - }, - "frameworks": { - "netcoreapp2.2": { - "dependencies": { - "Microsoft.NETCore.App": { - "suppressParent": "All", - "target": "Package", - "version": "[2.2.0, )", - "autoReferenced": true - }, - "StyleCop.Analyzers": { - "suppressParent": "All", - "target": "Package", - "version": "[1.1.118, )" - }, - "System.Configuration.ConfigurationManager": { - "target": "Package", - "version": "[4.5.0, )" - }, - "System.Data.SqlClient": { - "target": "Package", - "version": "[4.6.0, )" - } - }, - "imports": [ - "net461" - ], - "assetTargetFallback": true, - "warn": true - }, - "net452": { - "dependencies": { - "StyleCop.Analyzers": { - "suppressParent": "All", - "target": "Package", - "version": "[1.1.118, )" - } - } - }, - "net472": { - "projectReferences": {} - } - } - } -} \ No newline at end of file diff --git a/Sources/ThirdPartyLibraries.NuGet.Test/Internal/ProjectAssetsParserTest.projectV3.assets.json b/Sources/ThirdPartyLibraries.NuGet.Test/Internal/ProjectAssetsParserTest.projectV3.assets.json new file mode 100644 index 00000000..97918a43 --- /dev/null +++ b/Sources/ThirdPartyLibraries.NuGet.Test/Internal/ProjectAssetsParserTest.projectV3.assets.json @@ -0,0 +1,329 @@ +{ + "version": 3, + "targets": { + ".NETCoreApp,Version=v2.2": { + "Microsoft.NETCore.App/2.2.0": { + "type": "package" + }, + "Microsoft.NETCore.DotNetAppHost/2.2.0": { + "type": "package" + }, + "Microsoft.NETCore.DotNetHostPolicy/2.2.0": { + "type": "package", + "dependencies": { + "Microsoft.NETCore.DotNetHostResolver": "2.2.0" + } + }, + "Microsoft.NETCore.DotNetHostResolver/2.2.0": { + "type": "package", + "dependencies": { + "Microsoft.NETCore.DotNetAppHost": "2.2.0" + } + }, + "Microsoft.NETCore.Platforms/2.2.0": { + "type": "package", + "compile": { + "lib/netstandard1.0/_._": {} + }, + "runtime": { + "lib/netstandard1.0/_._": {} + } + }, + "Microsoft.NETCore.Targets/2.0.0": { + "type": "package", + "compile": { + "lib/netstandard1.0/_._": {} + }, + "runtime": { + "lib/netstandard1.0/_._": {} + } + }, + "Microsoft.Win32.Registry/4.5.0": { + "type": "package", + "dependencies": { + "System.Security.AccessControl": "4.5.0", + "System.Security.Principal.Windows": "4.5.0" + }, + "compile": { + "ref/netstandard2.0/_._": {} + }, + "runtime": { + "lib/netstandard2.0/Microsoft.Win32.Registry.dll": {} + }, + "runtimeTargets": { + "runtimes/unix/lib/netstandard2.0/Microsoft.Win32.Registry.dll": { + "assetType": "runtime", + "rid": "unix" + }, + "runtimes/win/lib/netstandard2.0/Microsoft.Win32.Registry.dll": { + "assetType": "runtime", + "rid": "win" + } + } + }, + "NETStandard.Library/2.0.3": { + "type": "package", + "dependencies": { + "Microsoft.NETCore.Platforms": "1.1.0" + }, + "compile": { + "lib/netstandard1.0/_._": {} + }, + "runtime": { + "lib/netstandard1.0/_._": {} + }, + "build": { + "build/netstandard2.0/NETStandard.Library.targets": {} + } + }, + "runtime.native.System.Data.SqlClient.sni/4.5.0": { + "type": "package", + "dependencies": { + "runtime.win-arm64.runtime.native.System.Data.SqlClient.sni": "4.4.0", + "runtime.win-x64.runtime.native.System.Data.SqlClient.sni": "4.4.0", + "runtime.win-x86.runtime.native.System.Data.SqlClient.sni": "4.4.0" + } + }, + "runtime.win-arm64.runtime.native.System.Data.SqlClient.sni/4.4.0": { + "type": "package", + "runtimeTargets": { + "runtimes/win-arm64/native/sni.dll": { + "assetType": "native", + "rid": "win-arm64" + } + } + }, + "runtime.win-x64.runtime.native.System.Data.SqlClient.sni/4.4.0": { + "type": "package", + "runtimeTargets": { + "runtimes/win-x64/native/sni.dll": { + "assetType": "native", + "rid": "win-x64" + } + } + }, + "runtime.win-x86.runtime.native.System.Data.SqlClient.sni/4.4.0": { + "type": "package", + "runtimeTargets": { + "runtimes/win-x86/native/sni.dll": { + "assetType": "native", + "rid": "win-x86" + } + } + }, + "StyleCop.Analyzers/1.1.118": { + "type": "package" + }, + "System.Configuration.ConfigurationManager/4.5.0": { + "type": "package", + "dependencies": { + "System.Security.Cryptography.ProtectedData": "4.5.0", + "System.Security.Permissions": "4.5.0" + }, + "compile": { + "ref/netstandard2.0/System.Configuration.ConfigurationManager.dll": {} + }, + "runtime": { + "lib/netstandard2.0/System.Configuration.ConfigurationManager.dll": {} + } + }, + "System.Data.SqlClient/4.6.0": { + "type": "package", + "dependencies": { + "Microsoft.Win32.Registry": "4.5.0", + "System.Security.Principal.Windows": "4.5.0", + "System.Text.Encoding.CodePages": "4.5.0", + "runtime.native.System.Data.SqlClient.sni": "4.5.0" + }, + "compile": { + "ref/netcoreapp2.1/System.Data.SqlClient.dll": {} + }, + "runtime": { + "lib/netcoreapp2.1/System.Data.SqlClient.dll": {} + }, + "runtimeTargets": { + "runtimes/unix/lib/netcoreapp2.1/System.Data.SqlClient.dll": { + "assetType": "runtime", + "rid": "unix" + }, + "runtimes/win/lib/netcoreapp2.1/System.Data.SqlClient.dll": { + "assetType": "runtime", + "rid": "win" + } + } + }, + "System.Runtime.CompilerServices.Unsafe/4.5.0": { + "type": "package", + "compile": { + "ref/netstandard2.0/_._": {} + }, + "runtime": { + "lib/netcoreapp2.0/System.Runtime.CompilerServices.Unsafe.dll": {} + } + }, + "System.Security.AccessControl/4.5.0": { + "type": "package", + "dependencies": { + "Microsoft.NETCore.Platforms": "2.0.0", + "System.Security.Principal.Windows": "4.5.0" + }, + "compile": { + "ref/netstandard2.0/System.Security.AccessControl.dll": {} + }, + "runtime": { + "lib/netstandard2.0/System.Security.AccessControl.dll": {} + }, + "runtimeTargets": { + "runtimes/win/lib/netcoreapp2.0/System.Security.AccessControl.dll": { + "assetType": "runtime", + "rid": "win" + } + } + }, + "System.Security.Cryptography.ProtectedData/4.5.0": { + "type": "package", + "compile": { + "ref/netstandard2.0/_._": {} + }, + "runtime": { + "lib/netstandard2.0/System.Security.Cryptography.ProtectedData.dll": {} + }, + "runtimeTargets": { + "runtimes/win/lib/netstandard2.0/System.Security.Cryptography.ProtectedData.dll": { + "assetType": "runtime", + "rid": "win" + } + } + }, + "System.Security.Permissions/4.5.0": { + "type": "package", + "dependencies": { + "System.Security.AccessControl": "4.5.0" + }, + "compile": { + "ref/netstandard2.0/System.Security.Permissions.dll": {} + }, + "runtime": { + "lib/netstandard2.0/System.Security.Permissions.dll": {} + } + }, + "System.Security.Principal.Windows/4.5.0": { + "type": "package", + "dependencies": { + "Microsoft.NETCore.Platforms": "2.0.0" + }, + "compile": { + "ref/netstandard2.0/System.Security.Principal.Windows.dll": {} + }, + "runtime": { + "lib/netstandard2.0/System.Security.Principal.Windows.dll": {} + }, + "runtimeTargets": { + "runtimes/unix/lib/netcoreapp2.0/System.Security.Principal.Windows.dll": { + "assetType": "runtime", + "rid": "unix" + }, + "runtimes/win/lib/netcoreapp2.0/System.Security.Principal.Windows.dll": { + "assetType": "runtime", + "rid": "win" + } + } + }, + "System.Text.Encoding.CodePages/4.5.0": { + "type": "package", + "dependencies": { + "Microsoft.NETCore.Platforms": "2.0.0", + "System.Runtime.CompilerServices.Unsafe": "4.5.0" + }, + "compile": { + "ref/netstandard2.0/_._": {} + }, + "runtime": { + "lib/netstandard2.0/System.Text.Encoding.CodePages.dll": {} + }, + "runtimeTargets": { + "runtimes/win/lib/netcoreapp2.0/System.Text.Encoding.CodePages.dll": { + "assetType": "runtime", + "rid": "win" + } + } + } + }, + ".NETFramework,Version=v4.5.2": { + "StyleCop.Analyzers/1.1.118": { + "type": "package" + } + }, + ".NETFramework,Version=v4.7.2": {} + }, + "project": { + "version": "1.0.0", + "restore": { + "projectName": "Company.Name.Project", + "originalTargetFrameworks": [ + "net452", + "netcoreapp2.2" + ], + "sources": { + "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {}, + "https://api.nuget.org/v3/index.json": {} + }, + "frameworks": { + "netcoreapp2.2": { + "projectReferences": {} + }, + "net452": { + "projectReferences": {} + } + }, + "warningProperties": { + "allWarningsAsErrors": true, + "noWarn": [ + "NU5125" + ] + } + }, + "frameworks": { + "netcoreapp2.2": { + "dependencies": { + "Microsoft.NETCore.App": { + "suppressParent": "All", + "target": "Package", + "version": "[2.2.0, )", + "autoReferenced": true + }, + "StyleCop.Analyzers": { + "suppressParent": "All", + "target": "Package", + "version": "[1.1.118, )" + }, + "System.Configuration.ConfigurationManager": { + "target": "Package", + "version": "[4.5.0, )" + }, + "System.Data.SqlClient": { + "target": "Package", + "version": "[4.6.0, )" + } + }, + "imports": [ + "net461" + ], + "assetTargetFallback": true, + "warn": true + }, + "net452": { + "dependencies": { + "StyleCop.Analyzers": { + "suppressParent": "All", + "target": "Package", + "version": "[1.1.118, )" + } + } + }, + "net472": { + "projectReferences": {} + } + } + } +} \ No newline at end of file diff --git a/Sources/ThirdPartyLibraries.NuGet.Test/Internal/ProjectAssetsParserTest.projectV4.assets.json b/Sources/ThirdPartyLibraries.NuGet.Test/Internal/ProjectAssetsParserTest.projectV4.assets.json new file mode 100644 index 00000000..aaf538dc --- /dev/null +++ b/Sources/ThirdPartyLibraries.NuGet.Test/Internal/ProjectAssetsParserTest.projectV4.assets.json @@ -0,0 +1,397 @@ +{ + "version": 4, + "targets": { + "netstandard2.1": { + "ConfigureAwaitChecker.Analyzer/5.0.0.1": { + "type": "package" + }, + "Microsoft.Bcl.AsyncInterfaces/10.0.0": { + "type": "package", + "compile": { + "lib/netstandard2.1/Microsoft.Bcl.AsyncInterfaces.dll": { + "related": ".xml" + } + }, + "runtime": { + "lib/netstandard2.1/Microsoft.Bcl.AsyncInterfaces.dll": { + "related": ".xml" + } + } + }, + "Microsoft.Build.Tasks.Git/8.0.0": { + "type": "package", + "build": { + "build/Microsoft.Build.Tasks.Git.props": {}, + "build/Microsoft.Build.Tasks.Git.targets": {} + }, + "buildMultiTargeting": { + "buildMultiTargeting/Microsoft.Build.Tasks.Git.props": {}, + "buildMultiTargeting/Microsoft.Build.Tasks.Git.targets": {} + } + }, + "Microsoft.Extensions.Configuration/10.0.0": { + "type": "package", + "dependencies": { + "Microsoft.Extensions.Configuration.Abstractions": "10.0.0", + "Microsoft.Extensions.Primitives": "10.0.0" + }, + "compile": { + "lib/netstandard2.0/Microsoft.Extensions.Configuration.dll": { + "related": ".xml" + } + }, + "runtime": { + "lib/netstandard2.0/Microsoft.Extensions.Configuration.dll": { + "related": ".xml" + } + } + }, + "Microsoft.Extensions.Configuration.Abstractions/10.0.0": { + "type": "package", + "dependencies": { + "Microsoft.Extensions.Primitives": "10.0.0" + }, + "compile": { + "lib/netstandard2.0/Microsoft.Extensions.Configuration.Abstractions.dll": { + "related": ".xml" + } + }, + "runtime": { + "lib/netstandard2.0/Microsoft.Extensions.Configuration.Abstractions.dll": { + "related": ".xml" + } + } + }, + "Microsoft.Extensions.Configuration.Binder/10.0.0": { + "type": "package", + "dependencies": { + "Microsoft.Extensions.Configuration": "10.0.0", + "Microsoft.Extensions.Configuration.Abstractions": "10.0.0" + }, + "compile": { + "lib/netstandard2.0/Microsoft.Extensions.Configuration.Binder.dll": { + "related": ".xml" + } + }, + "runtime": { + "lib/netstandard2.0/Microsoft.Extensions.Configuration.Binder.dll": { + "related": ".xml" + } + }, + "build": { + "buildTransitive/netstandard2.0/Microsoft.Extensions.Configuration.Binder.targets": {} + } + }, + "Microsoft.Extensions.DependencyInjection/10.0.0": { + "type": "package", + "dependencies": { + "Microsoft.Extensions.DependencyInjection.Abstractions": "10.0.0" + }, + "compile": { + "lib/netstandard2.1/Microsoft.Extensions.DependencyInjection.dll": { + "related": ".xml" + } + }, + "runtime": { + "lib/netstandard2.1/Microsoft.Extensions.DependencyInjection.dll": { + "related": ".xml" + } + } + }, + "Microsoft.Extensions.DependencyInjection.Abstractions/10.0.0": { + "type": "package", + "compile": { + "lib/netstandard2.1/Microsoft.Extensions.DependencyInjection.Abstractions.dll": {} + }, + "runtime": { + "lib/netstandard2.1/Microsoft.Extensions.DependencyInjection.Abstractions.dll": {} + } + }, + "Microsoft.Extensions.Options/10.0.0": { + "type": "package", + "dependencies": { + "Microsoft.Extensions.DependencyInjection.Abstractions": "10.0.0", + "Microsoft.Extensions.Primitives": "10.0.0", + "System.ComponentModel.Annotations": "5.0.0" + }, + "compile": { + "lib/netstandard2.1/Microsoft.Extensions.Options.dll": { + "related": ".xml" + } + }, + "runtime": { + "lib/netstandard2.1/Microsoft.Extensions.Options.dll": { + "related": ".xml" + } + }, + "build": { + "buildTransitive/netstandard2.0/Microsoft.Extensions.Options.targets": {} + } + }, + "Microsoft.Extensions.Options.ConfigurationExtensions/10.0.0": { + "type": "package", + "dependencies": { + "Microsoft.Extensions.Configuration.Abstractions": "10.0.0", + "Microsoft.Extensions.Configuration.Binder": "10.0.0", + "Microsoft.Extensions.DependencyInjection.Abstractions": "10.0.0", + "Microsoft.Extensions.Options": "10.0.0", + "Microsoft.Extensions.Primitives": "10.0.0" + }, + "compile": { + "lib/netstandard2.0/Microsoft.Extensions.Options.ConfigurationExtensions.dll": { + "related": ".xml" + } + }, + "runtime": { + "lib/netstandard2.0/Microsoft.Extensions.Options.ConfigurationExtensions.dll": { + "related": ".xml" + } + } + }, + "Microsoft.Extensions.Primitives/10.0.0": { + "type": "package", + "dependencies": { + "System.Memory": "4.6.3", + "System.Runtime.CompilerServices.Unsafe": "6.1.2" + }, + "compile": { + "lib/netstandard2.0/Microsoft.Extensions.Primitives.dll": { + "related": ".xml" + } + }, + "runtime": { + "lib/netstandard2.0/Microsoft.Extensions.Primitives.dll": { + "related": ".xml" + } + } + }, + "Microsoft.SourceLink.Common/8.0.0": { + "type": "package", + "build": { + "build/Microsoft.SourceLink.Common.props": {}, + "build/Microsoft.SourceLink.Common.targets": {} + }, + "buildMultiTargeting": { + "buildMultiTargeting/Microsoft.SourceLink.Common.props": {}, + "buildMultiTargeting/Microsoft.SourceLink.Common.targets": {} + } + }, + "Microsoft.SourceLink.GitHub/8.0.0": { + "type": "package", + "dependencies": { + "Microsoft.Build.Tasks.Git": "8.0.0", + "Microsoft.SourceLink.Common": "8.0.0" + }, + "build": { + "build/Microsoft.SourceLink.GitHub.props": {}, + "build/Microsoft.SourceLink.GitHub.targets": {} + }, + "buildMultiTargeting": { + "buildMultiTargeting/Microsoft.SourceLink.GitHub.props": {}, + "buildMultiTargeting/Microsoft.SourceLink.GitHub.targets": {} + } + }, + "StyleCop.Analyzers.Unstable/1.2.0.556": { + "type": "package" + }, + "System.Buffers/4.6.1": { + "type": "package", + "compile": { + "lib/netstandard2.1/_._": {} + }, + "runtime": { + "lib/netstandard2.1/_._": {} + } + }, + "System.ComponentModel.Annotations/5.0.0": { + "type": "package", + "compile": { + "ref/netstandard2.1/System.ComponentModel.Annotations.dll": { + "related": ".xml" + } + }, + "runtime": { + "lib/netstandard2.1/System.ComponentModel.Annotations.dll": { + "related": ".xml" + } + } + }, + "System.IO.Pipelines/10.0.0": { + "type": "package", + "dependencies": { + "System.Buffers": "4.6.1", + "System.Memory": "4.6.3", + "System.Threading.Tasks.Extensions": "4.6.3" + }, + "compile": { + "lib/netstandard2.0/System.IO.Pipelines.dll": { + "related": ".xml" + } + }, + "runtime": { + "lib/netstandard2.0/System.IO.Pipelines.dll": { + "related": ".xml" + } + } + }, + "System.Memory/4.6.3": { + "type": "package", + "compile": { + "lib/netstandard2.1/_._": {} + }, + "runtime": { + "lib/netstandard2.1/_._": {} + } + }, + "System.Runtime.CompilerServices.Unsafe/6.1.2": { + "type": "package", + "compile": { + "lib/netstandard2.0/System.Runtime.CompilerServices.Unsafe.dll": { + "related": ".xml" + } + }, + "runtime": { + "lib/netstandard2.0/System.Runtime.CompilerServices.Unsafe.dll": { + "related": ".xml" + } + } + }, + "System.Text.Encodings.Web/10.0.0": { + "type": "package", + "dependencies": { + "System.Buffers": "4.6.1", + "System.Memory": "4.6.3", + "System.Runtime.CompilerServices.Unsafe": "6.1.2" + }, + "compile": { + "lib/netstandard2.0/System.Text.Encodings.Web.dll": { + "related": ".xml" + } + }, + "runtime": { + "lib/netstandard2.0/System.Text.Encodings.Web.dll": { + "related": ".xml" + } + } + }, + "System.Text.Json/10.0.0": { + "type": "package", + "dependencies": { + "Microsoft.Bcl.AsyncInterfaces": "10.0.0", + "System.Buffers": "4.6.1", + "System.IO.Pipelines": "10.0.0", + "System.Memory": "4.6.3", + "System.Runtime.CompilerServices.Unsafe": "6.1.2", + "System.Text.Encodings.Web": "10.0.0", + "System.Threading.Tasks.Extensions": "4.6.3" + }, + "compile": { + "lib/netstandard2.0/System.Text.Json.dll": { + "related": ".xml" + } + }, + "runtime": { + "lib/netstandard2.0/System.Text.Json.dll": { + "related": ".xml" + } + }, + "build": { + "buildTransitive/netstandard2.0/System.Text.Json.targets": {} + } + }, + "System.Threading.Tasks.Extensions/4.6.3": { + "type": "package", + "compile": { + "lib/netstandard2.1/_._": {} + }, + "runtime": { + "lib/netstandard2.1/_._": {} + } + }, + "ThirdPartyLibraries.Domain/3.11.0": { + "type": "project", + "framework": ".NETStandard,Version=v2.1", + "compile": { + "bin/placeholder/ThirdPartyLibraries.Domain.dll": {} + }, + "runtime": { + "bin/placeholder/ThirdPartyLibraries.Domain.dll": {} + } + }, + "ThirdPartyLibraries.Shared/3.11.0": { + "type": "project", + "framework": ".NETStandard,Version=v2.1", + "dependencies": { + "Microsoft.Extensions.DependencyInjection": "10.0.0", + "System.Text.Json": "10.0.0" + }, + "compile": { + "bin/placeholder/ThirdPartyLibraries.Shared.dll": {} + }, + "runtime": { + "bin/placeholder/ThirdPartyLibraries.Shared.dll": {} + } + } + } + }, + "project": { + "version": "3.11.0", + "restore": { + "projectName": "Company.Name.Project", + "originalTargetFrameworks": [ + "netstandard2.1" + ], + "sources": { + "https://api.nuget.org/v3/index.json": {} + }, + "frameworks": { + "netstandard2.1": { + "framework": "netstandard2.1", + "targetAlias": "netstandard2.1", + "projectReferences": {} + } + } + }, + "frameworks": { + "netstandard2.1": { + "framework": "netstandard2.1", + "targetAlias": "netstandard2.1", + "dependencies": { + "ConfigureAwaitChecker.Analyzer": { + "suppressParent": "All", + "target": "Package", + "version": "[5.0.0.1, )", + "versionCentrallyManaged": true + }, + "Microsoft.Extensions.Configuration.Binder": { + "target": "Package", + "version": "[10.0.0, )", + "versionCentrallyManaged": true + }, + "Microsoft.Extensions.Options.ConfigurationExtensions": { + "target": "Package", + "version": "[10.0.0, )", + "versionCentrallyManaged": true + }, + "Microsoft.SourceLink.GitHub": { + "suppressParent": "All", + "target": "Package", + "version": "[8.0.0, )", + "versionCentrallyManaged": true + }, + "StyleCop.Analyzers.Unstable": { + "suppressParent": "All", + "target": "Package", + "version": "[1.2.0.556, )", + "versionCentrallyManaged": true + } + }, + "frameworkReferences": { + "NETStandard.Library": { + "privateAssets": "all" + } + } + } + } + } +} \ No newline at end of file diff --git a/Sources/ThirdPartyLibraries.NuGet.Test/Internal/ProjectAssetsParserV3Test.cs b/Sources/ThirdPartyLibraries.NuGet.Test/Internal/ProjectAssetsParserV3Test.cs new file mode 100644 index 00000000..9afcd9a1 --- /dev/null +++ b/Sources/ThirdPartyLibraries.NuGet.Test/Internal/ProjectAssetsParserV3Test.cs @@ -0,0 +1,77 @@ +using NUnit.Framework; +using Shouldly; + +namespace ThirdPartyLibraries.NuGet.Internal; + +[TestFixture] +public class ProjectAssetsParserV3Test +{ + [Test] + public void GetTargetFrameworks() + { + var actual = CreateSut().GetTargetFrameworks(); + + actual.ShouldBe(["net452", "netcoreapp2.2", "net472"], ignoreOrder: true); + } + + [Test] + public void GetNet452References() + { + var actual = CreateSut().GetReferences("net452").ToList(); + + actual.Count.ShouldBe(1); + + actual[0].Package.Name.ShouldBe("StyleCop.Analyzers"); + actual[0].Package.Version.ShouldBe("1.1.118"); + } + + [Test] + public void GetNetCore22References() + { + var actual = CreateSut().GetReferences("netcoreapp2.2").ToList(); + + actual.Count.ShouldBe(11); + actual[2].Package.Name.ShouldBe("System.Configuration.ConfigurationManager"); + actual[2].Package.Version.ShouldBe("4.5.0"); + + var dependencies = actual[2].Dependencies; + dependencies.Count.ShouldBe(2); + + dependencies[0].Name.ShouldBe("System.Security.Cryptography.ProtectedData"); + dependencies[0].Version.ShouldBe("4.5.0"); + + dependencies[1].Name.ShouldBe("System.Security.Permissions"); + dependencies[1].Version.ShouldBe("4.5.0"); + } + + [Test] + public void GetNet472References() + { + var actual = CreateSut().GetReferences("net472").ToList(); + + actual.ShouldBeEmpty(); + } + + [Test] + public void GetProjectName() + { + CreateSut().GetProjectName().ShouldBe("Company.Name.Project"); + } + + [Test] + public void GetPackageSources() + { + CreateSut().GetPackageSources().ShouldBe( + [ + new Uri(@"C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\", UriKind.Absolute), + new Uri("https://api.nuget.org/v3/index.json", UriKind.Absolute) + ]); + } + + private static ProjectAssetsParser CreateSut() + { + var resourceName = "ProjectAssetsParserTest.projectV3.assets.json"; + using var stream = TempFile.OpenResource(typeof(ProjectAssetsParserTest), resourceName); + return ProjectAssetsParser.FromStream(stream); + } +} \ No newline at end of file diff --git a/Sources/ThirdPartyLibraries.NuGet.Test/Internal/ProjectAssetsParserV4Test.cs b/Sources/ThirdPartyLibraries.NuGet.Test/Internal/ProjectAssetsParserV4Test.cs new file mode 100644 index 00000000..355b5105 --- /dev/null +++ b/Sources/ThirdPartyLibraries.NuGet.Test/Internal/ProjectAssetsParserV4Test.cs @@ -0,0 +1,47 @@ +using NUnit.Framework; +using Shouldly; + +namespace ThirdPartyLibraries.NuGet.Internal; + +[TestFixture] +public class ProjectAssetsParserV4Test +{ + [Test] + public void GetTargetFrameworks() + { + var actual = CreateSut().GetTargetFrameworks(); + + actual.ShouldBe(["netstandard2.1"]); + } + + [Test] + public void GetNetStandard21References() + { + var actual = CreateSut().GetReferences("netstandard2.1").ToList(); + + actual.Count.ShouldBe(12); + + actual[1].Package.Name.ShouldBe("Microsoft.Extensions.Configuration.Binder"); + actual[1].Package.Version.ShouldBe("10.0.0"); + actual[1].Dependencies.Select(i => i.Name).ShouldBe(["Microsoft.Extensions.Configuration", "Microsoft.Extensions.Configuration.Abstractions"]); + } + + [Test] + public void GetProjectName() + { + CreateSut().GetProjectName().ShouldBe("Company.Name.Project"); + } + + [Test] + public void GetPackageSources() + { + CreateSut().GetPackageSources().ShouldBe([new Uri("https://api.nuget.org/v3/index.json", UriKind.Absolute)]); + } + + private static ProjectAssetsParser CreateSut() + { + var resourceName = "ProjectAssetsParserTest.projectV4.assets.json"; + using var stream = TempFile.OpenResource(typeof(ProjectAssetsParserTest), resourceName); + return ProjectAssetsParser.FromStream(stream); + } +} \ No newline at end of file diff --git a/Sources/ThirdPartyLibraries.NuGet/Internal/Domain/DomainJsonSerializerContext.cs b/Sources/ThirdPartyLibraries.NuGet/Internal/Domain/DomainJsonSerializerContext.cs index 27c51f85..76c1d4f0 100644 --- a/Sources/ThirdPartyLibraries.NuGet/Internal/Domain/DomainJsonSerializerContext.cs +++ b/Sources/ThirdPartyLibraries.NuGet/Internal/Domain/DomainJsonSerializerContext.cs @@ -4,5 +4,7 @@ namespace ThirdPartyLibraries.NuGet.Internal.Domain; [JsonSerializable(typeof(ProjectAssetsJson))] +[JsonSerializable(typeof(ProjectAssetsProjectFrameworkJson))] +[JsonSerializable(typeof(ProjectAssetsProjectFrameworkDependencyJson))] [JsonSourceGenerationOptions(JsonSerializerDefaults.Web, AllowTrailingCommas = true, NumberHandling = JsonNumberHandling.AllowReadingFromString)] internal sealed partial class DomainJsonSerializerContext : JsonSerializerContext; \ No newline at end of file diff --git a/Sources/ThirdPartyLibraries.NuGet/Internal/Domain/ProjectAssetsJson.cs b/Sources/ThirdPartyLibraries.NuGet/Internal/Domain/ProjectAssetsJson.cs index 211d070d..bff958ac 100644 --- a/Sources/ThirdPartyLibraries.NuGet/Internal/Domain/ProjectAssetsJson.cs +++ b/Sources/ThirdPartyLibraries.NuGet/Internal/Domain/ProjectAssetsJson.cs @@ -9,4 +9,19 @@ internal sealed class ProjectAssetsJson public JsonElement Targets { get; set; } public ProjectAssetsProjectJson Project { get; set; } = null!; + + internal JsonElement.ObjectEnumerator EnumerateTargetItems(string targetName, string? targetAlternativeName) + { + var target = Targets + .EnumerateObject() + .FirstOrDefault(i => i.Name.Equals(targetName, StringComparison.OrdinalIgnoreCase) || i.Name.Equals(targetAlternativeName, StringComparison.OrdinalIgnoreCase)); + if (target.Value.ValueKind != JsonValueKind.Object) + { + var names = Targets.EnumerateObject().Select(i => i.Name); + var namesText = string.Join(", ", names); + throw new InvalidOperationException($"targets/{targetName} and targets/{targetAlternativeName} not found in [{namesText}]."); + } + + return target.Value.EnumerateObject(); + } } \ No newline at end of file diff --git a/Sources/ThirdPartyLibraries.NuGet/Internal/Domain/ProjectAssetsProjectFrameworkDependencyJson.cs b/Sources/ThirdPartyLibraries.NuGet/Internal/Domain/ProjectAssetsProjectFrameworkDependencyJson.cs new file mode 100644 index 00000000..071374e7 --- /dev/null +++ b/Sources/ThirdPartyLibraries.NuGet/Internal/Domain/ProjectAssetsProjectFrameworkDependencyJson.cs @@ -0,0 +1,11 @@ +using System.Text.Json.Serialization; + +namespace ThirdPartyLibraries.NuGet.Internal.Domain; + +internal sealed class ProjectAssetsProjectFrameworkDependencyJson +{ + [JsonIgnore] + public string Name { get; set; } = null!; + + public string? Target { get; set; } +} \ No newline at end of file diff --git a/Sources/ThirdPartyLibraries.NuGet/Internal/Domain/ProjectAssetsProjectFrameworkJson.cs b/Sources/ThirdPartyLibraries.NuGet/Internal/Domain/ProjectAssetsProjectFrameworkJson.cs new file mode 100644 index 00000000..41602a81 --- /dev/null +++ b/Sources/ThirdPartyLibraries.NuGet/Internal/Domain/ProjectAssetsProjectFrameworkJson.cs @@ -0,0 +1,20 @@ +using System.Text.Json; + +namespace ThirdPartyLibraries.NuGet.Internal.Domain; + +internal sealed class ProjectAssetsProjectFrameworkJson +{ + public string? TargetAlias { get; set; } + + public JsonElement Dependencies { get; set; } + + internal IEnumerable EnumerateDependencies() + { + foreach (var row in Dependencies.EnumerateObject()) + { + var dependency = row.Value.Deserialize(DomainJsonSerializerContext.Default.ProjectAssetsProjectFrameworkDependencyJson); + dependency!.Name = row.Name; + yield return dependency; + } + } +} \ No newline at end of file diff --git a/Sources/ThirdPartyLibraries.NuGet/Internal/Domain/ProjectAssetsProjectJson.cs b/Sources/ThirdPartyLibraries.NuGet/Internal/Domain/ProjectAssetsProjectJson.cs index 93dfa995..31a9f20f 100644 --- a/Sources/ThirdPartyLibraries.NuGet/Internal/Domain/ProjectAssetsProjectJson.cs +++ b/Sources/ThirdPartyLibraries.NuGet/Internal/Domain/ProjectAssetsProjectJson.cs @@ -7,4 +7,16 @@ internal sealed class ProjectAssetsProjectJson public ProjectAssetsProjectRestoreJson Restore { get; set; } = null!; public JsonElement Frameworks { get; set; } + + internal ProjectAssetsProjectFrameworkJson FindFramework(string name) + { + if (!Frameworks.TryGetProperty(name, out var framework)) + { + var names = Frameworks.EnumerateObject().Select(i => i.Name); + var namesText = string.Join(", ", names); + throw new InvalidOperationException($"project/frameworks/{name} not found in [{namesText}]."); + } + + return framework.Deserialize(DomainJsonSerializerContext.Default.ProjectAssetsProjectFrameworkJson)!; + } } \ No newline at end of file diff --git a/Sources/ThirdPartyLibraries.NuGet/Internal/Domain/ProjectAssetsTargetItemJson.cs b/Sources/ThirdPartyLibraries.NuGet/Internal/Domain/ProjectAssetsTargetItemJson.cs new file mode 100644 index 00000000..36fd3e58 --- /dev/null +++ b/Sources/ThirdPartyLibraries.NuGet/Internal/Domain/ProjectAssetsTargetItemJson.cs @@ -0,0 +1,11 @@ +using System.Text.Json.Serialization; + +namespace ThirdPartyLibraries.NuGet.Internal.Domain; + +internal sealed class ProjectAssetsTargetItemJson +{ + [JsonIgnore] + public string Name { get; set; } = null!; + + public string? Type { get; set; } +} \ No newline at end of file diff --git a/Sources/ThirdPartyLibraries.NuGet/Internal/ProjectAssetsParser.cs b/Sources/ThirdPartyLibraries.NuGet/Internal/ProjectAssetsParser.cs index 9834d925..266c155e 100644 --- a/Sources/ThirdPartyLibraries.NuGet/Internal/ProjectAssetsParser.cs +++ b/Sources/ThirdPartyLibraries.NuGet/Internal/ProjectAssetsParser.cs @@ -12,7 +12,7 @@ internal readonly struct ProjectAssetsParser public ProjectAssetsParser(ProjectAssetsJson content) { - if (content.Version != 3) + if (content.Version < 3 || content.Version > 4) { throw new NotSupportedException($"{FileName} version {content.Version} is not supported"); } @@ -46,26 +46,22 @@ public string[] GetTargetFrameworks() public IEnumerable<(LibraryId Package, List Dependencies)> GetReferences(string targetFramework) { - var framework = MapTargetFrameworkProjFormatToNuGetFormat(targetFramework); - - var projectFrameworks = Content.Project.Frameworks; - if (!projectFrameworks.TryGetProperty(targetFramework, out var projectFramework)) - { - var frameworks = projectFrameworks.EnumerateObject().Select(i => i.Name); - var frameworksText = string.Join(", ", frameworks); - throw new InvalidOperationException($"project/frameworks/{targetFramework} not found in {frameworksText}."); - } - - if (!projectFramework.TryGetProperty("dependencies", out var projectDependencies)) + var projectFramework = Content.Project.FindFramework(targetFramework); + if (projectFramework.Dependencies.ValueKind == JsonValueKind.Undefined) { return []; } - var targetPackageByName = ParseTarget(framework); - foreach (var row in projectDependencies.EnumerateObject()) + // v3 and v4: project/frameworks/netstandard2.1 { targetAlias:netstandard2.1 } + // v3: targets/.NETStandard,Version=v2.1 + // v4: targets/netstandard2.1 + var frameworkName = MapTargetFrameworkProjFormatToNuGetFormat(targetFramework); + var frameworkAlternativeName = projectFramework.TargetAlias; + + var targetPackageByName = ParseTarget(frameworkName, frameworkAlternativeName); + foreach (var row in projectFramework.EnumerateDependencies()) { - var targetName = row.Value.GetProperty("target").GetString(); - if (!"package".Equals(targetName, StringComparison.OrdinalIgnoreCase)) + if (!"package".Equals(row.Target, StringComparison.OrdinalIgnoreCase)) { continue; } @@ -138,20 +134,13 @@ private static void AddPackage( } } - private IDictionary ParseTarget(string frameworkName) + private IDictionary ParseTarget(string frameworkName, string? frameworkAlternativeName) { - var targets = Content.Targets; - var target = targets.EnumerateObject().FirstOrDefault(i => i.Name.Equals(frameworkName, StringComparison.OrdinalIgnoreCase)); - if (target.Value.ValueKind != JsonValueKind.Object) - { - var frameworks = targets.EnumerateObject().Select(i => i.Name); - var frameworksText = string.Join(", ", frameworks); - throw new InvalidOperationException($"Target {frameworkName} not found in {frameworksText}."); - } + var targetItems = Content.EnumerateTargetItems(frameworkName, frameworkAlternativeName); var result = new Dictionary(StringComparer.OrdinalIgnoreCase); - foreach (var row in target.Value.EnumerateObject()) + foreach (var row in targetItems) { var type = row.Value.GetProperty("type").GetString(); if ("package".Equals(type, StringComparison.OrdinalIgnoreCase))