A quick pre-Thanksgiving tip that came from an internal discussion today: how to find the location of a .NET module (meaning the currently executing assembly).
Two techniques were identified:
- Identify the current assembly by asking where one of its types is defined
- Use the Assembly.GetExecutingAssembly() to get the assembly from where the current code is executing
Here's the C# code showing the two techniques:
using System;
using System.Reflection;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
namespace AssemblyLocationTest
{
public class AssemblyCmds
{
[CommandMethod("LOC")]
public void GetModuleLocation()
{
Editor ed =
Application.DocumentManager.MdiActiveDocument.Editor;
// First technique
Type type = typeof(AssemblyCmds);
Assembly asm1 = type.Assembly;
ed.WriteMessage(
"\nAssembly location (1) is: "
+ asm1.Location
);
// Second technique
Assembly asm2 = Assembly.GetExecutingAssembly();
ed.WriteMessage(
"\nAssembly location (2) is: "
+ asm2.Location
);
}
}
}
And here are the results, just to show they return the same thing:
Command: loc
Assembly location (1) is: C:\temp\MyAssembly.dll
Assembly location (2) is: C:\temp\MyAssembly.dll