Home View folder not being copied by dotnet publish
Reply: 0

View folder not being copied by dotnet publish

joanlofe
1#
joanlofe Published in 2018-02-12 12:05:36Z

I have a .NET Core 2.0 multiproject solution. My main project is named myproject.Web and has a folder Views (with subfolder) where I have all the cshtml files. In addition, myproject.Web depends on another project, myproject.UI, which also has a folder Views which contains more cshtml that are common to many projects.

The project myproject.Web runs fine when I execute dotnet run on the command line. However, when I dotnet publish and (in the publish folder) execute dotnet myproject.Web.dll the project does not work as expected. The landing page loads in the browser, but when I log in I received HTTP 404 error. After inspection I found that none of the files in the Views folder were being copied. That seems to be the likely source of the problem.

I have managed to get the cshtml files in the UI project into the publish folder, but after all my efforts I cannot get the cshtmlfiles in myproject.Web\Views into the publish folder.

I post below the relevant parts of my .csproj file.

  <ItemGroup>
    <Folder Include="Views\" />
  </ItemGroup>

  <ItemGroup>
    <None Include="Views\**\*">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      <CopyToPublishDirectory>Always</CopyToPublishDirectory>
    </None>
  </ItemGroup>

  <Target Name="PostPublish" AfterTargets="AfterPublish">
    <Exec Command="xcopy /E /Y /R  &quot;$(ProjectDir)..\myproject.UI\Views\*&quot; $(PublishDir)Views\*" />
  </Target>

Update

The comment by Kirk below explains why the cshtml files are not being copied. But that does not explain why I get the 404 error. In brief:

  1. The 404 does not appear for the login page (it works as expected).
  2. The 404 error appears after performing logging.
  3. The dotnet myproject.Web.dll output does not show any error (copied below for completeness).
  4. This behaviour only happens with the published artifact, when executed with dotnet run it works perfectly.

dotnet myproject.Web.dll output:

Hosting environment: Local
Content root path: C:\Projects\Master-Demos\Code\myproject.Web\bin\Release\netcoreapp2.0\publish
Now listening on: http://0.0.0.0:57579
Application started. Press Ctrl+C to shut down.
ContentProvider [Watch]: /Views/Home/../Shared/Widgets/_TileEnriched.cshtml
ContentProvider [GetFileInfo]: /Views/Home/../Shared/Widgets/_TileEnriched.cshtml
ContentProvider [GetFileInfo]: /Views/Home/../Shared/Widgets/_TileEnriched.cshtml
ContentProvider [Watch]: /Views/Home/../Shared/Widgets/_TileEnriched.cshtml
ContentProvider [GetFileInfo]: /Views/Home/../Shared/Widgets/_TileEnriched.cshtml
ContentProvider [GetFileInfo]: /Views/Home/../Shared/Widgets/_TileEnriched.cshtml
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.294753 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO