From a94323499bd0bdb048495035b4bab349ed816123 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 24 Apr 2018 12:52:44 -0700 Subject: [PATCH] Change CopyToPublishDirectory on Content items instead of explicitly removing this from publish items Fixes #2295 --- .../Sdk.Razor.CurrentVersion.targets | 21 +++++++++ .../PublishIntegrationTest.cs | 44 +++++++++++++++++++ test/testapps/SimpleMvc/wwwroot/css/site.css | 37 ++++++++++++++++ .../SimpleMvc/wwwroot/js/SimpleMvc.js | 1 + 4 files changed, 103 insertions(+) create mode 100644 test/testapps/SimpleMvc/wwwroot/css/site.css create mode 100644 test/testapps/SimpleMvc/wwwroot/js/SimpleMvc.js 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 591d4a0f4f..7d771e7c0d 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 @@ -69,6 +69,11 @@ Copyright (c) .NET Foundation. All rights reserved. _RazorAddDebugSymbolsProjectOutputGroupOutput + + $(PrepareForBuildDependsOn); + ResolveRazorGenerateInputs + + _RazorPrepareForRun; $(PrepareForRunDependsOn) @@ -285,6 +290,8 @@ Copyright (c) .NET Foundation. All rights reserved. + + + + diff --git a/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/PublishIntegrationTest.cs b/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/PublishIntegrationTest.cs index be6b1fed29..0931cfd43b 100644 --- a/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/PublishIntegrationTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/PublishIntegrationTest.cs @@ -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 = @" + + false + + + + + +"; + 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"); + } } } diff --git a/test/testapps/SimpleMvc/wwwroot/css/site.css b/test/testapps/SimpleMvc/wwwroot/css/site.css new file mode 100644 index 0000000000..6b0e6c3ab2 --- /dev/null +++ b/test/testapps/SimpleMvc/wwwroot/css/site.css @@ -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; + } +} diff --git a/test/testapps/SimpleMvc/wwwroot/js/SimpleMvc.js b/test/testapps/SimpleMvc/wwwroot/js/SimpleMvc.js new file mode 100644 index 0000000000..ad51101cd1 --- /dev/null +++ b/test/testapps/SimpleMvc/wwwroot/js/SimpleMvc.js @@ -0,0 +1 @@ +// This is a test file