I'm using the publishing wizard and it published all of the necessary files except for my Controllers folder. I was under the assumption that I need a controller.
I have navigated to Package/Publish Web setting, do I need to tweak anything in here? I'm guessing this isn't set up properly out of the box. If I change the drop down to publish all files in this folder/solution will it try to upload all the referenced DLLs that don't need to be copied to the server?
In ASP.NET web projects, including MVC projects, .cs files (controllers in this case) are compiled into the /bin/[your.project].dll assembly when you do a Build or Publish.
So you don't need to publish/copy .cs files.
The controller and model code is compiled into the web site dll. The views are deployed in their folders.
Related
I'm trying to publish a solution that contains several projects -one of them is MVC- to IIS7.
When the MVC project is published and some views are being accessed I get the following error:
Could not load file or assembly 'NHibernate.Mapping.Attributes, Version=3.2.0.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4' or one of its dependencies. The system cannot find the file specified.
This happens because the view I'm trying to access is calling a function in another project in that solution and needs this library!
but this library is not contained in the MVC project!
I was able to solve it by referencing that DLL in the MVC project! but I need another solution, because it doesn't make sense to reference every single DLL in all the other projects!
I'm using the "Web Deploy" publish option for the MVC project, is there another way that I can publish it and make it work without referencing all the DLLs from all the other projects?
There is an article on how to deploy assemblies that are not referenced by your MVC project directly:
http://haacked.com/archive/2011/05/25/bin-deploying-asp-net-mvc-3.aspx
Basically you need to create a folder in your project called _bin_deployableAssemblies and add your assemblies to it. They will get deployed with the website.
Here is a quote from the article:
So here’s the kicker. If you’re building a web application, and you
need an assembly deployed but don’t want it referenced and don’t want
it checked into the bin directory, you can simply add this folder
yourself and put your own assemblies in here.
I have a Code folder in my asp.net mvc web project, I added a .cs file and the compiler does not seem to pick up any errors I make. However, if I first add the .cs file to the root of my mvc web project and then moves it to the Code folder, the compiler will work properly. Why is this happening? I'm using VS10 and mvc3. Thanks.
Edit: I notice I first called the folder App_Code and then renamed it to Code, so it seems if you add .cs to App_Code the compiler doesn't run on those, even if you move the .cs out or change the folder name to something else. Very strange.
From what you describing it sounds like the Build Action is not set to Compile on your file.
In response to your Edit. The App_Code is a special folder in ASP.NET, its files are compiled at run time. For more information see: Shared Code Folders in ASP.NET Web Sites
I am working on a project that started out using ASP.Net MVC 1 and has since been upgraded to ASP.Net MVC 3. It is my understanding that if I am running my ASP.NET MVC 3 app on IIS 7 using the integrated pipeline that I no longer need the Default.aspx file. However after I have removed the file from the project and physically deleted it I get the following error every time I try to compile in Release mode:
Description: Could not load type 'ProjectName.Default'.
File: Default.Aspx
I have verified that there is no instance of ProjectName.Default or Default.aspx in my project file. I have even done a grep search in all of my files in the project for any mention those names and still have found nothing. What do I need to do to be able to remove Default.aspx from my ASP.Net MVC 3 app and get it to compile in release mode. It compiles just fine in Debug mode by the way.
From the debugging listed here you probably had a cached version of your compiled code. While Visual Studio builds the code behind files into a single DLL, ASP.NET compiles each aspx file into a DLL as well (depending on how you configure it, there can be variations on this). These DLLs are located at %WINDIR%\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files note that this directory is sensitive to .Net version, could be in 2.0 or 4.0, it is also in some way dependent on bit-ness, as there is a similar directory in Framework64.
I tried to clean my solution, delete the project temp files, remove all the leftover crud I could think of. Unfortunately none of this worked so I had to take the brute force approach and checkout a new copy of my project. After doing this I no longer had the error occur when building the new copy that had Default.aspx removed. Unfortunately this solution did not provide me any insight into what leftover file Visual Studio was holding onto.
This seems to be the only thing that works:
If a .cs file is inside App_Code...
And does not contain extension methods: set the build action to "Compile"; otherwise no other source code in the project knows of its existence.
And contains extension methods: set the build action to "None"; otherwise you get an error that the reference to x.Foo is ambiguous between MyExtensions.Foo and MyExtensions.Foo.
If a .cs file is outside App_Code, inside a folder called Helpers, it must have build action set to "Compile," regardless of whether or not it contains extension methods.
I don't understand this behavior. I wasn't sure that ASP.NET MVC contained any special privileges for App_Code, but it looks like it does... but only in the sense that it auto-compiles extension-method containing .cs files, even when the build action is set to "None"?? Someone please explain.
I'm assuming you've created a Web Application Project, not a Web Site Project. The App_Code folder in an ASP.NET application is special. It is designed to allow you to drop in code to have it compiled with the website in place. Because of this, the project items are marked as "None" to make sure they are not compiled by Visual Studio. When you publish a Web Site Project to your hosted environment, the code files themselves are copied in the App_Code folder, and this is compiled into a seperate assembly by the ASP.NET runtime.
Now, when you create an MVC Web Application, you must remember that it is not the same project type as a Web Site Project. An MVC Web Application will compile locally to an assembly in your /bin directory. If you add an App_Code folder to your project with your code in and you change the Build type to Compile, you run into problems because:
Your MVC application has compiled and includes a MyExtensions.Foo type and,
ASP.NET is compiling the App_Code folder which also has a MyExtensions.Foo type.
My recommendation is to avoid using App_Code. I tend not to, as I favour a more concise project structure. Use the Models folder for code, or create other folders.....
If you really want to use an App_Code folder, it might be better to mark the build action of any of the files as "Content" to ensure they are copied to the output directory when publishing your site.
I would like to use a WebSite project instead of a Web Application project for an MVC project.
What is the best way to accomplish this and are there signifigant problems that I might run into?
(as a side note, my reasoning for wanting this is because I have graphic designers who put files into SVN but they don't get added to the "project" and don't show up on deployment or deployment testing. My thought was that switching to a Web Site project might prevent this)
You don't need to do anything special if you are not using CodeBehind files (if you're using them, it'll be more complex but anyway, it's an MVC app. If you're using them, don't!). Just take an MVC Web app project and put all source files (*.cs) under App_Code directory of the Web site. That said, I fail to see any advantage for it.
The application project allows you to use the Models folder to embed classes into. This would then be compiled for that web project. A web site does not provide for this directly. It would require that you use an assembly project to maintain all of your classes. Rather than converting from one project type to another (which I am not sure how you wold go about doing that) you can simply attach an assembly project to your web application and not store any classes in the model folder of your application.
Having said this, you should keep your web project as an application as there usually are view specific classes that are required such as a your view model classes that belong in the web project.