Newbie looking for some help please.
I am creating a DLL with compiled regular expressions by following this MS article:
The generate DLL is functional and the regular expressions work as expected.
But I would like to be able to control the version information seen in the DLL properties (when you click on Properties from the right-click menu in Windows Explorer). I want the version info to match that of the project executable. So I have tried to pass the version information into the Regex.CompileToAssembly method. But I can’t seem to get this to work. When I look at the properties of the DLL that is generated, I do not see the version information set.
How can I get the version property set?
Thanks for any kind help! Dan
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using System.Text.RegularExpressions;
namespace MakeRegExDLL
{
class MakeRegExDLL
{
// We will run this executable as a post-build step to generate the DLL
static void Main()
{
// Local variables
RegexCompilationInfo regex;
List<RegexCompilationInfo> regexList = new List<RegexCompilationInfo>();
regex = new RegexCompilationInfo(
@"[\dY]{4}-[01M][\dM]-[0123D][\dD]",
RegexOptions.IgnoreCase,
"FindDate",
"MakeRegExDLL",
true);
regexList.Add(regex);
// Copy our regex into compile info array
RegexCompilationInfo[] regexArray = new RegexCompilationInfo[regexList.Count];
regexList.CopyTo(regexArray);
// Get the current assembly object
string exeFile = System.Reflection.Assembly.GetEntryAssembly().Location;
AssemblyName currentAssembly = AssemblyName.GetAssemblyName(exeFile);
// Create the assembly name object for DLL
string assemblyName = string.Format("{0}, Version={1}, Culture = neutral, PublicKeyToken = null",
currentAssembly.Name, currentAssembly.Version);
AssemblyName regexAssembly = new AssemblyName(assemblyName);
// Setup AssemblyVersionAttribute
Type[] assemVAParams = { typeof(string) };
object[] assemVAValues = { currentAssembly.Version.ToString() };
ConstructorInfo assemVACtor = typeof(AssemblyVersionAttribute).GetConstructor(assemVAParams);
// Setup AssemblyFileVersionAttribute
Type[] assemFVAParams = { typeof(string) };
object[] assemFVAValues = { currentAssembly.Version.ToString() };
ConstructorInfo assemFVACtor = ypeof(AssemblyFileVersionAttribute).GetConstructor(assemFVAParams);
// Setup AssemblyProductAttribute
Type[] assemPAParams = { typeof(string) };
object[] assemPAValues = { currentAssembly.Version.ToString() };
ConstructorInfo assemPACtor = typeof(AssemblyProductAttribute).GetConstructor(assemPAParams);
// Create the CustomAttributeBuilder object array
CustomAttributeBuilder[] attBuilder = {
new CustomAttributeBuilder(assemVACtor, assemVAValues),
new CustomAttributeBuilder(assemFVACtor, assemFVAValues),
new CustomAttributeBuilder(assemPACtor, assemPAValues) };
// Create the DLL
Regex.CompileToAssembly(regexArray, regexAssembly, attBuilder);
}
}
}
