App_Code folder is automatically created on the published website

I have an MVC4 application created in VS 2010 with Umbraco 6, and I created a web deployment project that my Team City CI server uses to deploy my website in a CI environment for testing.

On the CI server, the first time the main page (or any page) is loaded, it loads completely fine. However, when the page loads, the App_Code folder is created on my CI server, and after that I get the message “Directory / App_Code /” is not allowed because the application is precompiled. ”Deleting the App_Code folder means that it works again to load one page, and the folder is created again.

Removing the PrecompiledApp.config file leads to the fact that my site does not load from YSOD with the indication "Link to the object is not installed in the instance of the object." in the next stack trace point "Umbraco.Web.UmbracoModule.BeginRequest (HttpContextBase httpContext) +25"

To be clear, I don't have the App_Code folder in my project, and I don't want or don't need it. All I want to do is stop creating it automatically when the page loads! I used Umbraco in VS and deployed as many times earlier, but not with Umbraco 6 and in the MVC project.

Any ideas why App_Code is automatically created and what can I do to stop it?

Many thanks

Richard

+7
source share
3 answers

I seem to be using Umbraco just like you, wrapping it up as an MVC 4 project. Therefore, it becomes a “VS web application” instead of a “VS website”.

It is important to remember that initially Umbraco did not start as an application, and many functions in Umbraco are primarily aimed at using App_Code.

The inner classes AssemblyExtensions, PluginManager, TypeHelper, and the public TypeFinder class in Umbraco.Core have methods that depend on whether there is an App_Code folder. Even if you do not need App_Code in your Umbraco solution, if you do not want to just hide it from your solution. If you really do not want it to delete all links to it in the source and create your own Umbraco compilation.

== CHANGE BELOW ==

After reading your comment and posting again, I created a small solution to your problem. The fact that Umbraco creates App_Code is still due to initialization of the structure, which will not work without the existing App_Code. But recompiling and creating your own Umbraco distribution will mean that the OP indicates some additional maintenance when upgrading, etc.

This is not ideal, but the cleanest way to handle this issue is for Umbraco to create the App_Code folder, but also delete it when the application is initialized. I would use IApplicationEventHandler. Sample code works in my box.

using Umbraco.Core; using Umbraco.Core.IO; namespace YourNamespace.EventHandlers { public class AppCodeEvents : IApplicationEventHandler { public void OnApplicationInitialized(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { } public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { } public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { if (System.IO.Directory.Exists(IOHelper.MapPath(IOHelper.ResolveUrl("~/App_Code")))) { System.IO.Directory.Delete(IOHelper.MapPath(IOHelper.ResolveUrl("~/App_Code"))); } } } } 
+1
source

If you precompile your site using a web deployment project, I assume that all of your links are separate from the project - that’s good. So, I think the simple answer here is not to precompile the site, just allow the creation of the web application so that it retrieves the links and deploys the built project.

Personally, I think the best way to work with Umbraco v6 is through NuGet. Create an empty MVC4 project and use NuGet to add Umbraco v6. This will automatically sort all links for you. This is because these fantastic guys from Umbraco created two Nuget packages, one with project files, and the other with core DLLs.

This means that when the site is built, the links are pulled in and updating the site is easy. It's just a matter of updating through NuGet.

0
source

It also happened to me, it turned out that it was because the precompiledApp.config file somehow made its way to the production server ... I don’t know how it happened, but as soon as I deleted and processed the web application, it stopped.

0
source

All Articles