Make incremental build in VS copy output files

Fixes #2306
This commit is contained in:
Pranav K 2018-04-25 11:44:37 -07:00
parent 4c8c86b629
commit 8d99ba53ce
5 changed files with 113 additions and 1 deletions

View File

@ -74,6 +74,11 @@ Copyright (c) .NET Foundation. All rights reserved.
$(PrepareForRunDependsOn)
</PrepareForRunDependsOn>
<GetCopyToOutputDirectoryItemsDependsOn>
_RazorGetCopyToOutputDirectoryItems;
$(GetCopyToOutputDirectoryItems)
</GetCopyToOutputDirectoryItemsDependsOn>
</PropertyGroup>
<!--
@ -266,6 +271,9 @@ Copyright (c) .NET Foundation. All rights reserved.
<!--
Gathers input source files for code generation. This is a separate target so that we can avoid
lots of work when there are no inputs for code generation.
NOTE: This target is called as part of an incremental build scenario in VS. Do not perform any work
outside of calculating RazorGenerate items in this target.
-->
<Target Name="ResolveRazorGenerateInputs">
<!--
@ -384,7 +392,7 @@ Copyright (c) .NET Foundation. All rights reserved.
-->
<Target
Name="_RazorGetCopyToOutputDirectoryItems"
BeforeTargets="GetCopyToOutputDirectoryItems"
DependsOnTargets="ResolveRazorGenerateInputs"
Condition="'$(ResolvedRazorCompileToolset)'=='RazorSdk' and '$(RazorCompileOnBuild)'=='true'">
<!--

View File

@ -100,6 +100,30 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
throw new BuildOutputMissingException(result, match);
}
public static void BuildOutputDoesNotContainLine(MSBuildResult result, string match)
{
if (result == null)
{
throw new ArgumentNullException(nameof(result));
}
if (match == null)
{
throw new ArgumentNullException(nameof(match));
}
// We don't really need to search line by line, I'm doing this so that it's possible/easy to debug.
var lines = result.Output.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
for (var i = 0; i < lines.Length; i++)
{
var line = lines[i].Trim();
if (line == match)
{
throw new BuildOutputContainsLineException(result, match);
}
}
}
public static void FileContains(MSBuildResult result, string filePath, string match)
{
if (result == null)
@ -432,6 +456,19 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
protected override string Heading => $"Build did not contain the line: '{Match}'.";
}
private class BuildOutputContainsLineException : MSBuildXunitException
{
public BuildOutputContainsLineException(MSBuildResult result, string match)
: base(result)
{
Match = match;
}
public string Match { get; }
protected override string Heading => $"Build output contains the line: '{Match}'.";
}
private class FileContentFoundException : MSBuildXunitException
{
public FileContentFoundException(MSBuildResult result, string filePath, string content, string match)

View File

@ -136,5 +136,42 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
Assert.FileDoesNotExist(result, IntermediateOutputPath, "Razor", "Views", "Home", "Index.cshtml.g.cs");
}
}
[Fact]
[InitializeTestProject("AppWithP2PReference", additionalProjects: "ClassLibrary")]
public async Task IncrementalBuild_WithP2P_WorksWhenBuildProjectReferencesIsDisabled()
{
// Simulates building the same way VS does by setting BuildProjectReferences=false.
// With this flag, the only target called is GetCopyToOutputDirectoryItems on the referenced project.
// We need to ensure that we continue providing Razor binaries and symbols as files to be copied over.
var result = await DotnetMSBuild(target: default);
Assert.BuildPassed(result);
Assert.FileExists(result, OutputPath, "AppWithP2PReference.dll");
Assert.FileExists(result, OutputPath, "AppWithP2PReference.Views.dll");
Assert.FileExists(result, OutputPath, "ClassLibrary.dll");
Assert.FileExists(result, OutputPath, "ClassLibrary.Views.dll");
Assert.FileExists(result, OutputPath, "ClassLibrary.Views.pdb");
result = await DotnetMSBuild(target: "Clean", "/p:BuildProjectReferences=false", suppressRestore: true);
Assert.BuildPassed(result);
Assert.FileDoesNotExist(result, OutputPath, "AppWithP2PReference.dll");
Assert.FileDoesNotExist(result, OutputPath, "AppWithP2PReference.Views.dll");
Assert.FileDoesNotExist(result, OutputPath, "ClassLibrary.dll");
Assert.FileDoesNotExist(result, OutputPath, "ClassLibrary.Views.dll");
Assert.FileDoesNotExist(result, OutputPath, "ClassLibrary.Views.pdb");
// dotnet msbuild /p:BuildProjectReferences=false
result = await DotnetMSBuild(target: default, "/p:BuildProjectReferences=false", suppressRestore: true);
Assert.BuildPassed(result);
Assert.FileExists(result, OutputPath, "AppWithP2PReference.dll");
Assert.FileExists(result, OutputPath, "AppWithP2PReference.Views.dll");
Assert.FileExists(result, OutputPath, "ClassLibrary.dll");
Assert.FileExists(result, OutputPath, "ClassLibrary.Views.dll");
Assert.FileExists(result, OutputPath, "ClassLibrary.Views.pdb");
}
}
}

View File

@ -45,5 +45,31 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
Assert.BuildPassed(result);
Assert.BuildOutputContainsLine(result, "UseRazorBuildServer: false");
}
[Fact]
[InitializeTestProject("ClassLibrary")]
public async Task GetCopyToOutputDirectoryItems_WhenNoFileIsPresent_ReturnsEmptySequence()
{
var result = await DotnetMSBuild(target: default);
Assert.BuildPassed(result);
Assert.FileExists(result, OutputPath, "ClassLibrary.dll");
Assert.FileExists(result, OutputPath, "ClassLibrary.Views.dll");
result = await DotnetMSBuild(target: "GetCopyToOutputDirectoryItems", "/t:_IntrospectGetCopyToOutputDirectoryItems /p:BuildProjectReferences=false", suppressRestore: true);
Assert.BuildPassed(result);
Assert.BuildOutputContainsLine(result, "AllItemsFullPathWithTargetPath: ClassLibrary.Views.dll");
Assert.BuildOutputContainsLine(result, "AllItemsFullPathWithTargetPath: ClassLibrary.Views.pdb");
// Remove all views from the class library
Directory.Delete(Path.Combine(Project.DirectoryPath, "Views"), recursive: true);
// dotnet msbuild /p:BuildProjectReferences=false
result = await DotnetMSBuild(target: "GetCopyToOutputDirectoryItems", "/t:_IntrospectGetCopyToOutputDirectoryItems /p:BuildProjectReferences=false", suppressRestore: true);
Assert.BuildOutputDoesNotContainLine(result, "AllItemsFullPathWithTargetPath: ClassLibrary.Views.dll");
Assert.BuildOutputDoesNotContainLine(result, "AllItemsFullPathWithTargetPath: ClassLibrary.Views.pdb");
}
}
}

View File

@ -18,4 +18,8 @@
<Target Name="_IntrospectUseRazorBuildServer">
<Message Text="UseRazorBuildServer: $(UseRazorBuildServer)" Importance="High" />
</Target>
<Target Name="_IntrospectGetCopyToOutputDirectoryItems">
<Message Text="AllItemsFullPathWithTargetPath: %(AllItemsFullPathWithTargetPath.TargetPath)" Importance="High" />
</Target>
</Project>