Apr 12, 2016

ASP.NET pre-compile into a single assembly


Approach 1: (From StackOverflow)
The easiest way to do this is to Create (or change) your project as (or to) an "Asp.Net Web Application" rather than the "Asp.Net Web Site". The process of converting is not that hard, but you will need to move everything out of the app_code folder, as WAP (Web Application Projects) projects do not have code inside app_code.

This will cause your project to be compiled into a single dll, rather than the "dll per page" or "dll per directory" scheme that the web sites normally work off of. It will also force you to resolve any type name problems (IE: if you have 6 pages called Default), It's important when you make a single assembly that fully qualified names be unique.

This will give you a proper project file (build script) and dump all your dll's out to the /bin folder when you compile.

You can then use something like ILMerge to combine all your assemblies in the /bin folder into a single dll if that's what you want to do. This assumes all your references are managed assemblies, if you have any non .Net libs it's going to be a lot trickier, although still not impossible.


Approach 2: Use the aspnet_merge.exe Utility to Merge Assemblies
how-do-i-use-the-aspnet_mergeexe-utility-to-merge-assemblies


Approach 3: Compile MVC project to a single DLL embed your js and css files. When you publish, in the configure part of the settings tab (see capture below), be sure to uncheck "allow precompiled site to be updatable" <--- a="" and="" assembly="" br="" chose="" compile="" control="" cshtml="" in="" merge="" page="" single="" the="" will="">

By default there is an assumption that whoever has access to your views and DLLs is trusted. If they have your files, they can do whatever they want with them.

By the nature of HTML, there is no point in trying to conceal your content files such as javascript and CSS. These files are served to the client regardless, so they are always retrievable.

If you want to put your views into DLLs, you can look into RazorGenerator.

A Custom Tool for Visual Studio that allows processing Razor files at design time instead of runtime, allowing them to be built into an assembly for simpler reuse and distribution. Please note that what you're doing is known as "Security through obscurity".(Security through obscurity is the use of secrecy of the design or implementation to provide security).Security through obscurity is discouraged and not recommended by standards bodies.


Approach 4: Packaging ASP.NET ASPX Pages into a separate Assembly

Read here