diff --git a/test/EndToEnd/tests/ServicesTest.ps1 b/test/EndToEnd/tests/ServicesTest.ps1 index a6635f46b3f..2f3a8f87c28 100644 --- a/test/EndToEnd/tests/ServicesTest.ps1 +++ b/test/EndToEnd/tests/ServicesTest.ps1 @@ -1002,3 +1002,21 @@ function Test-InstallPackageAsyncWithPackageReferenceFormat { Assert-AreEqual $packageRefs[0].GetMetadataValue("Identity") 'owin' Assert-AreEqual $packageRefs[0].GetMetadataValue("Version") '1.0.0' } + +function Test-BuildIntegratedProjectInstallPackage { + + # Arrange + $project = New-Project BuildIntegratedClassLibrary Project1 + $id = 'CustomBuildIntegratedProjectInstallPackage' + $version = '1.0.0' + + $solutionFile = Get-SolutionFullName + $solutionDir = Split-Path $solutionFile -Parent + $source = Join-Path $solutionDir "CustomSource" + + # Act + [API.Test.InternalAPITestHook]::InstallPackageApiFromSource($source, $id, $version) + + # Assert + Assert-ProjectJsonLockFilePackage $project $id $version +} diff --git a/test/TestExtensions/API.Test/InternalAPITestHook.cs b/test/TestExtensions/API.Test/InternalAPITestHook.cs index 6feb9aa0923..9e1795a128b 100644 --- a/test/TestExtensions/API.Test/InternalAPITestHook.cs +++ b/test/TestExtensions/API.Test/InternalAPITestHook.cs @@ -4,10 +4,14 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using System.IO; +using System.Runtime.Versioning; using System.Threading.Tasks; using Microsoft.VisualStudio.Shell; using NuGet.Common; using NuGet.PackageManagement.VisualStudio; +using NuGet.Packaging; +using NuGet.Versioning; using NuGet.VisualStudio; using Task = System.Threading.Tasks.Task; @@ -56,6 +60,49 @@ public static void InstallPackageApi(string source, string id, string version, b }); } + public static void InstallPackageApiFromSource(string source, string id, string version) + { + CreatePackage(source, id, version); + InstallPackageApi(source, id, version, prerelease: false); + } + + private static void CreatePackage(string path, string id, string version) + { + var builder = new NuGet.Packaging.PackageBuilder() + { + Id = id, + Version = NuGetVersion.Parse(version), + Description = "Description.", + DevelopmentDependency = false + }; + + builder.Authors.Add("testAuthor"); + builder.Files.Add(CreatePackageFile("lib/net45/a.dll")); + + Directory.CreateDirectory(path); + + using (var stream = File.OpenWrite(Path.Combine(path, $"{id}.{version}.nupkg"))) + { + builder.Save(stream); + } + } + + private static IPackageFile CreatePackageFile(string name) + { + var file = new InMemoryFile + { + Path = name, + Stream = new MemoryStream() + }; + + string effectivePath; + var fx = FrameworkNameUtility.ParseFrameworkNameFromFilePath(name, out effectivePath); + file.EffectivePath = effectivePath; + file.TargetFramework = fx; + + return file; + } + public static void UninstallPackageApi(string id, bool dependency) { ThreadHelper.JoinableTaskFactory.Run( @@ -185,5 +232,26 @@ public static bool IsFileExistsInProject(string projectUniqueName, string filePa return false; }); } + + private class InMemoryFile : IPackageFile + { + private DateTimeOffset _lastWriteTime; + + public string EffectivePath { get; set; } + + public string Path { get; set; } + + public FrameworkName TargetFramework { get; set; } + + public MemoryStream Stream { get; set; } + + public Stream GetStream() + { + _lastWriteTime = DateTimeOffset.UtcNow; + return Stream; + } + + public DateTimeOffset LastWriteTime => _lastWriteTime; + } } }