|
1 | 1 | // Copyright (c) .NET Foundation. All rights reserved. |
2 | 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. |
3 | 3 |
|
| 4 | +using System; |
4 | 5 | using System.Collections.Generic; |
5 | 6 | using System.IO; |
6 | 7 | using System.Linq; |
@@ -136,5 +137,83 @@ async Task VerifyError() |
136 | 137 | Assert.FileDoesNotExist(result, IntermediateOutputPath, "Razor", "Views", "Home", "Index.cshtml.g.cs"); |
137 | 138 | } |
138 | 139 | } |
| 140 | + |
| 141 | + [Fact] |
| 142 | + [InitializeTestProject("AppWithP2PReference", additionalProjects: "ClassLibrary")] |
| 143 | + public async Task IncrementalBuild_WithP2P_WorksWhenBuildProjectReferencesIsDisabled() |
| 144 | + { |
| 145 | + // Simulates building the same way VS does by setting BuildProjectReferences=false. |
| 146 | + // With this flag, the only target called is GetCopyToOutputDirectoryItems on the referenced project. |
| 147 | + // We need to ensure that we continue providing Razor binaries and symbols as files to be copied over. |
| 148 | + var result = await DotnetMSBuild(target: default); |
| 149 | + |
| 150 | + Assert.BuildPassed(result); |
| 151 | + |
| 152 | + Assert.FileExists(result, OutputPath, "AppWithP2PReference.dll"); |
| 153 | + Assert.FileExists(result, OutputPath, "AppWithP2PReference.Views.dll"); |
| 154 | + Assert.FileExists(result, OutputPath, "ClassLibrary.dll"); |
| 155 | + Assert.FileExists(result, OutputPath, "ClassLibrary.Views.dll"); |
| 156 | + Assert.FileExists(result, OutputPath, "ClassLibrary.Views.pdb"); |
| 157 | + |
| 158 | + result = await DotnetMSBuild(target: "Clean", "/p:BuildProjectReferences=false", suppressRestore: true); |
| 159 | + Assert.BuildPassed(result); |
| 160 | + |
| 161 | + Assert.FileDoesNotExist(result, OutputPath, "AppWithP2PReference.dll"); |
| 162 | + Assert.FileDoesNotExist(result, OutputPath, "AppWithP2PReference.Views.dll"); |
| 163 | + Assert.FileDoesNotExist(result, OutputPath, "ClassLibrary.dll"); |
| 164 | + Assert.FileDoesNotExist(result, OutputPath, "ClassLibrary.Views.dll"); |
| 165 | + Assert.FileDoesNotExist(result, OutputPath, "ClassLibrary.Views.pdb"); |
| 166 | + |
| 167 | + // dotnet msbuild /p:BuildProjectReferences=false |
| 168 | + result = await DotnetMSBuild(target: default, "/p:BuildProjectReferences=false", suppressRestore: true); |
| 169 | + |
| 170 | + Assert.BuildPassed(result); |
| 171 | + Assert.FileExists(result, OutputPath, "AppWithP2PReference.dll"); |
| 172 | + Assert.FileExists(result, OutputPath, "AppWithP2PReference.Views.dll"); |
| 173 | + Assert.FileExists(result, OutputPath, "ClassLibrary.dll"); |
| 174 | + Assert.FileExists(result, OutputPath, "ClassLibrary.Views.dll"); |
| 175 | + Assert.FileExists(result, OutputPath, "ClassLibrary.Views.pdb"); |
| 176 | + } |
| 177 | + |
| 178 | + [Fact] |
| 179 | + [InitializeTestProject("ClassLibrary")] |
| 180 | + public async Task Build_TouchesUpToDateMarkerFile() |
| 181 | + { |
| 182 | + var classLibraryDll = Path.Combine(IntermediateOutputPath, "ClassLibrary.dll"); |
| 183 | + var classLibraryViewsDll = Path.Combine(IntermediateOutputPath, "ClassLibrary.Views.dll"); |
| 184 | + var markerFile = Path.Combine(IntermediateOutputPath, "ClassLibrary.csproj.CopyComplete"); |
| 185 | + |
| 186 | + var result = await DotnetMSBuild("Build"); |
| 187 | + Assert.BuildPassed(result); |
| 188 | + |
| 189 | + Assert.FileExists(result, classLibraryDll); |
| 190 | + Assert.FileExists(result, classLibraryViewsDll); |
| 191 | + Assert.FileExists(result, markerFile); |
| 192 | + |
| 193 | + // Gather thumbprints before incremental build. |
| 194 | + var classLibraryThumbPrint = GetThumbPrint(classLibraryDll); |
| 195 | + var classLibraryViewsThumbPrint = GetThumbPrint(classLibraryViewsDll); |
| 196 | + var markerFileThumbPrint = GetThumbPrint(markerFile); |
| 197 | + |
| 198 | + result = await DotnetMSBuild("Build"); |
| 199 | + Assert.BuildPassed(result); |
| 200 | + |
| 201 | + // Verify thumbprint file is unchanged between true incremental builds |
| 202 | + Assert.Equal(classLibraryThumbPrint, GetThumbPrint(classLibraryDll)); |
| 203 | + Assert.Equal(classLibraryViewsThumbPrint, GetThumbPrint(classLibraryViewsDll)); |
| 204 | + // In practice, this should remain unchanged. However, since our tests reference |
| 205 | + // binaries from other projects, this file gets updated by Microsoft.Common.targets |
| 206 | + Assert.NotEqual(markerFileThumbPrint, GetThumbPrint(markerFile)); |
| 207 | + |
| 208 | + // Change a cshtml file and verify ClassLibrary.Views.dll and marker file are updated |
| 209 | + File.AppendAllText(Path.Combine(Project.DirectoryPath, "Views", "_ViewImports.cshtml"), Environment.NewLine); |
| 210 | + |
| 211 | + result = await DotnetMSBuild("Build"); |
| 212 | + Assert.BuildPassed(result); |
| 213 | + |
| 214 | + Assert.Equal(classLibraryThumbPrint, GetThumbPrint(classLibraryDll)); |
| 215 | + Assert.NotEqual(classLibraryViewsThumbPrint, GetThumbPrint(classLibraryViewsDll)); |
| 216 | + Assert.NotEqual(markerFileThumbPrint, GetThumbPrint(markerFile)); |
| 217 | + } |
139 | 218 | } |
140 | 219 | } |
0 commit comments