How do I get the assembly name at compile time?

D

Dave

Surely it must be possible to access an assembly's name (ie the name of the
..exe or .dll file to which it will eventually compile) at compile time. All
the information is available within VS, but how do I get at it?

(Actually what I'd like to do is get the assembly name of a referenced
assembly, but I'm hoping that if I can do the first the second will be
trivial).

(NB- I know it can be acquired at runtime using reflection, that's not what
I'm asking.)
 
P

Peter Macej

The following macro shows project assembly name and then all referenced
assemblies names and paths:

Sub ShowAssemblies()
Dim project As EnvDTE.Project
project = DTE.Solution.Projects.Item(1)

Dim text As String

' get project assembly
text = "Project assembly: "
text &= project.Properties.Item("AssemblyName").Value.ToString
text &= vbCrLf & vbCrLf

' get references assemblies (will not work for web site projects)
Dim vsProject As VSLangProj.VSProject
Try
vsProject = DirectCast(project.Object, VSLangProj.VSProject)
Catch ex As Exception
End Try
If Not vsProject Is Nothing Then
Dim reference As VSLangProj.Reference
For Each reference In vsProject.References
text &= reference.Name & ": "
text &= reference.Path & vbCrLf
Next
End If

' show results
MessageBox.Show(text)
End Sub

Create this macro and run, see http://www.helixoft.com/blog/archives/6
if you don't know how.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top