Do dynamically compiled files use csc.exe in .NET? - asp.net

Title asked it all,
Do dynamically compiled files, such as .cshtml files, use csc.exe in .NET?
I saw this question C# JIT compiling and .NET
But it doesn't fully go into the compilation of a dynamic file to before being Jit'ed.
So you have this site https://msdn.microsoft.com/en-us/library/ms366723.aspx.
Which says:
By default, ASP.NET Web pages and code files are compiled dynamically
when users first request a resource, such as an ASP.NET page (.aspx
file), from a Web site. After pages and code files have been compiled
the first time, the compiled resources are cached, so that subsequent
requests to the same page are extremely efficient.
So am I to understand that csc.exe runs on first request of a new resource before being JIT'ed?

The short answer appears to be yes.
Source: https://blogs.msdn.microsoft.com/webdev/2014/05/12/enabling-the-net-compiler-platform-roslyn-in-asp-net-applications/
"the Roslyn compiler would be loaded into memory, improving greatly performance for not pre-compiled websites with multiple .asx/*.cshtml files. The new version, however, features a new /bin/roslyn/csc.exe file, which is executed once per file, completely removing the mentioned above optimization feature"

Related

Update Embedded Resource at runtime

In my ASP.NET MVC application, I want to update the contents of a css or js file which is embedded inside my dll at runtime, without restarting the application.
My application takes a long time to restart, so in development I'd rather not wait for minutes at a time to see changes in js or css.
I think Embedded resources are not meant to be changed in the runtime at all. It is almost same as you cannot modify the bytes (compiled from your source code) within your assembly at runtime. You may consider a different architecture for your Application so that you won't need to update your embedded resource at runtime. Especially for JS and CSS, they can be added in the runtime and they can be served by your server without any need to be embedded.
Anyway, I understand that you may have the need to embed the resource and so, here is the link I found, maybe useful for you: Programmically embed resources in a .NET assembly

How does compiling happen only for the first time in projectless development?

I read these words in a book:
Projectless development simplifies debugging: When creating a web project, you must recompile the entire application when you change a single page. With projectless development, each page is compiled separately, and the page is only compiled when you request it for the first time.
How does compiling happen only for the first time in projectless development?
Should it recompile every time I run the page to reflect the new code I wrote it?
IIS compiles it. When a page changes and is uploaded again, IIS will compile it again.
See this topic on MSDN, in particular the section headed Automatic Compilation.
This should apply to other web servers as well (XPS, apache with mod_mono) as can be seen in this article.

Are asp.net pages compiled per page or per folder?

