From 05c84f008a5a6536b6ce84c3dbf8c468dc08f4c0 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 30 Apr 2018 08:25:55 -0700 Subject: [PATCH] Ensure Views dll are copied during P2P builds FastUpToDateCheck in VS doesn't account for changes solely to .Views.dll. This causes referencing projects to be treated as up to date even though a referenced project rebuilt. Touch the marker file to cause referenced projects to rebuild. Fixes https://github.com/aspnet/Razor/issues/2306 to cause it to treat --- .../Sdk.Razor.CurrentVersion.targets | 27 +++++++++++- .../BuildIncrementalismTest.cs | 42 +++++++++++++++++++ .../BuildIntrospectionTest.cs | 3 +- test/testapps/RazorTest.Introspection.targets | 5 ++- 4 files changed, 73 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Sdk.Razor.CurrentVersion.targets b/src/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Sdk.Razor.CurrentVersion.targets index 49332be01f..591d4a0f4f 100644 --- a/src/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Sdk.Razor.CurrentVersion.targets +++ b/src/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Sdk.Razor.CurrentVersion.targets @@ -185,10 +185,24 @@ Copyright (c) .NET Foundation. All rights reserved. <_RazorDebugSymbolsIntermediatePath Condition="'$(_RazorDebugSymbolsProduced)'=='true'" Include="$(IntermediateOutputPath)$(RazorTargetName).pdb" /> - - + + + + + + + + + + + + diff --git a/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/BuildIncrementalismTest.cs b/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/BuildIncrementalismTest.cs index e368095630..f6b4c7ac4e 100644 --- a/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/BuildIncrementalismTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/BuildIncrementalismTest.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -173,5 +174,46 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests Assert.FileExists(result, OutputPath, "ClassLibrary.Views.dll"); Assert.FileExists(result, OutputPath, "ClassLibrary.Views.pdb"); } + + [Fact] + [InitializeTestProject("ClassLibrary")] + public async Task Build_TouchesUpToDateMarkerFile() + { + var classLibraryDll = Path.Combine(IntermediateOutputPath, "ClassLibrary.dll"); + var classLibraryViewsDll = Path.Combine(IntermediateOutputPath, "ClassLibrary.Views.dll"); + var markerFile = Path.Combine(IntermediateOutputPath, "ClassLibrary.csproj.CopyComplete"); + + var result = await DotnetMSBuild("Build"); + Assert.BuildPassed(result); + + Assert.FileExists(result, classLibraryDll); + Assert.FileExists(result, classLibraryViewsDll); + Assert.FileExists(result, markerFile); + + // Gather thumbprints before incremental build. + var classLibraryThumbPrint = GetThumbPrint(classLibraryDll); + var classLibraryViewsThumbPrint = GetThumbPrint(classLibraryViewsDll); + var markerFileThumbPrint = GetThumbPrint(markerFile); + + result = await DotnetMSBuild("Build"); + Assert.BuildPassed(result); + + // Verify thumbprint file is unchanged between true incremental builds + Assert.Equal(classLibraryThumbPrint, GetThumbPrint(classLibraryDll)); + Assert.Equal(classLibraryViewsThumbPrint, GetThumbPrint(classLibraryViewsDll)); + // In practice, this should remain unchanged. However, since our tests reference + // binaries from other projects, this file gets updated by Microsoft.Common.targets + Assert.NotEqual(markerFileThumbPrint, GetThumbPrint(markerFile)); + + // Change a cshtml file and verify ClassLibrary.Views.dll and marker file are updated + File.AppendAllText(Path.Combine(Project.DirectoryPath, "Views", "_ViewImports.cshtml"), Environment.NewLine); + + result = await DotnetMSBuild("Build"); + Assert.BuildPassed(result); + + Assert.Equal(classLibraryThumbPrint, GetThumbPrint(classLibraryDll)); + Assert.NotEqual(classLibraryViewsThumbPrint, GetThumbPrint(classLibraryViewsDll)); + Assert.NotEqual(markerFileThumbPrint, GetThumbPrint(markerFile)); + } } } diff --git a/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/BuildIntrospectionTest.cs b/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/BuildIntrospectionTest.cs index a6d7eeac3e..f19401a140 100644 --- a/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/BuildIntrospectionTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/BuildIntrospectionTest.cs @@ -18,11 +18,12 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests [InitializeTestProject("SimpleMvc")] public async Task RazorSdk_AddsCshtmlFilesToUpToDateCheckInput() { - var result = await DotnetMSBuild("_IntrospectUpToDateCheckInput"); + var result = await DotnetMSBuild("_IntrospectUpToDateCheck"); Assert.BuildPassed(result); Assert.BuildOutputContainsLine(result, $"UpToDateCheckInput: {Path.Combine("Views", "Home", "Index.cshtml")}"); Assert.BuildOutputContainsLine(result, $"UpToDateCheckInput: {Path.Combine("Views", "_ViewStart.cshtml")}"); + Assert.BuildOutputContainsLine(result, $"UpToDateCheckBuilt: {Path.Combine(IntermediateOutputPath, "SimpleMvc.Views.dll")}"); } [Fact] diff --git a/test/testapps/RazorTest.Introspection.targets b/test/testapps/RazorTest.Introspection.targets index 03c94f9c44..a22622b0d6 100644 --- a/test/testapps/RazorTest.Introspection.targets +++ b/test/testapps/RazorTest.Introspection.targets @@ -7,8 +7,11 @@ - + + + +