.Net Core MVC Deployment (Publish) missing views
Asked Answered
Y

5

6

I am trying to publish my MVC application in .NET core. I tried the File system, but it's missing all the View related files and throws error as soon as accessed.

After copying the view folder it started working . I am not sure If it's missing other web components also.

Yukikoyukio answered 26/11, 2016 at 6:5 Comment(1)
Possible duplicate of Deployed asp.net core mvc app not browsable in azureWee
C
5

Make sure you have Views in your PublishOptions of Project.json.

If you are maintaing views inside Areas then make sure you have added Areas/**/Views

Sample below-

  "publishOptions": {
    "include": [
      "wwwroot",
      "web.config",
      "Views",
      "Areas/**/Views",
      "appsettings.json",
    ]
  },

See if this helps.

Codel answered 26/11, 2016 at 11:35 Comment(1)
What would it look like for a classical Asp.Net application? Is there something similar in the .csproj?Selfpreservation
Q
3

edit your.csproj file and add PreserveCompilationContext as true and MvcRazorCompileOnPublish as false

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<PreserveCompilationContext>true</PreserveCompilationContext>
<MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>
</PropertyGroup>

then views will be included in publish

Quotable answered 19/3, 2020 at 12:4 Comment(0)
C
0

Areas do not work this way... So adding

Areas/**/Views

It might not work for you, It has not for me.

  "publishOptions": {
    "include": [
      "wwwroot",
      "web.config",
      "Views",
      "Areas/**/Views",
      "appsettings.json",
    ]
  },

If you replace it with this, It will definitely work..

 "publishOptions": {
    "include": [
      "wwwroot",
      "web.config",
      "Views",
      "Areas/**/Views/**/*.cshtml",
      "appsettings.json",
    ]
  },
Crystlecs answered 24/6, 2017 at 20:48 Comment(0)
B
0

Edit your project and add

<pre>
MvcRazorCompileOnPublish=false 
</pre>

in xml file property group

this will force publishing the view files as .cshtml file as usual.

Note : precompiled views within dll is faster at runtime

Barrio answered 29/7, 2018 at 19:50 Comment(0)
O
0

With .Net Core MVC when publishing the View folder is not suppose to go instead you should have a file yourprojectname.Views.dll, check if you have this dll.

Depending where u publishing to you have to target that OS https://learn.microsoft.com/en-us/dotnet/core/rid-catalog.

Also you should show the error you getting, could be related to many other things such as permission.

Oolite answered 1/3, 2019 at 12:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.