Merge pull request #9911 from livarcocc/fix_nuget_config_tests
Write ExternalRestoreSources to some tests NuGet.Config file
This commit is contained in:
commit
9ba8d04c6b
5 changed files with 51 additions and 4 deletions
|
@ -10,6 +10,7 @@
|
||||||
<TestPackagesDir>$(TestOutputDir)/packages/</TestPackagesDir>
|
<TestPackagesDir>$(TestOutputDir)/packages/</TestPackagesDir>
|
||||||
<TestArtifactsDir>$(TestOutputDir)/artifacts/</TestArtifactsDir>
|
<TestArtifactsDir>$(TestOutputDir)/artifacts/</TestArtifactsDir>
|
||||||
<TestResultXmlDir>$(TestOutputDir)/results/</TestResultXmlDir>
|
<TestResultXmlDir>$(TestOutputDir)/results/</TestResultXmlDir>
|
||||||
|
<ExternalRestoreSourcesTestsContainer>$(TestArtifactsDir)/ExternalRestoreSourcesForTestsContainer.txt</ExternalRestoreSourcesTestsContainer>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<Target Name="Test"
|
<Target Name="Test"
|
||||||
|
@ -51,6 +52,11 @@
|
||||||
DependsOnTargets="Init;
|
DependsOnTargets="Init;
|
||||||
SetupTestProjectData">
|
SetupTestProjectData">
|
||||||
<MakeDir Directories="$(TestPackagesDir)" Condition="!Exists('$(TestPackagesDir)')"/>
|
<MakeDir Directories="$(TestPackagesDir)" Condition="!Exists('$(TestPackagesDir)')"/>
|
||||||
|
|
||||||
|
<WriteLinesToFile Condition="'$(ExternalRestoreSources)' != ''"
|
||||||
|
File="$(ExternalRestoreSourcesTestsContainer)"
|
||||||
|
Lines="<add key="PrivateBlobFeed%(NugetConfigPrivateFeeds.Identity)" value="%(NugetConfigPrivateFeeds.Identity)" />"
|
||||||
|
Overwrite="false" />
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
<Target Name="RestoreTests"
|
<Target Name="RestoreTests"
|
||||||
|
|
|
@ -339,7 +339,7 @@ namespace Microsoft.DotNet.Tests
|
||||||
var testInstance = TestAssets.Get("AppWithFallbackFolderToolDependency")
|
var testInstance = TestAssets.Get("AppWithFallbackFolderToolDependency")
|
||||||
.CreateInstance()
|
.CreateInstance()
|
||||||
.WithSourceFiles()
|
.WithSourceFiles()
|
||||||
.WithNuGetConfig(new RepoDirectoriesProvider().TestPackages);
|
.WithNuGetConfigAndExternalRestoreSources(new RepoDirectoriesProvider().TestPackages);
|
||||||
var testProjectDirectory = testInstance.Root.FullName;
|
var testProjectDirectory = testInstance.Root.FullName;
|
||||||
var fallbackFolder = Path.Combine(testProjectDirectory, "fallbackFolder");
|
var fallbackFolder = Path.Combine(testProjectDirectory, "fallbackFolder");
|
||||||
|
|
||||||
|
@ -382,7 +382,7 @@ namespace Microsoft.DotNet.Tests
|
||||||
var testInstance = TestAssets.Get("AppWithFallbackFolderToolDependency")
|
var testInstance = TestAssets.Get("AppWithFallbackFolderToolDependency")
|
||||||
.CreateInstance()
|
.CreateInstance()
|
||||||
.WithSourceFiles()
|
.WithSourceFiles()
|
||||||
.WithNuGetConfig(new RepoDirectoriesProvider().TestPackages);
|
.WithNuGetConfigAndExternalRestoreSources(new RepoDirectoriesProvider().TestPackages);
|
||||||
var testProjectDirectory = testInstance.Root.FullName;
|
var testProjectDirectory = testInstance.Root.FullName;
|
||||||
var fallbackFolder = Path.Combine(testProjectDirectory, "fallbackFolder");
|
var fallbackFolder = Path.Combine(testProjectDirectory, "fallbackFolder");
|
||||||
|
|
||||||
|
|
|
@ -109,19 +109,23 @@ namespace Microsoft.DotNet.TestFramework
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TestAssetInstance WithNuGetConfig(string nugetCache)
|
public TestAssetInstance WithNuGetConfig(string nugetCache, string externalRestoreSources = null)
|
||||||
{
|
{
|
||||||
var thisAssembly = typeof(TestAssetInstance).GetTypeInfo().Assembly;
|
var thisAssembly = typeof(TestAssetInstance).GetTypeInfo().Assembly;
|
||||||
var newNuGetConfig = Root.GetFile("NuGet.Config");
|
var newNuGetConfig = Root.GetFile("NuGet.Config");
|
||||||
|
externalRestoreSources = externalRestoreSources ?? string.Empty;
|
||||||
|
|
||||||
var content = @"<?xml version=""1.0"" encoding=""utf-8""?>
|
var content = @"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<packageSources>
|
<packageSources>
|
||||||
<add key=""dotnet-core"" value=""https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json"" />
|
<add key=""dotnet-core"" value=""https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json"" />
|
||||||
<add key=""test-packages"" value=""$fullpath$"" />
|
<add key=""test-packages"" value=""$fullpath$"" />
|
||||||
|
$externalRestoreSources$
|
||||||
</packageSources>
|
</packageSources>
|
||||||
</configuration>";
|
</configuration>";
|
||||||
content = content.Replace("$fullpath$", nugetCache);
|
content = content
|
||||||
|
.Replace("$fullpath$", nugetCache)
|
||||||
|
.Replace("$externalRestoreSources$", externalRestoreSources);
|
||||||
|
|
||||||
using (var newNuGetConfigStream =
|
using (var newNuGetConfigStream =
|
||||||
new FileStream(newNuGetConfig.FullName, FileMode.Create, FileAccess.Write))
|
new FileStream(newNuGetConfig.FullName, FileMode.Create, FileAccess.Write))
|
||||||
|
|
|
@ -22,6 +22,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||||
private string _stage2WithBackwardsCompatibleRuntimesDirectory;
|
private string _stage2WithBackwardsCompatibleRuntimesDirectory;
|
||||||
private string _testPackages;
|
private string _testPackages;
|
||||||
private string _testWorkingFolder;
|
private string _testWorkingFolder;
|
||||||
|
private string _testArtifactsFolder;
|
||||||
|
|
||||||
public static string RepoRoot
|
public static string RepoRoot
|
||||||
{
|
{
|
||||||
|
@ -92,6 +93,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||||
public string Stage2WithBackwardsCompatibleRuntimesDirectory => _stage2WithBackwardsCompatibleRuntimesDirectory;
|
public string Stage2WithBackwardsCompatibleRuntimesDirectory => _stage2WithBackwardsCompatibleRuntimesDirectory;
|
||||||
public string TestPackages => _testPackages;
|
public string TestPackages => _testPackages;
|
||||||
public string TestWorkingFolder => _testWorkingFolder;
|
public string TestWorkingFolder => _testWorkingFolder;
|
||||||
|
public string TestArtifactsFolder => _testArtifactsFolder;
|
||||||
|
|
||||||
public RepoDirectoriesProvider(
|
public RepoDirectoriesProvider(
|
||||||
string artifacts = null,
|
string artifacts = null,
|
||||||
|
@ -123,6 +125,8 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||||
_testPackages = Path.Combine(_artifacts, "test", "packages");
|
_testPackages = Path.Combine(_artifacts, "test", "packages");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_testArtifactsFolder = Path.Combine(_artifacts, "test", "artifacts");
|
||||||
|
|
||||||
_testWorkingFolder = Path.Combine(RepoRoot,
|
_testWorkingFolder = Path.Combine(RepoRoot,
|
||||||
"bin",
|
"bin",
|
||||||
(previousStage + 1).ToString(),
|
(previousStage + 1).ToString(),
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||||
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
using Microsoft.DotNet.Cli.Utils;
|
||||||
|
using Microsoft.DotNet.TestFramework;
|
||||||
|
using Microsoft.DotNet.Tools.Common;
|
||||||
|
|
||||||
|
namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||||
|
{
|
||||||
|
public static class TestAssetInstanceExtensions
|
||||||
|
{
|
||||||
|
public static TestAssetInstance WithNuGetConfigAndExternalRestoreSources(
|
||||||
|
this TestAssetInstance testAssetInstance, string nugetCache)
|
||||||
|
{
|
||||||
|
var externalRestoreSourcesForTests = Path.Combine(
|
||||||
|
new RepoDirectoriesProvider().TestArtifactsFolder, "ExternalRestoreSourcesForTestsContainer.txt");
|
||||||
|
var externalRestoreSources = File.Exists(externalRestoreSourcesForTests) ?
|
||||||
|
File.ReadAllText(externalRestoreSourcesForTests) :
|
||||||
|
string.Empty;
|
||||||
|
|
||||||
|
return testAssetInstance.WithNuGetConfig(nugetCache, externalRestoreSources);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue