From dbca182d8c8e72eb806d3423c0fbb54d7dfcf2c4 Mon Sep 17 00:00:00 2001 From: Ankit Mishra Date: Fri, 1 Jun 2018 12:35:19 -0700 Subject: Removing dependency on NuGet.ProjectModel --- .../Json/Json.Designer.cs | 20 ++++ .../Json/Json.resx | 6 ++ .../Json/WithTargets.assets.json | 51 ++++++++++ .../Json/WithoutTargets.assets.json | 39 ++++++++ .../ReferenceResolutionTests.cs | 108 +-------------------- 5 files changed, 121 insertions(+), 103 deletions(-) create mode 100644 src/Microsoft.NuGet.Build.Tasks.Tests/Json/WithTargets.assets.json create mode 100644 src/Microsoft.NuGet.Build.Tasks.Tests/Json/WithoutTargets.assets.json diff --git a/src/Microsoft.NuGet.Build.Tasks.Tests/Json/Json.Designer.cs b/src/Microsoft.NuGet.Build.Tasks.Tests/Json/Json.Designer.cs index e75ea94..9137dec 100644 --- a/src/Microsoft.NuGet.Build.Tasks.Tests/Json/Json.Designer.cs +++ b/src/Microsoft.NuGet.Build.Tasks.Tests/Json/Json.Designer.cs @@ -358,5 +358,25 @@ namespace Microsoft.NuGet.Build.Tasks.Tests.Json { return ResourceManager.GetString("Win10_xunit", resourceCulture); } } + + /// + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] WithoutTargets_assets { + get { + object obj = ResourceManager.GetObject("WithoutTargets_assets", resourceCulture); + return ((byte[])(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] WithTargets_assets { + get { + object obj = ResourceManager.GetObject("WithTargets_assets", resourceCulture); + return ((byte[])(obj)); + } + } } } diff --git a/src/Microsoft.NuGet.Build.Tasks.Tests/Json/Json.resx b/src/Microsoft.NuGet.Build.Tasks.Tests/Json/Json.resx index 993a1fe..0286e1b 100644 --- a/src/Microsoft.NuGet.Build.Tasks.Tests/Json/Json.resx +++ b/src/Microsoft.NuGet.Build.Tasks.Tests/Json/Json.resx @@ -151,4 +151,10 @@ multipleprojectfiledependencygroups_casemismatch.json;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + + WithoutTargets.assets.json;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + WithTargets.assets.json;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + \ No newline at end of file diff --git a/src/Microsoft.NuGet.Build.Tasks.Tests/Json/WithTargets.assets.json b/src/Microsoft.NuGet.Build.Tasks.Tests/Json/WithTargets.assets.json new file mode 100644 index 0000000..bef673f --- /dev/null +++ b/src/Microsoft.NuGet.Build.Tasks.Tests/Json/WithTargets.assets.json @@ -0,0 +1,51 @@ +{ + "version": 2, + "targets": { + ".NETFramework,Version=v4.5": { + "System.Text/4.5.0": { + "type": "package", + "dependencies": { + "System": "4.5.0" + }, + "compile": { + "ref/net45/System.Text.dll": {} + } + } + } + }, + "libraries": { + "System.Text/4.5.0": { + "type": "package", + "path": "system.text/4.5.0" + } + }, + "projectFileDependencyGroups": {}, + "project": { + "version": "1.0.0", + "restore": { + "projectUniqueName": "X:\\ProjectPath\\ProjectPath.csproj", + "projectName": "ProjectPath", + "projectPath": "X:\\ProjectPath\\ProjectPath.csproj", + "outputPath": "X:\\ProjectPath\\obj\\", + "projectStyle": "PackageReference", + "originalTargetFrameworks": [ + "net45" + ], + "frameworks": { + "net45": { + "projectReferences": {} + } + } + }, + "frameworks": { + "net45": { + "dependencies": { + "System.Text": { + "target": "Package", + "version": "[4.5.0, )" + } + } + } + } + } +} \ No newline at end of file diff --git a/src/Microsoft.NuGet.Build.Tasks.Tests/Json/WithoutTargets.assets.json b/src/Microsoft.NuGet.Build.Tasks.Tests/Json/WithoutTargets.assets.json new file mode 100644 index 0000000..4eae5df --- /dev/null +++ b/src/Microsoft.NuGet.Build.Tasks.Tests/Json/WithoutTargets.assets.json @@ -0,0 +1,39 @@ +{ + "version": 2, + "targets": {}, + "libraries": { + "System.Text/4.5.0": { + "type": "package", + "path": "system.text/4.5.0" + } + }, + "projectFileDependencyGroups": {}, + "project": { + "version": "1.0.0", + "restore": { + "projectUniqueName": "X:\\ProjectPath\\ProjectPath.csproj", + "projectName": "ProjectPath", + "projectPath": "X:\\ProjectPath\\ProjectPath.csproj", + "outputPath": "X:\\ProjectPath\\obj\\", + "projectStyle": "PackageReference", + "originalTargetFrameworks": [ + "net45" + ], + "frameworks": { + "net45": { + "projectReferences": {} + } + } + }, + "frameworks": { + "net45": { + "dependencies": { + "System.Text": { + "target": "Package", + "version": "[4.5.0, )" + } + } + } + } + } +} \ No newline at end of file diff --git a/src/Microsoft.NuGet.Build.Tasks.Tests/ReferenceResolutionTests.cs b/src/Microsoft.NuGet.Build.Tasks.Tests/ReferenceResolutionTests.cs index 4990535..180c94f 100644 --- a/src/Microsoft.NuGet.Build.Tasks.Tests/ReferenceResolutionTests.cs +++ b/src/Microsoft.NuGet.Build.Tasks.Tests/ReferenceResolutionTests.cs @@ -2,16 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Linq; +using System.Text; using Microsoft.NuGet.Build.Tasks.Tests.Helpers; -using NuGet.Frameworks; -using NuGet.LibraryModel; -using NuGet.Packaging.Core; -using NuGet.ProjectModel; -using NuGet.Versioning; using Xunit; namespace Microsoft.NuGet.Build.Tasks.Tests @@ -117,16 +111,12 @@ namespace Microsoft.NuGet.Build.Tasks.Tests [Fact] public static void TestReferenceResolutionWithMissingRuntimeIDAndNoFallbackInProjectCsproj() { - var lockFile = GenerateLockFileWithTarget(); - using (var tempRoot = new TempRoot()) using (var disposableFile = new DisposableFile(tempRoot.CreateFile(extension: "assets.json").Path)) { - new LockFileFormat().Write(disposableFile.Path, lockFile); - var exception = Assert.Throws(() => NuGetTestHelpers.ResolvePackagesWithJsonFileContents( - File.ReadAllText(disposableFile.Path), + Encoding.UTF8.GetString(Json.Json.WithTargets_assets, 0, Json.Json.WithTargets_assets.Length), targetMoniker: ".NETFramework,Version=v4.5", runtimeIdentifier: "missing-runtime-identifier", allowFallbackOnTargetSelection: false, @@ -169,16 +159,12 @@ namespace Microsoft.NuGet.Build.Tasks.Tests [Fact] public static void TestReferenceResolutionWithMissingTargetFrameworkAndNoFallbackInProjectCsproj() { - var lockFile = GenerateLockFileWithoutTarget(); - using (var tempRoot = new TempRoot()) using (var disposableFile = new DisposableFile(tempRoot.CreateFile(extension: "assets.json").Path)) { - new LockFileFormat().Write(disposableFile.Path, lockFile); - var exception = Assert.Throws(() => NuGetTestHelpers.ResolvePackagesWithJsonFileContents( - File.ReadAllText(disposableFile.Path), + Encoding.UTF8.GetString(Json.Json.WithoutTargets_assets, 0, Json.Json.WithoutTargets_assets.Length), targetMoniker: "Missing,Version=1.0", runtimeIdentifier: "missing-runtime-identifier", allowFallbackOnTargetSelection: false, @@ -206,15 +192,11 @@ namespace Microsoft.NuGet.Build.Tasks.Tests [Fact] public static void TestReferenceResolutionWithMissingTargetFrameworkAndFallbackInProjectCsproj() { - var lockFile = GenerateLockFileWithTarget(); - using (var tempRoot = new TempRoot()) using (var disposableFile = new DisposableFile(tempRoot.CreateFile(extension: "assets.json").Path)) { - new LockFileFormat().Write(disposableFile.Path, lockFile); - var result = NuGetTestHelpers.ResolvePackagesWithJsonFileContents( - File.ReadAllText(disposableFile.Path), + Encoding.UTF8.GetString(Json.Json.WithTargets_assets, 0, Json.Json.WithTargets_assets.Length), targetMoniker: "MissingFrameworkMoniker,Version=v42.0", runtimeIdentifier: "", allowFallbackOnTargetSelection: true, @@ -231,16 +213,12 @@ namespace Microsoft.NuGet.Build.Tasks.Tests [InlineData(false, nameof(Strings.NoTargetsInLockFileForProjectFile))] public static void TestReferenceResolutionWithMissingTargets(bool isProjectJsonBased, string errorResourceName) { - var lockFile = GenerateLockFileWithoutTarget(); - using (var tempRoot = new TempRoot()) using (var disposableFile = new DisposableFile(tempRoot.CreateFile(extension: "assets.json").Path)) { - new LockFileFormat().Write(disposableFile.Path, lockFile); - var exception = Assert.Throws(() => NuGetTestHelpers.ResolvePackagesWithJsonFileContents( - File.ReadAllText(disposableFile.Path), + Encoding.UTF8.GetString(Json.Json.WithoutTargets_assets, 0, Json.Json.WithoutTargets_assets.Length), targetMoniker: "MissingFrameworkMoniker,Version=v42.0", runtimeIdentifier: "", allowFallbackOnTargetSelection: true, @@ -566,81 +544,5 @@ namespace Microsoft.NuGet.Build.Tasks.Tests Assert.DoesNotContain("ClassLibrary1", result.ReferencedPackages.Select(t => t.ItemSpec)); } - private static LockFile GenerateLockFileWithoutTarget() - { - return new LockFile - { - Version = 2, - PackageSpec = new PackageSpec(new TargetFrameworkInformation[] - { - new TargetFrameworkInformation - { - FrameworkName = FrameworkConstants.CommonFrameworks.Net45, - Dependencies = new[] - { - new LibraryDependency - { - LibraryRange = new LibraryRange( - "System.Text", - new VersionRange( - minVersion: new NuGetVersion("4.5.0"), - originalString: "4.5.0"), - LibraryDependencyTarget.Package) - } - } - } - }) - { - Version = new NuGetVersion("1.0.0"), - RestoreMetadata = new ProjectRestoreMetadata - { - ProjectUniqueName = @"X:\ProjectPath\ProjectPath.csproj", - ProjectName = "ProjectPath", - ProjectPath = @"X:\ProjectPath\ProjectPath.csproj", - OutputPath = @"X:\ProjectPath\obj\", - ProjectStyle = ProjectStyle.PackageReference, - OriginalTargetFrameworks = new string[] { "net45" }, - TargetFrameworks = new List - { - new ProjectRestoreMetadataFrameworkInfo(NuGetFramework.Parse("net45")) - } - } - }, - Libraries = new LockFileLibrary[] - { - new LockFileLibrary() - { - Name = "System.Text", - Version = NuGetVersion.Parse("4.5.0"), - Path = "system.text/4.5.0", - Type = LibraryType.Package - } - } - }; - } - - private static LockFile GenerateLockFileWithTarget() - { - var lockFile = GenerateLockFileWithoutTarget(); - - var target = new LockFileTarget() - { - TargetFramework = FrameworkConstants.CommonFrameworks.Net45 - }; - - var targetLib = new LockFileTargetLibrary() - { - Name = "System.Text", - Version = new NuGetVersion("4.5.0"), - Type = LibraryType.Package - }; - - targetLib.Dependencies.Add(new PackageDependency("System", new VersionRange(NuGetVersion.Parse("4.5.0")))); - targetLib.CompileTimeAssemblies.Add(new LockFileItem("ref/net45/System.Text.dll")); - target.Libraries.Add(targetLib); - lockFile.Targets.Add(target); - - return lockFile; - } } } -- cgit v1.2.3