Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Tasks/Microsoft.NET.Build.Tasks/GenerateDepsFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ public class GenerateDepsFile : TaskBase

public ITaskItem[] PrivateAssetsPackageReferences { get; set; }

List<ITaskItem> _filesWritten = new List<ITaskItem>();

[Output]
public ITaskItem[] FilesWritten
{
get { return _filesWritten.ToArray(); }
}

protected override void ExecuteCore()
{
LockFile lockFile = new LockFileCache(BuildEngine4).GetLockFile(AssetsFilePath);
Expand Down Expand Up @@ -94,6 +102,8 @@ protected override void ExecuteCore()
{
writer.Write(dependencyContext, fileStream);
}
_filesWritten.Add(new TaskItem(DepsFilePath));

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ public class GenerateRuntimeConfigurationFiles : TaskBase

public string UserRuntimeConfig { get; set; }

List<ITaskItem> _filesWritten = new List<ITaskItem>();

[Output]
public ITaskItem[] FilesWritten
{
get { return _filesWritten.ToArray(); }
}

protected override void ExecuteCore()
{
LockFile lockFile = new LockFileCache(BuildEngine4).GetLockFile(AssetsFilePath);
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Copyright (c) .NET Foundation. All rights reserved.

<Target Name="GenerateBuildDependencyFile"
DependsOnTargets="_DefaultMicrosoftNETPlatformLibrary"
BeforeTargets="_CheckForCompileOutputs"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My instinct would be to go before _CleanGetCurrentAndPriorFileWrites instead, since this isn't really compile-specific. But _CheckForCompileOutputs is before that so this is ok. Did you prefer this for a reason?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this cause GenerateBuildDependencyFile to run on Clean? That's not right. We want it to only run on build and log the write then.

Copy link
Copy Markdown
Member Author

@dsplaisted dsplaisted Nov 11, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this cause GenerateBuildDependencyFile to run on Clean?

The IncrementalClean target runs during a normal build (CoreBuild depends on it). IncrementalClean depends on _CleanGetCurrentAndPriorFileWrites, which depends on _CheckForCompileOutputs. So it's confusing (which is why I asked for Rainier's review), but I think it's doing the right thing and not causing this to run during Clean.

Did you prefer this for a reason?

I think it was because GenerateBuildDependencyFile also writes files to the output folder, so I thought it might make sense to be before the CopyFilesToOutputDirectory target, which depends on _CheckForCompileOutputs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ that meshes with my reasoning on @nguerrera's question. 👍

Condition=" '$(GenerateDependencyFile)' == 'true'"
Inputs="$(ProjectAssetsFile)"
Outputs="$(ProjectDepsFilePath)">
Expand All @@ -90,7 +91,10 @@ Copyright (c) .NET Foundation. All rights reserved.
ReferenceSatellitePaths="@(ReferenceSatellitePaths)"
RuntimeIdentifier="$(RuntimeIdentifier)"
PlatformLibraryName="$(MicrosoftNETPlatformLibrary)"
CompilerOptions="@(DependencyFileCompilerOptions)" />
CompilerOptions="@(DependencyFileCompilerOptions)">

<Output TaskParameter="FilesWritten" ItemName="FileWrites" />
</GenerateDepsFile>

</Target>

Expand All @@ -104,6 +108,7 @@ Copyright (c) .NET Foundation. All rights reserved.

<Target Name="GenerateBuildRuntimeConfigurationFiles"
DependsOnTargets="_DefaultMicrosoftNETPlatformLibrary"
BeforeTargets="_CheckForCompileOutputs"
Condition=" '$(GenerateRuntimeConfigurationFiles)' == 'true'"
Inputs="$(ProjectAssetsFile);$(UserRuntimeConfig)"
Outputs="$(ProjectRuntimeConfigFilePath);$(ProjectRuntimeConfigDevFilePath)">
Expand All @@ -114,7 +119,10 @@ Copyright (c) .NET Foundation. All rights reserved.
RuntimeConfigDevPath="$(ProjectRuntimeConfigDevFilePath)"
RuntimeIdentifier="$(RuntimeIdentifier)"
PlatformLibraryName="$(MicrosoftNETPlatformLibrary)"
UserRuntimeConfig="$(UserRuntimeConfig)" />
UserRuntimeConfig="$(UserRuntimeConfig)">

<Output TaskParameter="FilesWritten" ItemName="FileWrites" />
</GenerateRuntimeConfigurationFiles>

</Target>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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<string>());

}
}
}