Insert AssemblyInfo (e.g. DLL versionno) in embedded JavaScript

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?

Upvotes: 0

Views: 157

Answers (2)

Jan Köhler
Jan Köhler

Reputation: 6030

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.

Upvotes: 0

537mfb
537mfb

Reputation: 1482

Without your code i can't tell what you do with that JS file but here's an idea:

  1. Read the content of the JS file into a string
  2. Replace in that string some token with the DLL AssemblyInfo value you need
  3. Either evaluate the string or save it to a temp file (depends on what you need it for)

Upvotes: 1

Related Questions