Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Per-Page Javascript files from one project using Script#?

Tags:

script#

Is it possible to have one Script# project and make multiple Javascript files out of it? What I'd like to do is have one Script# project and have it emit one Javascript file per class or namespace. I know that you can't really generate multiple DLLs out of a .NET class project, but in this case it would be helpful to have the Javascript split out so you're not loading the whole thing. Or am I thinking about this the wrong way? I'm using VS2010.

like image 776
Rob Avatar asked Sep 24 '26 08:09

Rob


1 Answers

Yes, you can... but you have to be careful when you start doing this.

In your csproj, you can add the property

<WebAppPartitioning>True</WebAppPartitioning>

This will tell the script# build task to build a .js file per top-level folder in your project. Any code you want to include into every .js file can be put into a top-level folder named "Shared".

Here is where you need to be careful - the c# compiler compiles the entire project rather than one folder at a time. So for example, its easy for one folder to reference code in another folder, and csc.exe will compile just fine. The script# won't see things the same way, since it only looks at a folder at a time. However, the script# compiler was written to assume the code compiled using it was first successfully compiled with c#. So this whole per-folder compile model violates a basic design assumption.

Hence if you use this feature, you'll need to be careful. Hope that helps.

like image 71
Nikhil Kothari Avatar answered Sep 26 '26 01:09

Nikhil Kothari



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!