My C# dll has an embedded Javascript file. In the header of this file I want to include the version information. Is it posible to insert in the DLL AssemblyInfo (e.g. dll version) in the JS file?
Asked
Active
Viewed 121 times
0
-
2Please elaborate your question a little bit further and show some code. – Jan Köhler Jul 13 '16 at 08:08
-
Hi, thanks for your comment. What's more to eleborate? A C# project, Javascript file embedded in the assembly, Our platform is using that file, and it would be helpfull if the javascript file contains the build version of the assembly. – Matthijs Sint Nicolaas Jul 13 '16 at 08:17
-
Check this question as well, it might be duplicate: http://stackoverflow.com/questions/26021684/how-to-automatically-insert-version-number-into-assemblyname – Farside Jul 13 '16 at 08:20
-
1@Farside - not seeing any relationship between that question and this one – 537mfb Jul 13 '16 at 08:36
2 Answers
1
Without your code i can't tell what you do with that JS file but here's an idea:
- Read the content of the JS file into a string
- Replace in that string some token with the DLL AssemblyInfo value you need
- Either evaluate the string or save it to a temp file (depends on what you need it for)

537mfb
- 1,374
- 1
- 16
- 32
-
Is it possible to write the changed string back to the resource? – Matthijs Sint Nicolaas Jul 13 '16 at 09:25
-
This is what I meant by "please elaborate it a bit further" ;-) We have no idea about your project structure. What do you mean by "the resource" in this context? – Jan Köhler Jul 13 '16 at 09:28
-
the resource is "the embedded javascriptfile" as mentioned in my question. What do you need to know about the project structure to answer the question if its possible to write back in an embedded resource? – Matthijs Sint Nicolaas Jul 13 '16 at 09:31
-
apparently the embedded resources in an assembly are readonly. So writing back to it is kind of impossible. Our platform requires the javascript file to be an embedded source file of the assembly. To writiing to an other file or location is not an option. I was hoping for a way of using some kind of Compiler constant or something (a constant replaced during build/compilation of the source file). Amy thoughts? – Matthijs Sint Nicolaas Jul 13 '16 at 09:37
-
@MatthijsSintNicolaas as you figured out, resources are readonly - but you shouldn't need it to be in the JS - simply always get the content through a nethod that makes the replacements - and either returns the content with the replacements done or a location on disk of a temp file with it - depends on your needs - You should explain what you use that js file for to get better help – 537mfb Jul 13 '16 at 11:15
-
@537mfb Out platform reads the JS to use in a webinterface. Therefor I cannot move it or save it to another file. It needs to be an embedded resource. – Matthijs Sint Nicolaas Jul 13 '16 at 12:49
-
@MatthijsSintNicolaas yes - my point is when reading it should apply the replace before using it. WebInterface requests the JS from the DLL - DLL delivers the JS with the replace done. Your webinterface either need the content or a file (i don't know) - simply have the dll deliver it after applying a replace to it – 537mfb Jul 13 '16 at 13:42
0
Maybe you could use the T4 templating engine in a way similar to this.
This will e.g. translate a someFile.tt
to someFile.js
:
<#@ output extension=".js" encoding="utf-8" #>
// This file was created at <#= DateTime.Now #>
// It's version is <#= System.Reflection.Assembly.GetExecutingAssembly().GetName().Version #>
function foo() {
console.log("bar");
}
Unfortunately this snippet won't do the trick for you. It has at least two flaws:
- Does not get executed on each build. Maybe have a look at this answer to find a way around it.
- Does not insert your project's assembly version into the output. You'll have to find a way to do so by finding your
AssemblyInfo.cs
and read the version from there.
So although this advice won't be perfect it may give you a starting point.

Community
- 1
- 1

Jan Köhler
- 5,817
- 5
- 26
- 35