controlLibrary my.application dosnt working
I have built a Wpf-ControLibrary-Project to put some Controls there. In one Control i need to get some informations about assambly, Version and directory path.
in the past i have done this one:
Dim msg As String
msg = "AssemblyName: " & My.Application.Info.AssemblyName & Environment.NewLine
msg &= "Version: " & My.Application.Info.Version.ToString &a开发者_如何学Cmp; Environment.NewLine
msg &= "DirectoryPath: " & My.Application.Info.DirectoryPath
MsgBox(msg)
but this doesnt working anymore. I get an Error which told me that Application isn't Party of the My Namespace. So, how i get this Informations?
You should be able to get all the information with this code (C# code but its trivial to convert it to VB)
System.Reflection.Assembly executingAssembly = System.Reflection.Assembly.GetExecutingAssembly();
System.Reflection.AssemblyName assemblyName = executingAssembly.GetName();
string name = assemblyName.Name;
System.Version version = assemblyName.Version;
string path = executingAssembly.Location;
This will give you information about the assembly that is currently executing (your control library dll). If you want information about you application assembly you can use:
System.Reflection.Assembly entryAssembly = System.Reflection.Assembly.GetEntryAssembly();
The project template you use is missing the code generator that puts the My namespace together. You can still use it if you code it like this:
Dim myapp As New ApplicationServices.ApplicationBase
Dim name As String = myapp.Info.AssemblyName
' etc...
精彩评论