Merge pull request #2324 from aspnet/release/2.1

Merge release/2.1
This commit is contained in:
Pranav K 2018-05-01 19:31:26 -07:00 committed by GitHub
commit 1a2ca58eba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 289 additions and 5 deletions

View File

@ -69,11 +69,21 @@ Copyright (c) .NET Foundation. All rights reserved.
_RazorAddDebugSymbolsProjectOutputGroupOutput
</DebugSymbolsProjectOutputGroupDependsOn>
<PrepareForBuildDependsOn>
$(PrepareForBuildDependsOn);
ResolveRazorGenerateInputs
</PrepareForBuildDependsOn>
<PrepareForRunDependsOn>
_RazorPrepareForRun;
$(PrepareForRunDependsOn)
</PrepareForRunDependsOn>
<GetCopyToOutputDirectoryItemsDependsOn>
_RazorGetCopyToOutputDirectoryItems;
$(GetCopyToOutputDirectoryItems)
</GetCopyToOutputDirectoryItemsDependsOn>
</PropertyGroup>
<!--
@ -180,10 +190,24 @@ Copyright (c) .NET Foundation. All rights reserved.
<RazorIntermediateAssembly Condition="'$(RazorIntermediateAssembly)'==''" Include="$(IntermediateOutputPath)$(RazorTargetName).dll" />
<!-- Used in Compilation.targets -->
<_RazorDebugSymbolsIntermediatePath Condition="'$(_RazorDebugSymbolsProduced)'=='true'" Include="$(IntermediateOutputPath)$(RazorTargetName).pdb" />
<!-- Add all cshtml files to UpToDateCheckInput - a collection used by the IDE's project system to determine if a project needs to be rebuilt -->
<UpToDateCheckInput Condition="'$(RazorCompileOnBuild)'=='true'" Include="@(Content->WithMetadataValue('Extension', '.cshtml'))" />
</ItemGroup>
<ItemGroup>
<!--
Add all cshtml files to UpToDateCheckInput - a collection of files used by FastUpToDateCheck to determine
if any of the the project inputs have changed.
-->
<UpToDateCheckInput Condition="'$(RazorCompileOnBuild)'=='true'" Include="@(Content->WithMetadataValue('Extension', '.cshtml'))" />
<!--
Add Razor output files to UpToDateCheckBuilt - a collection of files used by FastUpToDateCheck to determine
if any of the project's outputs have changed.
-->
<UpToDateCheckBuilt Include="@(RazorIntermediateAssembly)"
Condition="'$(RazorCompileOnBuild)'=='true' AND '@(Content->WithMetadataValue('Extension', '.cshtml'))' != ''" />
</ItemGroup>
<!--
These are the targets that generate code using Razor, separated from the main file for ease of maintenance.
Most targets related to Razor code generation are defined there.
@ -266,6 +290,11 @@ 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.
This target runs as part of PrepareForBuild. This gives us an opportunitity to change things like CopyToPublishDirectory
for Content items before they are processed by other Build targets.
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">
<!--
@ -283,6 +312,20 @@ Copyright (c) .NET Foundation. All rights reserved.
<ItemGroup Condition="'$(EnableDefaultRazorGenerateItems)'=='true'">
<RazorGenerate Include="@(Content)" Condition="'%(Content.Extension)'=='.cshtml'" />
</ItemGroup>
<!--
Ideally we want to able to update all Content items that also appear in RazorGenerate to have
CopyToPublishDirectory=Never. However, there isn't a simple way to do this (https://github.com/Microsoft/msbuild/issues/1618).
Instead, we'll update all cshtml Content items when EnableDefaultRazorGenerateItems=true and Razor Sdk is used for publishing.
-->
<ItemGroup Condition="
'$(EnableDefaultRazorGenerateItems)'=='true' and
'$(CopyRazorGenerateFilesToPublishDirectory)'=='false' and
'$(ResolvedRazorCompileToolset)'=='RazorSdk' and
'$(RazorCompileOnPublish)'=='true'">
<Content Condition="'%(Content.Extension)'=='.cshtml'" CopyToPublishDirectory="Never" />
</ItemGroup>
</Target>
<Target Name="AssignRazorGenerateTargetPaths" Condition="'@(RazorGenerate)' != ''">
@ -384,7 +427,7 @@ Copyright (c) .NET Foundation. All rights reserved.
-->
<Target
Name="_RazorGetCopyToOutputDirectoryItems"
BeforeTargets="GetCopyToOutputDirectoryItems"
DependsOnTargets="ResolveRazorGenerateInputs"
Condition="'$(ResolvedRazorCompileToolset)'=='RazorSdk' and '$(RazorCompileOnBuild)'=='true'">
<!--
@ -479,6 +522,15 @@ Copyright (c) .NET Foundation. All rights reserved.
<Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
</Copy>
<!--
FastUpToDate check in VS does not consider the Views dll when determining if referencing projects need to be rebuilt.
We'll touch a marker file that is used during as input for up to date check. Based on
https://github.com/Microsoft/msbuild/blob/637f06e31ef46892faeb40044899a62a15b77f79/src/Tasks/Microsoft.Common.CurrentVersion.targets#L4364-L4368
-->
<Touch Files="@(CopyUpToDateMarker)" AlwaysCreate="true" Condition="'@(_RazorAssembly)' != ''">
<Output TaskParameter="TouchedFiles" ItemName="FileWrites" />
</Touch>
</Target>

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

@ -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;
@ -136,5 +137,83 @@ 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");
}
[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));
}
}
}

View File

@ -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]
@ -45,5 +46,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

