Assembly.Location 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取包含清单的已加载文件的完整路径或 UNC 位置。
public:
virtual property System::String ^ Location { System::String ^ get(); };
public virtual string Location { get; }
member this.Location : string
Public Overridable ReadOnly Property Location As String
属性值
包含清单的已加载文件的位置。 如果程序集是从字节数组加载的,例如在使用 Load(Byte[])时,返回的值是空字符串 (“”) 。
实现
例外
当前的程序集是动态程序集,由 AssemblyBuilder 对象表示。
示例
以下示例显示包含清单的已加载文件的位置。
Assembly^ SampleAssembly;
// Instantiate a target object.
Int32 Integer1(0);
Type^ Type1;
// Set the Type instance to the target class type.
Type1 = Integer1.GetType();
// Instantiate an Assembly class to the assembly housing the Integer type.
SampleAssembly = Assembly::GetAssembly( Integer1.GetType() );
// Display the physical location of the assembly containing the manifest.
Console::WriteLine( "Location= {0}", SampleAssembly->Location );
// The example displays the following output:
// Location=C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll
Assembly SampleAssembly;
// Instantiate a target object.
Int32 Integer1 = new Int32();
Type Type1;
// Set the Type instance to the target class type.
Type1 = Integer1.GetType();
// Instantiate an Assembly class to the assembly housing the Integer type.
SampleAssembly = Assembly.GetAssembly(Integer1.GetType());
// Display the physical location of the assembly containing the manifest.
Console.WriteLine("Location=" + SampleAssembly.Location);
// The example displays the following output:
// Location=C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll
Dim SampleAssembly As [Assembly]
' Instantiate a target object.
Dim Integer1 As New Int32()
Dim Type1 As Type
' Set the Type instance to the target class type.
Type1 = Integer1.GetType()
' Instantiate an Assembly class to the assembly housing the Integer type.
SampleAssembly = [Assembly].GetAssembly(Integer1.GetType())
' Display the physical location of the assembly containing the manifest.
Console.WriteLine(("Location=" + SampleAssembly.Location))
' The example displays the following output:
' Location=C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll
注解
在 .NET 5 及更高版本中,对于捆绑程序集,返回的值是空字符串。
仅.NET Framework:如果加载的文件是卷影复制的,则文件在卷影复制后的位置为该文件的位置。 若要获取文件被卷影复制之前的位置,请使用 CodeBase 属性。