Deploying a Solution with multiple projects on IIS7 - Missing DLLs - asp.net-mvc

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.

Related

Controllers folder missing Umbraco 8

I installed Umbraco 8.4 as per the instructions found at https://our.umbraco.com/documentation/Getting-Started/Setup/Install/install-umbraco-with-nuget
Once done within Visual Studio 2017 i tried to created a new Controller and the folder (Controllers) was missing.
I'm not sure if i've missed something but i didnt want to create the folder manually in case it introduces new problems later down the line.
I thought to recreate the project but instead of selecting Empty as the project to use MVC but after reading through a few threads it seems the correct way is to select an empty project.
Under the bin directory i do see System.Web.Mvc.dll
Am i missing something?
You should definitely not use the MVC project template when creating a new project - that will add all sorts of dependencies that will likely conflict with what comes with the Umbraco NuGet package.
Go with the "Empty" template and then add in the NuGet and it will give you the dependencies you need for Umbraco to run. If you need to add in other stuff from MVC afterwards, you can add these in a version that aligns with what the Umbraco package has added.
In regards to the Controllers folder - it really doesn't matter where this folder lives or what it is called. Controllers are registered by other means. You are totally fine to create this folder manually and call it whatever you prefer.
I think most people actually prefer to keep Controllers in a completely separate project in the VS solution. Then reference that project by your main project to ensure the compiled DLL is included in your web project - and thereby your controllers can be used by the Umbraco website itself. By doing this, you get a clean separation of your .cs source files so you won't accidentally be deploying those when you deploy your site. To do this you would of course require to add UmbracoCms.Core NuGet package to your other project in order to use Umbraco functionality.
Keep in mind if you are adding plain MVC controllers (not inheriting from the Umbraco base controllers - and therefore not getting automatically registered) you will need to manually register these controllers in the route table in order to access them.
This is no different from what you would do in a normal ASP.NET MVC project, but since this isn't added by default in an Umbraco project - you need to do it yourself.
See this answer for instructions on how to do it: https://stackoverflow.com/a/56972929/336105

NLog.Extended not copied to my Web Project

I have a solution with 2 projects:
Project 1: Wrapper.Dll which contains a NLog wrapper. NLog and NLog.Extended have been installed with Nuget.
Project 2: is an ASP.Net MVC project which contains a reference to project 1.
When I try to run the web project, it throws an exception because NLog tries to load a target renderer from NLog.Extended.Dll.
If I check the bin directory of Wrapper.dll, I have NLog.Dll and NLog.Extended.Dll.
If I check the bin directory of the Web project, I only have NLog.dll.
How can I tell Visual Studio to copy the NLog.Extended.Dll from project 1 to project 2?
EDIT: Adding some dead code that use something from NLog.Extended.Dll makes the file copied.
Is there any cleaner solution?
Thanks
Unfortunately no, there is no cleaner solution. If no objects from the NLog.Extended assembly are referenced (directly or indirectly) from your code, it will not copy it. This is of course a problem since the layouts are just strings and not a direct reference. You could use a post-build event, but that's an uglier solution in my opinion.
You could add a reference to NLog.Extended.dll in the web project if it depends on it.

Web Deploy does not include files necessary for NHibernate in deployment

I am building my deployment process and I am running into a really annoying problem.
Using Visual Studio 2010 Sp1 on a .Net4 project with ASP.NET MVC3 that I want to deploy to an IIS7.5 webserver. The deployment works fine - both from Visual Studio and command line - except for this one important part:
I am using NHibernate (with Fluent NH) in a class library that is referenced by my web app. These were installed using NuGet, and also show up on the server when deployed.
However, these depend on some other libraries:
Castle.Core
Iesi.Collections
NHibernate.ByteCode.Castle
These are also fetched by NuGet, they are referenced in my class library, and the references have "Copy Local" set to True. However, out of these three, only Iesi.Collections actually show up on the server!
Of course, I can copy them manually, but the next time I run the deploy, it will delete them. Deleting unused files is actually something I want, but these files should not be in that category!
What can I do to make Web Deploy respect the fact that these guys are desired members of my application!?
Try adding those assemblies as references to your web project otherwise implicit references in class libraries might not be included.

Publishing my ASP.NET MVC project doesn't publish all necessary files

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.

ASP.NET MVC: files containing extension methods inside App_Code must have Build Action "None"?

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.

Resources