From 2c7a0cdb9eb6b8c4cb7325ea8a0c37e69b3072d2 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Fri, 5 May 2023 20:49:04 +0000 Subject: [PATCH 1/8] Add test for incremental publish with excluded assets --- .../GivenThatWeWantToPublishIncrementally.cs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishIncrementally.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishIncrementally.cs index c338c43c47c7..e1fb9cce02d2 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; @@ -298,6 +299,37 @@ public void It_cleans_with_multiple_output_dirs() CheckPublishOutput(publishDir2, expectedSingleExeFiles, expectedNonSingleExeFiles); } + [Theory] + [InlineData(ToolsetInfo.CurrentTargetFramework)] + public void GeneratePublishDepependencyFile_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) From 5b540f2fffeeb3dcb407277bec0fbb67fe7bc5de Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Fri, 5 May 2023 21:16:34 +0000 Subject: [PATCH 2/8] Make GeneratePublishDependencyFile incremental --- .../targets/Microsoft.NET.Publish.targets | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) 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..a3b73e55a9ab 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 @@ -957,6 +957,14 @@ Copyright (c) .NET Foundation. All rights reserved. + + + + $(PublishDepsFilePath) + $(IntermediateOutputPath)$(ProjectDepsFileName) + + + + Condition="'$(GenerateDependencyFile)' == 'true' and '$(_UseBuildDependencyFile)' != 'true' and '$(PublishAot)' != 'true'" + Inputs="$(ProjectAssetsFile);$(ProjectAssetsCacheFile);$(MSBuildAllProjects)" + Outputs="$(IntermediateDepsFilePath)"> - - $(PublishDepsFilePath) - $(IntermediateOutputPath)$(ProjectDepsFileName) $(PublishDir)$(ProjectDepsFileName) <_IsSingleFilePublish Condition="'$(PublishSingleFile)' == ''">false <_IsSingleFilePublish Condition="'$(PublishSingleFile)' != ''">$(PublishSingleFile) + From 9e519ad8339307cf37a0dad46b2a2f1d2dab351a Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Wed, 10 May 2023 00:28:43 +0000 Subject: [PATCH 3/8] Don't rely on incremental publish for compression test --- .../GivenThatWeWantToPublishASingleFileApp.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASingleFileApp.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASingleFileApp.cs index ba2798bd15f7..cb160cacd229 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASingleFileApp.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASingleFileApp.cs @@ -799,7 +799,9 @@ public void It_compresses_single_file_as_directed() .Pass(); var uncompressedSize = new FileInfo(singleFilePath).Length; - WaitForUtcNowToAdvance(); + testAsset = _testAssetsManager.CreateTestProject(testProject); + publishCommand = new PublishCommand(testAsset); + singleFilePath = Path.Combine(GetPublishDirectory(publishCommand, ToolsetInfo.CurrentTargetFramework).FullName, $"SingleFileTest{Constants.ExeSuffix}"); publishCommand .Execute(PublishSingleFile, RuntimeIdentifier, IncludeNative, "/p:EnableCompressionInSingleFile=true") From 01a16b2256b161a8f222d5af969ff129716239d4 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Tue, 23 May 2023 18:49:28 +0000 Subject: [PATCH 4/8] Revert "Don't rely on incremental publish for compression test" This reverts commit 9e519ad8339307cf37a0dad46b2a2f1d2dab351a. --- .../GivenThatWeWantToPublishASingleFileApp.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASingleFileApp.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASingleFileApp.cs index cb160cacd229..ba2798bd15f7 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASingleFileApp.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASingleFileApp.cs @@ -799,9 +799,7 @@ public void It_compresses_single_file_as_directed() .Pass(); var uncompressedSize = new FileInfo(singleFilePath).Length; - testAsset = _testAssetsManager.CreateTestProject(testProject); - publishCommand = new PublishCommand(testAsset); - singleFilePath = Path.Combine(GetPublishDirectory(publishCommand, ToolsetInfo.CurrentTargetFramework).FullName, $"SingleFileTest{Constants.ExeSuffix}"); + WaitForUtcNowToAdvance(); publishCommand .Execute(PublishSingleFile, RuntimeIdentifier, IncludeNative, "/p:EnableCompressionInSingleFile=true") From 490d428c397e1d267ef2868932ce802e87dc8cfc Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Tue, 23 May 2023 21:39:29 +0000 Subject: [PATCH 5/8] Fix incremental build when properties change For GeneratePublishDependencyFile and GenerateSingleFileBundle targets --- .../targets/Microsoft.NET.Publish.targets | 70 +++++++++++++++++-- .../targets/Microsoft.NET.Sdk.targets | 4 ++ 2 files changed, 70 insertions(+), 4 deletions(-) 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 a3b73e55a9ab..0a2ce8f9c2b6 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,39 @@ 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)" /> + + + + + + + + + + + + + @@ -965,6 +993,40 @@ Copyright (c) .NET Foundation. All rights reserved. + + + <_GeneratePublishDependencyFilePropertyInputsCacheToHash Include="$(PublishDepsFilePath)" /> + <_GeneratePublishDependencyFilePropertyInputsCacheToHash Include="$(PublishSingleFile)" /> + <_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)" /> + + + + + + + + + + + + + + PublishDepsFilePath is empty (by default) for PublishSingleFile, since the deps.json file is embedded within the single-file bundle --> $(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))) From 9cb55bcf478566cc8c375ef8af74dac48242e520 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Tue, 23 May 2023 23:18:02 +0000 Subject: [PATCH 6/8] Fix typo --- .../GivenThatWeWantToPublishIncrementally.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishIncrementally.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishIncrementally.cs index 7764420f880a..85468de264ab 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishIncrementally.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishIncrementally.cs @@ -303,7 +303,7 @@ public void It_cleans_with_multiple_output_dirs() [Theory] [InlineData(ToolsetInfo.CurrentTargetFramework)] - public void GeneratePublishDepependencyFile_runs_incrementally(string targetFramework) + public void GeneratePublishDependencyFile_runs_incrementally(string targetFramework) { var rid = EnvironmentInfo.GetCompatibleRid(targetFramework); var testProject = new TestProject() From fe6126547f30f1a1c687e2932076fd62a3223259 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Wed, 24 May 2023 15:06:28 +0000 Subject: [PATCH 7/8] Fix target dependency, typo --- .../targets/Microsoft.NET.Publish.targets | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 0a2ce8f9c2b6..482bb67e6c2e 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 @@ -1023,7 +1023,7 @@ Copyright (c) .NET Foundation. All rights reserved. WriteOnlyWhenDifferent="True" /> - + @@ -1042,7 +1042,8 @@ Copyright (c) .NET Foundation. All rights reserved. _ComputeReferenceAssemblies; _ComputeUserRuntimeAssemblies; ResolveRuntimePackAssets; - _ComputePackageReferencePublish" + _ComputePackageReferencePublish; + _GeneratePublishDependencyFileInputCache" Condition="'$(GenerateDependencyFile)' == 'true' and '$(_UseBuildDependencyFile)' != 'true' and '$(PublishAot)' != 'true'" Inputs="$(ProjectAssetsFile);$(ProjectAssetsCacheFile);$(MSBuildAllProjects);$(_GeneratePublishDependencyFilePropertyInputsCache)" Outputs="$(IntermediateDepsFilePath)"> From 7c3607447ee87a1da3914afc59dbd10dc735be5f Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Thu, 25 May 2023 22:56:17 +0000 Subject: [PATCH 8/8] PR feedback - Add target dependency - Add more relevant inputs to hash - Leave out unnecessary FileWrites --- .../targets/Microsoft.NET.Publish.targets | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 482bb67e6c2e..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 @@ -930,6 +930,8 @@ Copyright (c) .NET Foundation. All rights reserved. <_GenerateSingleFileBundlePropertyInputsCacheToHash Include="$(PublishedSingleFileName)" /> <_GenerateSingleFileBundlePropertyInputsCacheToHash Include="$(RuntimeIdentifier)" /> <_GenerateSingleFileBundlePropertyInputsCacheToHash Include="$(PublishDir)" /> + <_GenerateSingleFileBundlePropertyInputsCacheToHash Include="$(_TargetFrameworkVersionWithoutV)" /> + <_GenerateSingleFileBundlePropertyInputsCacheToHash Include="@(FilesToBundle)" /> @@ -941,10 +943,6 @@ Copyright (c) .NET Foundation. All rights reserved. File="$(_GenerateSingleFileBundlePropertyInputsCache)" Overwrite="true" WriteOnlyWhenDifferent="true" /> - - - - @@ -993,10 +991,12 @@ Copyright (c) .NET Foundation. All rights reserved. - + <_GeneratePublishDependencyFilePropertyInputsCacheToHash Include="$(PublishDepsFilePath)" /> <_GeneratePublishDependencyFilePropertyInputsCacheToHash Include="$(PublishSingleFile)" /> + <_GeneratePublishDependencyFilePropertyInputsCacheToHash Include="$(MSBuildProjectFullPath)" /> <_GeneratePublishDependencyFilePropertyInputsCacheToHash Include="$(ProjectAssetsFile)" /> <_GeneratePublishDependencyFilePropertyInputsCacheToHash Include="$(IntermediateDepsFilePath)" /> <_GeneratePublishDependencyFilePropertyInputsCacheToHash Include="$(TargetFramework)" />