dotnet publish not copying extra View files on Linux
See original GitHub issueI am working on an ASP.NET Core 2.0 project, and I have some .cshtml
files in my Views
directory that are used as e-mail templates and rendered using a wrapper service around the Razor engine. My project is configured to precompile views during publish to speed up rendering later down the line, which happens successfully, except that the Razor engine can’t find the Email views in Production because they apparently aren’t included in the view precompilation (as they’re never referenced by a Controller).
I have these additional .cshtml
files specified in my .csproj
file in an <ItemGroup>
as
<None Include="Views\Email\**\*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToPublishDirectory>Always</CopyToPublishDirectory>
</None>
When I run dotnet publish
on Windows, the Views are correctly copied to the bin\Debug\netcoreapp2.0\publish\
directory as expected. However, when I run the same command on Linux (in the same repo), they aren’t copied to the specified publish directory, so I get a 500 error when the site tries to send e-mails.
The output of dotnet --info
on Windows, where the views are copied correctly, is the following:
.NET Command Line Tools (2.1.0-preview1-007042)
Product Information:
Version: 2.1.0-preview1-007042
Commit SHA-1 hash: e94a82c9a3
Runtime Environment:
OS Name: Windows
OS Version: 10.0.14393
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.1.0-preview1-007042\
Microsoft .NET Core Shared Framework Host
Version : 2.0.0
Build : e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d
The output on Linux is the following:
.NET Command Line Tools (2.0.0)
Product Information:
Version: 2.0.0
Commit SHA-1 hash: cdcd1928c9
Runtime Environment:
OS Name: centos
OS Version: 7
OS Platform: Linux
RID: centos.7-x64
Base Path: /usr/share/dotnet/sdk/2.0.0/
Microsoft .NET Core Shared Framework Host
Version : 2.0.0
Build : e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d
From what I can tell, 2.1.0-preview is not available for CentOS yet. Is the version difference why it succeeds on Windows and not Linux, or is there something else I’m missing?
Issue Analytics
- State:
- Created 6 years ago
- Comments:5
Well, I ended up solving my own problem now after an hour of sifting through StackOverflow and GitHub issues, so I’ll describe my fix for anyone else in a similar scenario.
I added a project property in one of the
<PropertyGroup>
sections for my e-mail template files, and appended that onto the<DefaultItemExcludes>
property:This apparently causes the Razor view precompilation to skip those View files, so the following
<ItemGroup>
entries correctly copy the files on output:I had the same issue on Windows Core 2.x - I had to set
But then I got Cannot find compilation library location for package Microsoft.Win32.Registry error which is described as per https://github.com/dotnet/core-setup/issues/2113 and fixable by manually adding
<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
which includes a load of extra DLL’s into a ref folder during publish…Works now! Phew… (On Windows)