diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets
index 0b6a27e131f5..e528742a5873 100644
--- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets
+++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets
@@ -919,11 +919,37 @@ Copyright (c) .NET Foundation. All rights reserved.
+
+
+ <_GenerateSingleFileBundlePropertyInputsCacheToHash Include="$(PublishedSingleFilePath)" />
+ <_GenerateSingleFileBundlePropertyInputsCacheToHash Include="$(TraceSingleFileBundler)" />
+ <_GenerateSingleFileBundlePropertyInputsCacheToHash Include="$(IncludeSymbolsInSingleFile)" />
+ <_GenerateSingleFileBundlePropertyInputsCacheToHash Include="$(IncludeAllContentForSelfExtract)" />
+ <_GenerateSingleFileBundlePropertyInputsCacheToHash Include="$(IncludeNativeLibrariesForSelfExtract)" />
+ <_GenerateSingleFileBundlePropertyInputsCacheToHash Include="$(EnableCompressionInSingleFile)" />
+ <_GenerateSingleFileBundlePropertyInputsCacheToHash Include="$(PublishedSingleFileName)" />
+ <_GenerateSingleFileBundlePropertyInputsCacheToHash Include="$(RuntimeIdentifier)" />
+ <_GenerateSingleFileBundlePropertyInputsCacheToHash Include="$(PublishDir)" />
+ <_GenerateSingleFileBundlePropertyInputsCacheToHash Include="$(_TargetFrameworkVersionWithoutV)" />
+ <_GenerateSingleFileBundlePropertyInputsCacheToHash Include="@(FilesToBundle)" />
+
+
+
+
+
+
+
+
+
@@ -957,6 +983,50 @@ Copyright (c) .NET Foundation. All rights reserved.
+
+
+
+ $(PublishDepsFilePath)
+ $(IntermediateOutputPath)$(ProjectDepsFileName)
+
+
+
+
+
+ <_GeneratePublishDependencyFilePropertyInputsCacheToHash Include="$(PublishDepsFilePath)" />
+ <_GeneratePublishDependencyFilePropertyInputsCacheToHash Include="$(PublishSingleFile)" />
+ <_GeneratePublishDependencyFilePropertyInputsCacheToHash Include="$(MSBuildProjectFullPath)" />
+ <_GeneratePublishDependencyFilePropertyInputsCacheToHash Include="$(ProjectAssetsFile)" />
+ <_GeneratePublishDependencyFilePropertyInputsCacheToHash Include="$(IntermediateDepsFilePath)" />
+ <_GeneratePublishDependencyFilePropertyInputsCacheToHash Include="$(TargetFramework)" />
+ <_GeneratePublishDependencyFilePropertyInputsCacheToHash Include="$(AssemblyName)" />
+ <_GeneratePublishDependencyFilePropertyInputsCacheToHash Include="$(TargetExt)" />
+ <_GeneratePublishDependencyFilePropertyInputsCacheToHash Include="$(Version)" />
+ <_GeneratePublishDependencyFilePropertyInputsCacheToHash Include="$(IncludeMainProjectInDepsFile)" />
+ <_GeneratePublishDependencyFilePropertyInputsCacheToHash Include="$(RuntimeIdentifier)" />
+ <_GeneratePublishDependencyFilePropertyInputsCacheToHash Include="$(MicrosoftNETPlatformLibrary)" />
+ <_GeneratePublishDependencyFilePropertyInputsCacheToHash Include="$(SelfContained)" />
+ <_GeneratePublishDependencyFilePropertyInputsCacheToHash Include="$(IncludeFileVersionsInDependencyFile)" />
+ <_GeneratePublishDependencyFilePropertyInputsCacheToHash Include="$(BundledRuntimeIdentifierGraphFile)" />
+ <_GeneratePublishDependencyFilePropertyInputsCacheToHash Include="$(IncludeProjectsNotInAssetsFileInDepsFile)" />
+
+
+
+
+
+
+
+
+
+
+
+
+
+ _ComputePackageReferencePublish;
+ _GeneratePublishDependencyFileInputCache"
+ Condition="'$(GenerateDependencyFile)' == 'true' and '$(_UseBuildDependencyFile)' != 'true' and '$(PublishAot)' != 'true'"
+ Inputs="$(ProjectAssetsFile);$(ProjectAssetsCacheFile);$(MSBuildAllProjects);$(_GeneratePublishDependencyFilePropertyInputsCache)"
+ Outputs="$(IntermediateDepsFilePath)">
-
- $(PublishDepsFilePath)
- $(IntermediateOutputPath)$(ProjectDepsFileName)
+
$(PublishDir)$(ProjectDepsFileName)
<_IsSingleFilePublish Condition="'$(PublishSingleFile)' == ''">false
<_IsSingleFilePublish Condition="'$(PublishSingleFile)' != ''">$(PublishSingleFile)
+
diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets
index a3efcc34aa0d..17a726f30721 100644
--- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets
+++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets
@@ -42,6 +42,10 @@ Copyright (c) .NET Foundation. All rights reserved.
true
<_GenerateRuntimeConfigurationPropertyInputsCache Condition="'$(_GenerateRuntimeConfigurationPropertyInputsCache)' == ''">$(IntermediateOutputPath)$(MSBuildProjectName).genruntimeconfig.cache
<_GenerateRuntimeConfigurationPropertyInputsCache>$([MSBuild]::NormalizePath($(MSBuildProjectDirectory), $(_GenerateRuntimeConfigurationPropertyInputsCache)))
+ <_GeneratePublishDependencyFilePropertyInputsCache Condition="'$(_GeneratePublishDependencyFilePropertyInputsCache)' == ''">$(IntermediateOutputPath)$(MSBuildProjectName).genpublishdeps.cache
+ <_GeneratePublishDependencyFilePropertyInputsCache>$([MSBuild]::NormalizePath($(MSBuildProjectDirectory), $(_GeneratePublishDependencyFilePropertyInputsCache)))
+ <_GenerateSingleFileBundlePropertyInputsCache Condition="'$(_GenerateSingleFileBundlePropertyInputsCache)' == ''">$(IntermediateOutputPath)$(MSBuildProjectName).genbundle.cache
+ <_GenerateSingleFileBundlePropertyInputsCache>$([MSBuild]::NormalizePath($(MSBuildProjectDirectory), $(_GenerateSingleFileBundlePropertyInputsCache)))
diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishIncrementally.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishIncrementally.cs
index da9ae1f129ec..85468de264ab 100644
--- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishIncrementally.cs
+++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishIncrementally.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
using FluentAssertions;
+using System;
using System.IO;
using System.Linq;
using Microsoft.NET.TestFramework;
@@ -300,6 +301,37 @@ public void It_cleans_with_multiple_output_dirs()
CheckPublishOutput(publishDir2, expectedSingleExeFiles, expectedNonSingleExeFiles);
}
+ [Theory]
+ [InlineData(ToolsetInfo.CurrentTargetFramework)]
+ public void GeneratePublishDependencyFile_runs_incrementally(string targetFramework)
+ {
+ var rid = EnvironmentInfo.GetCompatibleRid(targetFramework);
+ var testProject = new TestProject()
+ {
+ Name = "PublishDependencyFileIncremental",
+ TargetFrameworks = targetFramework,
+ IsExe = true,
+ RuntimeIdentifier = rid
+ };
+
+ testProject.PackageReferences.Add(new TestPackageReference("NewtonSoft.Json", "13.0.1", publish: "false"));
+ var testAsset = _testAssetsManager.CreateTestProject(testProject, testProject.Name);
+
+ var publishCommand = new PublishCommand(testAsset);
+ var publishDir = publishCommand.GetOutputDirectory(targetFramework, runtimeIdentifier: rid).FullName;
+ var depsJsonPath = Path.Combine(publishDir, testProject.Name + ".deps.json");
+
+ publishCommand.Execute().Should().Pass();
+ DateTime depsJsonFirstModifiedTime = File.GetLastWriteTimeUtc(depsJsonPath);
+
+ WaitForUtcNowToAdvance();
+
+ publishCommand.Execute().Should().Pass();
+ DateTime depsJsonSecondModifiedTime = File.GetLastWriteTimeUtc(depsJsonPath);
+
+ depsJsonSecondModifiedTime.Should().Be(depsJsonFirstModifiedTime);
+ }
+
private void CheckPublishOutput(string publishDir, IEnumerable expectedFiles, IEnumerable unexpectedFiles)
{
if (expectedFiles != null)