Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC3 project does not always publish all views/content

This is crazy, but I can't seem to get all my views/content/scripts published when I publish the site. This seems to happen, I believe, when the view or content is not directly referenced by my project, but used by another assembly in my project. So I might have:

  • ExternalAssembly.dll referenced (it gets published)
  • I'll need ExternalLogin.cshtml in my main project, under my views folder
  • ExternalLogin.cshtml doesn't get published

Right now I have a script that copies everything in the Views folder and dumps it to where I want it deployed, but VS should do this for me. What am I doing wrong?

like image 662
chum of chance Avatar asked Nov 01 '11 23:11

chum of chance


2 Answers

When you click on one if these files what is the build action for it on the properties? Content....or? Set to content.

like image 184
Adam Tuliper Avatar answered Oct 15 '22 08:10

Adam Tuliper


So your views files are in another project or folder outside your current project? Normally the files have to exist in the web site project, in it's views folder, not externally, and the build action should be set to Content and not to copy to the output folder. But there are some workarounds:

  • Duplicate them in to your site views folder and make sure they are marked content (as stated in another answer). One thing to note though is that you can add them as "Linked Files" in visual studio which actually allows them to exist in two places in the hierarchy without having to exist in two places on disk: http://support.microsoft.com/kb/306234
  • If you have control over the external library, you can compile them in as embedded resources or use Razor Generator or something similar and use a custom view engine to return them: How can I make ASP.NET MVC 3 use views (aspx, ascx) files from an external assembly in my website?
  • Manually put the copies in the .csproj build XML using the Copy task: http://msdn.microsoft.com/en-us/library/3e54c37h.aspx (Note that this will make it work in visual studio doing essentially what you are doing now, as it will then be part of the Visual Studio build if you add it to the AfterBuild target or something)
like image 30
Paul Tyng Avatar answered Oct 15 '22 09:10

Paul Tyng