diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/GenerateDepsFile.cs b/src/Tasks/Microsoft.NET.Build.Tasks/GenerateDepsFile.cs index c6cbf051ca2e..eeb261e925cf 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/GenerateDepsFile.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/GenerateDepsFile.cs @@ -55,6 +55,14 @@ public class GenerateDepsFile : TaskBase public ITaskItem[] PrivateAssetsPackageReferences { get; set; } + List _filesWritten = new List(); + + [Output] + public ITaskItem[] FilesWritten + { + get { return _filesWritten.ToArray(); } + } + protected override void ExecuteCore() { LockFile lockFile = new LockFileCache(BuildEngine4).GetLockFile(AssetsFilePath); @@ -94,6 +102,8 @@ protected override void ExecuteCore() { writer.Write(dependencyContext, fileStream); } + _filesWritten.Add(new TaskItem(DepsFilePath)); + } } } diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/GenerateRuntimeConfigurationFiles.cs b/src/Tasks/Microsoft.NET.Build.Tasks/GenerateRuntimeConfigurationFiles.cs index d63fd710c3b5..4461f0b5fea2 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/GenerateRuntimeConfigurationFiles.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/GenerateRuntimeConfigurationFiles.cs @@ -38,6 +38,14 @@ public class GenerateRuntimeConfigurationFiles : TaskBase public string UserRuntimeConfig { get; set; } + List _filesWritten = new List(); + + [Output] + public ITaskItem[] FilesWritten + { + get { return _filesWritten.ToArray(); } + } + protected override void ExecuteCore() { LockFile lockFile = new LockFileCache(BuildEngine4).GetLockFile(AssetsFilePath); @@ -63,6 +71,7 @@ private void WriteRuntimeConfig(ProjectContext projectContext) AddUserRuntimeOptions(config.RuntimeOptions); WriteToJsonFile(RuntimeConfigPath, config); + _filesWritten.Add(new TaskItem(RuntimeConfigPath)); } private void AddFramework(RuntimeOptions runtimeOptions, ProjectContext projectContext) @@ -105,6 +114,7 @@ private void WriteDevRuntimeConfig(ProjectContext projectContext) AddAdditionalProbingPaths(devConfig.RuntimeOptions, projectContext); WriteToJsonFile(RuntimeConfigDevPath, devConfig); + _filesWritten.Add(new TaskItem(RuntimeConfigDevPath)); } private void AddAdditionalProbingPaths(RuntimeOptions runtimeOptions, ProjectContext projectContext) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.targets b/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.targets index 20c993354716..1038208d156b 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.targets @@ -70,6 +70,7 @@ Copyright (c) .NET Foundation. All rights reserved. @@ -90,7 +91,10 @@ Copyright (c) .NET Foundation. All rights reserved. ReferenceSatellitePaths="@(ReferenceSatellitePaths)" RuntimeIdentifier="$(RuntimeIdentifier)" PlatformLibraryName="$(MicrosoftNETPlatformLibrary)" - CompilerOptions="@(DependencyFileCompilerOptions)" /> + CompilerOptions="@(DependencyFileCompilerOptions)"> + + + @@ -104,6 +108,7 @@ Copyright (c) .NET Foundation. All rights reserved. @@ -114,7 +119,10 @@ Copyright (c) .NET Foundation. All rights reserved. RuntimeConfigDevPath="$(ProjectRuntimeConfigDevFilePath)" RuntimeIdentifier="$(RuntimeIdentifier)" PlatformLibraryName="$(MicrosoftNETPlatformLibrary)" - UserRuntimeConfig="$(UserRuntimeConfig)" /> + UserRuntimeConfig="$(UserRuntimeConfig)"> + + + diff --git a/test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildAnAppWithLibrary.cs b/test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildAnAppWithLibrary.cs index d7461e7a84ca..30d726f1066a 100644 --- a/test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildAnAppWithLibrary.cs +++ b/test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildAnAppWithLibrary.cs @@ -12,6 +12,9 @@ using Xunit; using static Microsoft.NET.TestFramework.Commands.MSBuildTest; using FluentAssertions; +using System.Xml.Linq; +using System.Linq; +using System; namespace Microsoft.NET.Build.Tests { @@ -134,5 +137,49 @@ public void It_generates_satellite_assemblies() commandResult.Should().HaveStdOutContaining(val); } } + [Fact] + public void The_clean_target_removes_all_files_from_the_output_folder() + { + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return; + } + + var testAsset = _testAssetsManager + .CopyTestAsset("AppWithLibrary") + .WithSource() + .Restore("TestApp"); + + var appProjectDirectory = Path.Combine(testAsset.TestRoot, "TestApp"); + + var buildCommand = new BuildCommand(Stage0MSBuild, appProjectDirectory); + + buildCommand + .Execute() + .Should() + .Pass(); + + var outputDirectory = buildCommand.GetOutputDirectory("netcoreapp1.0"); + + outputDirectory.Should().OnlyHaveFiles(new[] { + "TestApp.dll", + "TestApp.pdb", + "TestApp.deps.json", + "TestApp.runtimeconfig.dev.json", + "TestApp.runtimeconfig.json", + "TestLibrary.dll", + "TestLibrary.pdb" + }); + + var cleanCommand = Stage0MSBuild.CreateCommandForTarget("Clean", buildCommand.FullPathProjectFile); + + cleanCommand + .Execute() + .Should() + .Pass(); + + outputDirectory.Should().OnlyHaveFiles(Array.Empty()); + + } } }