My understanding is asp.net pages are grouped in folders and each folder is compiled into a dll file. However when a page is requested the first time, only that page is compiled? So is it possible to compile part of a dll file? And when a page is requested, is it only the page's code within the dll file is executed, but not the whole dll? Somehow I'm under thr impression that a dll file should be compiled or executed as a whole.
Your answer exists within ASP.NET Compilation Overview and the compilation element.
Directories are compiled when browsed to, but the batch=true/false configures if only the loaded page will be compiled, or all of the pages in that directory. (There's a maxBatchSize that configures maximum of pages to compile in a batch.)
Page can compile per folder if you have enable the batch=true. The compiler compile the first n page that found on the folder un-compiled.
Also compiles all the modules that need for the page that you run. When again found one other page that have not been compiled then again compile a second set of n files.
The limits of the how many files are compile with the batch=true, are set from the compilation settings .
If I understand well you search a way to seed up the developmental.
For your development computer I suggest 2 settings.
<compilation batch="false" optimizeCompilations="true" ... >
When batch=false then only the file you ask is called. When optimizeCompilations=true then the compiler did not build the functions on the dlls, nether some cache files if they have not change.
Read also: Slow Performance -- ASP .NET ASPNET_WP.EXE and CSC.EXE Running After Clicking Redirect Link
If you have problems with the compilations then set optimizeCompilations=false.
When the optimizeCompilations is on, there are case that the compile can not understand the change of a function and you get errors. One case is when you have a function call, and change the function by just adding an argument with a default value (net4). In this case the compiler did not compile it again, and this some times product errors.
However when a page is requested the first time, only that page is compiled?
If your application is a website,when it calls first time that aspx page compile automatically.But not for web application it will compile once when you build
So is it possible to compile part of a dll file?
Means you want to compile particular part of a project.

Optimize loading an XAP file with an asp.net website

I've been developing a game using Silverlight 4 and silversprite (http://silversprite.codeplex.com/)
This game is HEAVILY content dependent, using a lot of audio and images. My content folder is around 90 mbs worth of stuff.
And because of that, my XAP file is around 60 MB, and takes 5 minutes to download from the website before any user can start playing.
I am using Visual Web Developer 2010 to create my site and load the XAP. Is there a way where I can take content out of my XAP and put it in my ASP.net site project? Or perhaps upload my content files to the site's storage?
This would make my XAP file much quicker to download.
Anyone have suggestions?
Thanks!
Yes, include in your XAP only content you need for the initial screen. Place other content you need in other XAPs (if you need to and understand the manifest xml) or just plain zip files would do. Perhaps a Zip for each "Level" or whatever.
You can download the Zip with WebClient and then use StreamResourceInfo and Application.GetResourceStream to access content in the zip file.
This blog although aging a little now still carries the basic idea and is still fundementally the current technique to use.
Absolutley its called Application Library Caching. Ive used it very successfully its now a standard operating procedure, particularly nice is its application with resource assemblies.
straight from msdn ...
Resource files are typically any non-executable data file used by your application, such as image, audio, and video files. A resource file can also have specific meanings in certain contexts. For example, in the context of application localization, resource files refer to .resx files, which you can deploy in localized satellite assemblies.
it continues with some really useful info
With Silverlight, you can deploy
resource files in the following ways:
•As individual files in the
application package.
•As individual files that you retrieve
on demand.
•As files embedded in an assembly in
the application package.
•As files embedded in an assembly in
an external library package.
•As files embedded in an assembly that
you retrieve on demand.
which is what is suggested in the other answer(s)

ASP.NET JavaScript File Embeded In DLL With GZIP

We have several fairly large JavaScript files embedded into a single script resources DLL. This is then consumed by multiple projects by way of a reference and page includes via the ASP.NET script manager. This keeps things nice and neat within our ASP.NET pages and requires very little work to integrate into new projects.
The problem is that some of these script files are quite larger (approx 100KB) and take time to download. By running minify on them before embedding this is reduced down a lot (around 70KB) but not enough. What we would like to do is GZIP the files before they are embedded. However, just gzipping the files causes syntax errors as the content is not unzipped. There is a content type "text/javascript" applied in AssemblyInfo when the resource is embedded but we can't find a way to specify content-encoding.
Is there any way to make this work without having to write a httpmodule/handler (which would mean changing the config for all consuming projects)?
Okay, so it looks, from many different attempts, an absence of answers and a lot of Google searching, that the HttpModule is the only way to approach this. In an attempt to keep this easy to configure I've setup an HttpModule inside the same dll containing the script files as below.
Simplified DLL Structure
\ScriptMinified\*.js [Embedded Resource] (Minified Only)
\ScriptCompressed\*.gz [Embedded Resource] (Gzipped and Minified)
\ScriptDebug\*.js [Embedded Resource] (Raw uncompressed and commented)
MyScriptManager.cs
MyHttpModule.cs
The only additional work is an entry in the consumer's web config to enable the module. Plus I've made the initialize call, in MyScriptManager, that includes the script tags, detect the presence/mode of the new http module and serve gziped, debug or minimized versions as required. This means we don't have to recode or configure any old projects for them to work so achieves much the same result.

Resources