Change CopyToPublishDirectory on Content items instead of explicitly removing this from publish items
Fixes #2295
This commit is contained in:
parent
05c84f008a
commit
a94323499b
|
|
@ -69,6 +69,11 @@ Copyright (c) .NET Foundation. All rights reserved.
|
||||||
_RazorAddDebugSymbolsProjectOutputGroupOutput
|
_RazorAddDebugSymbolsProjectOutputGroupOutput
|
||||||
</DebugSymbolsProjectOutputGroupDependsOn>
|
</DebugSymbolsProjectOutputGroupDependsOn>
|
||||||
|
|
||||||
|
<PrepareForBuildDependsOn>
|
||||||
|
$(PrepareForBuildDependsOn);
|
||||||
|
ResolveRazorGenerateInputs
|
||||||
|
</PrepareForBuildDependsOn>
|
||||||
|
|
||||||
<PrepareForRunDependsOn>
|
<PrepareForRunDependsOn>
|
||||||
_RazorPrepareForRun;
|
_RazorPrepareForRun;
|
||||||
$(PrepareForRunDependsOn)
|
$(PrepareForRunDependsOn)
|
||||||
|
|
@ -285,6 +290,8 @@ Copyright (c) .NET Foundation. All rights reserved.
|
||||||
<!--
|
<!--
|
||||||
Gathers input source files for code generation. This is a separate target so that we can avoid
|
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.
|
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
|
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.
|
outside of calculating RazorGenerate items in this target.
|
||||||
|
|
@ -305,6 +312,20 @@ Copyright (c) .NET Foundation. All rights reserved.
|
||||||
<ItemGroup Condition="'$(EnableDefaultRazorGenerateItems)'=='true'">
|
<ItemGroup Condition="'$(EnableDefaultRazorGenerateItems)'=='true'">
|
||||||
<RazorGenerate Include="@(Content)" Condition="'%(Content.Extension)'=='.cshtml'" />
|
<RazorGenerate Include="@(Content)" Condition="'%(Content.Extension)'=='.cshtml'" />
|
||||||
</ItemGroup>
|
</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>
|
||||||
|
|
||||||
<Target Name="AssignRazorGenerateTargetPaths" Condition="'@(RazorGenerate)' != ''">
|
<Target Name="AssignRazorGenerateTargetPaths" Condition="'@(RazorGenerate)' != ''">
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,10 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
|
||||||
Assert.FileExists(result, PublishOutputPath, "SimpleMvc.Views.dll");
|
Assert.FileExists(result, PublishOutputPath, "SimpleMvc.Views.dll");
|
||||||
Assert.FileExists(result, PublishOutputPath, "SimpleMvc.Views.pdb");
|
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
|
// 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, "refs"), "*.dll");
|
||||||
Assert.FileCountEquals(result, 0, Path.Combine(PublishOutputPath, "Views"), "*.cshtml");
|
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.pdb");
|
||||||
Assert.FileExists(result, PublishOutputPath, "ClassLibrary.Views.dll");
|
Assert.FileExists(result, PublishOutputPath, "ClassLibrary.Views.dll");
|
||||||
Assert.FileExists(result, PublishOutputPath, "ClassLibrary.Views.pdb");
|
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]
|
[Fact]
|
||||||
|
|
@ -310,5 +319,40 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
|
||||||
Assert.FileDoesNotExist(result, OutputPath, "SimpleMvcFSharp.Views.dll");
|
Assert.FileDoesNotExist(result, OutputPath, "SimpleMvcFSharp.Views.dll");
|
||||||
Assert.FileDoesNotExist(result, OutputPath, "SimpleMvcFSharp.Views.pdb");
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
// This is a test file
|
||||||
Loading…
Reference in New Issue