5

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.

Sid
  • 4,893
  • 14
  • 55
  • 110
user2449952
  • 581
  • 1
  • 7
  • 21
  • Possible duplicate of [Deployed asp.net core mvc app not browsable in azure](http://stackoverflow.com/questions/40717145/deployed-asp-net-core-mvc-app-not-browsable-in-azure) – James P Nov 26 '16 at 10:25

5 Answers5

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.

Sanket
  • 19,295
  • 10
  • 71
  • 82
  • What would it look like for a classical Asp.Net application? Is there something similar in the .csproj? – BaluJr. Jan 23 '18 at 10:25
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

Morteza Jangjoo
  • 1,780
  • 2
  • 13
  • 25
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",
    ]
  },
Assil
  • 572
  • 6
  • 21
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

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.