diff --git a/scripts/dotnet-cli-build/TestTargets.cs b/scripts/dotnet-cli-build/TestTargets.cs index 6e28d2c0b..ad79ca4aa 100644 --- a/scripts/dotnet-cli-build/TestTargets.cs +++ b/scripts/dotnet-cli-build/TestTargets.cs @@ -56,6 +56,13 @@ namespace Microsoft.DotNet.Cli.Build [Target] public static BuildTargetResult BuildTestPrerequisites(BuildTargetContext c) + { + BuildTestAssetPackages(c); + BuildTestAssetProjects(c); + return c.Success(); + } + + public static void BuildTestAssetPackages(BuildTargetContext c) { var dotnet = DotNetCli.Stage2; @@ -71,8 +78,24 @@ namespace Microsoft.DotNet.Cli.Build .Execute() .EnsureSuccessful(); } + } - return c.Success(); + public static void BuildTestAssetProjects(BuildTargetContext c) + { + var dotnet = DotNetCli.Stage2; + string testProjectsRoot = Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "TestProjects"); + List exclusionList = new List { Path.Combine(testProjectsRoot, "CompileFail", "project.json") }; + var projects = Directory.GetFiles(testProjectsRoot, "project.json", SearchOption.AllDirectories) + .Where(p => !exclusionList.Any(e => e.Contains(p))); + + foreach (var project in projects) + { + c.Info($"Building: {project}"); + dotnet.Build("--framework", "dnxcore50") + .WorkingDirectory(Path.GetDirectoryName(project)) + .Execute() + .EnsureSuccessful(); + } } [Target] diff --git a/src/Microsoft.DotNet.TestFramework/Microsoft.DotNet.TestFramework.TestAssetsManager.cs b/src/Microsoft.DotNet.TestFramework/Microsoft.DotNet.TestFramework.TestAssetsManager.cs index e4565708e..9d4e59313 100644 --- a/src/Microsoft.DotNet.TestFramework/Microsoft.DotNet.TestFramework.TestAssetsManager.cs +++ b/src/Microsoft.DotNet.TestFramework/Microsoft.DotNet.TestFramework.TestAssetsManager.cs @@ -18,7 +18,7 @@ namespace Microsoft.DotNet.TestFramework get; private set; } - public TestAssetsManager(string assetsRoot, bool skipRestore = true, bool skipBuild = true) + public TestAssetsManager(string assetsRoot, bool doRestore = false, bool doBuild = false) { if (!Directory.Exists(assetsRoot)) { @@ -27,12 +27,12 @@ namespace Microsoft.DotNet.TestFramework AssetsRoot = assetsRoot; - if (!skipRestore) + if (doRestore) { Restore(); } - if (!skipBuild) + if (doBuild) { Build(); } diff --git a/test/dotnet-build.Tests/BuildProjectToProjectTests.cs b/test/dotnet-build.Tests/BuildProjectToProjectTests.cs index dacc29a28..c3b55a740 100644 --- a/test/dotnet-build.Tests/BuildProjectToProjectTests.cs +++ b/test/dotnet-build.Tests/BuildProjectToProjectTests.cs @@ -62,11 +62,13 @@ namespace Microsoft.DotNet.Tools.Builder.Tests [Fact] public void TestNoDependencyFlag() { - var dependencies = new[] { "L11", "L12", "L21", "L22" }; + var testInstance = TestAssetsManager.CreateTestInstance("TestProjectToProjectDependencies") + .WithLockFiles() + .WithBuildArtifacts(); + + TestProjectRoot = testInstance.TestRoot; - // first clean build; all projects required compilation - var result1 = BuildProject(); - AssertRebuilt(result1, _projects); + var dependencies = new[] { "L11", "L12", "L21", "L22" }; // modify the source code of a leaf dependency TouchSourcesOfProject("L22"); diff --git a/test/dotnet-build.Tests/IncrementalTestBase.cs b/test/dotnet-build.Tests/IncrementalTestBase.cs index ca202766e..046f9e781 100644 --- a/test/dotnet-build.Tests/IncrementalTestBase.cs +++ b/test/dotnet-build.Tests/IncrementalTestBase.cs @@ -61,7 +61,7 @@ namespace Microsoft.DotNet.Tools.Builder.Tests protected CommandResult BuildProject(bool noDependencies = false, bool noIncremental = false, bool expectBuildFailure = false) { var mainProjectFile = GetProjectFile(MainProject); - return BuildProject(mainProjectFile, noIncremental, expectBuildFailure); + return BuildProject(mainProjectFile, noDependencies, noIncremental, expectBuildFailure); } protected CommandResult BuildProject(string projectFile, bool noDependencies = false, bool noIncremental = false, bool expectBuildFailure = false) diff --git a/test/dotnet-compile.UnitTests/GivenACompilationDriver.cs b/test/dotnet-compile.UnitTests/GivenACompilationDriver.cs index b0724bd99..0a1e1d47b 100644 --- a/test/dotnet-compile.UnitTests/GivenACompilationDriver.cs +++ b/test/dotnet-compile.UnitTests/GivenACompilationDriver.cs @@ -24,7 +24,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests public GivenACompilationDriverController() { _projectJson = - Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects", "TestApp", "project.json"); + Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects", "TestAppWithLibrary", "TestApp", "project.json"); _managedCompilerMock = new Mock(); _managedCompilerMock.Setup(c => c .Compile(It.IsAny(), It.IsAny())) diff --git a/test/dotnet-compile.UnitTests/GivenThatICareAboutScriptVariablesFromAManagedCompiler.cs b/test/dotnet-compile.UnitTests/GivenThatICareAboutScriptVariablesFromAManagedCompiler.cs index bfb98b0b7..484a482bf 100644 --- a/test/dotnet-compile.UnitTests/GivenThatICareAboutScriptVariablesFromAManagedCompiler.cs +++ b/test/dotnet-compile.UnitTests/GivenThatICareAboutScriptVariablesFromAManagedCompiler.cs @@ -156,6 +156,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests AppContext.BaseDirectory, "TestAssets", "TestProjects", + "TestAppWithLibrary", "TestApp"); public static string OutputPath = Path.Combine( diff --git a/test/dotnet-compile.UnitTests/project.json b/test/dotnet-compile.UnitTests/project.json index 666a1b55b..6f1cc07d6 100644 --- a/test/dotnet-compile.UnitTests/project.json +++ b/test/dotnet-compile.UnitTests/project.json @@ -24,9 +24,7 @@ }, "content": [ - "../../TestAssets/TestProjects/TestLibrary/*", - "../../TestAssets/TestProjects/TestApp/*", - "../../TestAssets/TestProjects/global.json" + "../../TestAssets/TestProjects/TestAppWithLibrary/**/*" ], "testRunner": "xunit"