Description
Describe the bug
The Web SDK does not normally publish *.cshtml
files when using dotnet publish
(because they're precompiled into the web site assembly and aren't needed). These files are published from referenced projects if $(NoBuild)
is true
e.g. using dotnet publish --no-build
. These files increase deployment payloads and can confuse tests.
To Reproduce
- In a clone of the dotnet/aspnetcore repo, run
eng\build.cmd -noBuildManaged -noBuildNative
dotnet build src\Mvc\test\WebSites\RazorPagesWebSite\
dotnet publish --no-build src\Mvc\test\WebSites\RazorPagesWebSite\
- Observe the artifacts\bin\RazorPagesWebSite\Debug\net7.0\publish\Pages\ClassLibraryPages folder as well as the
*.cshtml
files within it - Reset using
rm -Recurse artifacts\bin\RazorPagesWebSite\
andrm -Recurse artifacts\obj\RazorPagesWebSite\
dotnet build src\Mvc\test\WebSites\RazorPagesWebSite\
dotnet publish src\Mvc\test\WebSites\RazorPagesWebSite\
- Observe the lack of an artifacts\bin\RazorPagesWebSite\Debug\net7.0\publish\Pages folder
More detail
Using /p:BuildProjectReferences=false
instead of --no-build
in step 3 results in the same over-publication.
The ClassLibraryPages folder comes from the referenced src\Mvc\test\WebSites\RazorPagesClassLibrary\ project. Note the many *.cshtml
files from the RazorPagesWebSite project are not published in either (3) or (7).
Moving up a project dependency level and doing the same with the src\Mvc\test\Mvc.FunctionalTests\ project is worse because src\Mvc\test\WebSites\RazorPagesWebSite\ contains a lot of *.cshtml
files and other referenced projects add to that; all are copied into artifacts\bin\Microsoft.AspNetCore.Mvc.FunctionalTests\Debug\net7.0\publish\Pages and …\Views. This breaks the functional tests because a few test sites use <RazorCompileOnPublish>false</RazorCompileOnPublish>
and pick up incorrect / unexpected files.
Binary logging
The AssignTargetPaths
target in the RazorPagesClassLibrary project adds@(ContentWithTargetPath)
for Pages\ClassLibraryPages\*.cshtml
in all cases. The items are removed before the GetCopyToPublishDirectoryItems
target is reached but not when using --no-build
or /p:BuildProjectReferences=false
. It's not clear where the removals happen because item removals are not consistently logged.
Versions
I've only tested with the 7.0.100-preview.2.22102.6
SDK but this is likely a long-standing issue.
dotnet details
> dotnet --info
.NET SDK (reflecting any global.json):
Version: 7.0.100-preview.2.22102.6
Commit: 6b77f292d5
Runtime Environment:
OS Name: Windows
OS Version: 10.0.22000
OS Platform: Windows
RID: win10-x64
Base Path: C:\dd\dnx\aspnetcore\.dotnet\sdk\7.0.100-preview.2.22102.6\
Host (useful for support):
Version: 7.0.0-preview.2.22103.2
Commit: 0ae04e5b33
.NET SDKs installed:
7.0.100-preview.2.22102.6 [C:\dd\dnx\aspnetcore\.dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.21 [C:\dd\dnx\aspnetcore\.dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.0-dev [C:\dd\dnx\aspnetcore\.dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.0-preview.2.22080.2 [C:\dd\dnx\aspnetcore\.dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.30 [C:\dd\dnx\aspnetcore\.dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.21 [C:\dd\dnx\aspnetcore\.dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.0-preview.2.22102.1 [C:\dd\dnx\aspnetcore\.dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.0-preview.2.22102.17 [C:\dd\dnx\aspnetcore\.dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.0-preview.2.22103.2 [C:\dd\dnx\aspnetcore\.dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 7.0.0-preview.2.22101.13 [C:\dd\dnx\aspnetcore\.dotnet\shared\Microsoft.WindowsDesktop.App]
To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download