1
我正在構建動態DLL,並且寫入FileVersion不起作用。動態創建DLL文件版本不起作用
的代碼我使用的是從Microsoft鏈接和我期待的EXE/DLL版本爲1.0.0.2001: http://msdn.microsoft.com/en-us/library/system.reflection.assemblyname.version.aspx
public static void Main()
{
// Create a dynamic assembly with name 'MyAssembly' and build version '1.0.0.2001'.
AssemblyName myAssemblyName = new AssemblyName();
myAssemblyName.Name = "MyAssembly";
myAssemblyName.Version = new Version("1.0.0.2001");
MakeAssembly(myAssemblyName, "MyAssembly.exe");
}
public static void MakeAssembly(AssemblyName myAssemblyName, string fileName)
{
// Get the assembly builder from the application domain associated with the current thread.
AssemblyBuilder myAssemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(myAssemblyName, AssemblyBuilderAccess.RunAndSave);
// Create a dynamic module in the assembly.
ModuleBuilder myModuleBuilder = myAssemblyBuilder.DefineDynamicModule("MyModule", fileName);
// Create a type in the module.
TypeBuilder myTypeBuilder = myModuleBuilder.DefineType("MyType");
// Create a method called 'Main'.
MethodBuilder myMethodBuilder = myTypeBuilder.DefineMethod("Main", MethodAttributes.Public | MethodAttributes.HideBySig |
MethodAttributes.Static, typeof(void), null);
// Get the Intermediate Language generator for the method.
ILGenerator myILGenerator = myMethodBuilder.GetILGenerator();
// Use the utility method to generate the IL instructions that print a string to the console.
myILGenerator.EmitWriteLine("Hello World!");
// Generate the 'ret' IL instruction.
myILGenerator.Emit(OpCodes.Ret);
// End the creation of the type.
myTypeBuilder.CreateType();
// Set the method with name 'Main' as the entry point in the assembly.
myAssemblyBuilder.SetEntryPoint(myMethodBuilder);
myAssemblyBuilder.Save(fileName);
}
但實際的結果是沒有文件版本寫的是:
檢查** AssemblyBuilder.DefineVersionInfoResource **的MSDN文檔(http://msdn.microsoft.com/zh-cn/library/14dk10z1。 aspx)那裏的例子部分可能有你正在尋找的代碼。但是,我不是100%確定的,因爲我沒有測試過自己(不要混淆文檔是針對看似無關的屬性的,這個例子很重要。) – elgonzo
@elgonzo非常感謝你。提示在[so]註釋中使用超鏈接的[Name](http://)語法。 –
感謝您的超鏈接提示:) – elgonzo