scriptsharp icon indicating copy to clipboard operation
scriptsharp copied to clipboard

Control over generated file names

Open stevehobbsdev opened this issue 13 years ago • 1 comments

Is there a way we could potentially have control over the file names that are generated from Script# libraries, for both the minified and debug files?

Imagine I have a Script# project simply called 'Scripts'; the files which are currently generated are called 'Scripts.debug.js' and 'Scripts.js' for the debug and minified versions respectively.

In order to play nicely with the new Asp.Net MVC 4 Bundling support, and to bring it inline with convention, it would be nicer if we could somehow specify that the debug and minified files were actually called 'scripts.js' and 'scripts.min.js' respectively.

I could imagine that we might do this through the Project file by using a couple of keys and macros, for example:

<DebugScriptName>${ScriptName}.js</DebugScriptName>
<MinScriptName>${ScriptName}.min.js</MinScriptName>

Or something to that effect.

The reason I've mentioned Bundling is because it has some interesting behaviours regarding how it treats files with 'conventional' file names (I've outlined this in a blog post). It will automatically favour .min files when bundling a directory, but also actually completely ignores files with a .debug.js extension, which means we would never be able to implement a custom minifier (should we happen to require one).

stevehobbsdev avatar Feb 24 '12 08:02 stevehobbsdev

You have full control over what gets generated, flags, localized file names etc. when using ssc.exe. The msbuild equivalent of ssc.exe is ScriptCompilerExecTask (instead of the default ScriptCompilerTask that is referenced by ScriptSharp.targets).

See https://github.com/nikhilk/scriptsharp/blob/master/src/Tools/Build/Tasks/ScriptCompilerExecTask.cs for the implementation. To use it you'll have to stop importing ScriptSharp.targets, and define your own post build steps to invoke this other task.

Of course, you could also add support for specifying output file names, since the code for the msbuild tasks is available and you can modify it. If you do so, you also need to account for localization which either affects the file name to include a locale, or puts the generated file in a locale subfolder.

As more context, here is what I'd like to eventually have happen.

Right now the msbuild task produces both debug and release versions for each c# build flavor. I'd like to fix that and have debug only be generated by the debug configuration, and release only with release configuration. In both cases the generated file name would be just ${ScriptName}.js. Minimization would be a separate step and the goal is to allow plugging in different minimizers. The result of minimization would be in ${ScriptName}.min.js.

So in that world you'd see bin\Debug${ScriptName}.js, bin\Debug${ScriptName}.min.js, bin\Release${ScriptName}.js and bin\Release${ScriptName}.min.js.

nikhilk avatar Feb 24 '12 16:02 nikhilk