@ -27,6 +27,10 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
Assert.FileExists(result, PublishOutputPath, "SimpleMvc.Views.dll");
Assert.FileExists(result, PublishOutputPath, "SimpleMvc.Views.pdb");
// Verify assets get published
Assert.FileExists(result, PublishOutputPath, "wwwroot", "js", "SimpleMvc.js");
Assert.FileExists(result, PublishOutputPath, "wwwroot", "css", "site.css");
// By default refs and .cshtml files will not be copied on publish
Assert.FileCountEquals(result, 0, Path.Combine(PublishOutputPath, "refs"), "*.dll");
Assert.FileCountEquals(result, 0, Path.Combine(PublishOutputPath, "Views"), "*.cshtml");
@ -294,6 +298,11 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
Assert.FileExists(result, PublishOutputPath, "ClassLibrary.pdb");
Assert.FileExists(result, PublishOutputPath, "ClassLibrary.Views.dll");
Assert.FileExists(result, PublishOutputPath, "ClassLibrary.Views.pdb");
// Verify fix for https://github.com/aspnet/Razor/issues/2295. No cshtml files should be published from the app
// or the ClassLibrary.
Assert.FileCountEquals(result, 0, Path.Combine(PublishOutputPath, "refs"), "*.dll");
Assert.FileCountEquals(result, 0, Path.Combine(PublishOutputPath, "Views"), "*.cshtml");
}
[Fact]
@ -310,5 +319,40 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
Assert.FileDoesNotExist(result, OutputPath, "SimpleMvcFSharp.Views.dll");
Assert.FileDoesNotExist(result, OutputPath, "SimpleMvcFSharp.Views.pdb");
}
[Fact]
[InitializeTestProject("SimpleMvc")]
public async Task Publish_DoesNotPublishCustomRazorGenerateItems()
{
var additionalProjectContent = @"
<PropertyGroup>
<EnableDefaultRazorGenerateItems>false</EnableDefaultRazorGenerateItems>
</PropertyGroup>
<ItemGroup>
<RazorGenerate Include=""Views\_ViewImports.cshtml"" />
<RazorGenerate Include=""Views\Home\Index.cshtml"" />
</ItemGroup>
";
AddProjectFileContent(additionalProjectContent);
var result = await DotnetMSBuild("Publish");
Assert.BuildPassed(result);
Assert.FileExists(result, PublishOutputPath, "SimpleMvc.dll");
Assert.FileExists(result, PublishOutputPath, "SimpleMvc.pdb");
Assert.FileExists(result, PublishOutputPath, "SimpleMvc.Views.dll");
Assert.FileExists(result, PublishOutputPath, "SimpleMvc.Views.pdb");
// Verify assets get published
Assert.FileExists(result, PublishOutputPath, "wwwroot", "js", "SimpleMvc.js");
Assert.FileExists(result, PublishOutputPath, "wwwroot", "css", "site.css");
// By default refs and .cshtml files will not be copied on publish
Assert.FileCountEquals(result, 0, Path.Combine(PublishOutputPath, "refs"), "*.dll");
// Custom RazorGenerate item does not get published
Assert.FileDoesNotExist(result, PublishOutputPath, "Views", "Home", "Home.cshtml");
// cshtml Content item that's not part of RazorGenerate gets published.
Assert.FileExists(result, PublishOutputPath, "Views", "Home", "About.cshtml");
}
}
}

View File

@ -7,8 +7,11 @@
<Message Text="CompileResource: %(_RazorCoreCompileResourceInputs.Identity) %(_RazorCoreCompileResourceInputs.LogicalName)" Importance="High" />
</Target>
<Target Name="_IntrospectUpToDateCheckInput">
<Target Name="_IntrospectUpToDateCheck">
<Message Text="UpToDateCheckInput: %(UpToDateCheckInput.Identity)" Importance="High" />
<Message Text="No UpToDateCheckInput input found" Importance="High" Condition="'@(UpToDateCheckInput->Count)' == '0'" />
<Message Text="UpToDateCheckBuilt: %(UpToDateCheckBuilt.Identity)" Importance="High" />
<Message Text="No UpToDateCheckBuilt input found" Importance="High" Condition="'@(UpToDateCheckBuilt->Count)' == '0'" />
</Target>
<Target Name="_IntrospectRazorCompileItems">
@ -18,4 +21,8 @@
<Target Name="_IntrospectUseRazorBuildServer">
<Message Text="UseRazorBuildServer: $(UseRazorBuildServer)" Importance="High" />
</Target>
<Target Name="_IntrospectGetCopyToOutputDirectoryItems">
<Message Text="AllItemsFullPathWithTargetPath: %(AllItemsFullPathWithTargetPath.TargetPath)" Importance="High" />
</Target>
</Project>

View File

@ -0,0 +1,37 @@
/* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification\
for details on configuring this project to bundle and minify static web assets. */
body {
padding-top: 50px;
padding-bottom: 20px;
}
/* Wrapping element */
/* Set some basic padding to keep content from hitting the edges */
.body-content {
padding-left: 15px;
padding-right: 15px;
}
/* Carousel */
.carousel-caption p {
font-size: 20px;
line-height: 1.4;
}
/* Make .svg files in the carousel display properly in older browsers */
.carousel-inner .item img[src$=".svg"] {
width: 100%;
}
/* QR code generator */
#qrCode {
margin: 15px;
}
/* Hide/rearrange for smaller screens */
@media screen and (max-width: 767px) {
/* Hide captions */
.carousel-caption {
display: none;
}
}

View File

@ -0,0 +1 @@
// This is a test file