How to load project references from a sub directory in C# and VB.NET

To load project references from a sub directory in C# and VB.NET you simply need to add the element to your app.config file.

  • assemblyBinding: Contains information about assembly version redirection and the locations of assemblies.
  • configuration: The root element in every configuration file used by the common language runtime and .NET Framework applications.
  • runtime: Contains information about assembly binding and garbage collection.
  • Sample XML

    <configuration>
       <runtime>
          <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
             <probing privatePath="bin;bin2\subbin;bin3"/>
          </assemblyBinding>
       </runtime>
    </configuration>
    

    Please rate this snippet

    How to get the BuildDate of a Assembly in C# and VB.NET

    Sample C#

    public DateTime GetBuildDate(Assembly assembly)
    {
    	var location = assembly.Location;
    	const int headerOffset = 60;
    	const int linkerTimestampOffset = 8;
    	var buffer = new byte[2048];
    	Stream stream = null;
    
    	try
    	{
    		stream = new FileStream(location, FileMode.Open, FileAccess.Read);
    		stream.Read(buffer, 0, 2048);
    	}
    	finally
    	{
    		if (stream != null)
    		{
    			stream.Close();
    		}
    	}
    
    	var i = BitConverter.ToInt32(buffer, headerOffset);
    	var secondsSince1970 = BitConverter.ToInt32(buffer, i + linkerTimestampOffset);
    	var dt = new DateTime(1970, 1, 1, 0, 0, 0);
    	dt = dt.AddSeconds(secondsSince1970);
    	dt = dt.AddHours(TimeZone.CurrentTimeZone.GetUtcOffset(dt).Hours);
    	return dt;
    }
    

    Sample VB.NET

    Public Function GetBuildDate(assembly as Assembly) As DateTime
    	Dim location = assembly.Location
    	Const  headerOffset As Integer = 60
    	Const  linkerTimestampOffset As Integer = 8
    	Dim buffer = New Byte(2047) {}
    	Dim stream As Stream = Nothing
    
    	Try
    		stream = New FileStream(location, FileMode.Open, FileAccess.Read)
    		stream.Read(buffer, 0, 2048)
    	Finally
    		If stream IsNot Nothing Then
    			stream.Close()
    		End If
    	End Try
    
    	Dim i = BitConverter.ToInt32(buffer, headerOffset)
    	Dim secondsSince1970 = BitConverter.ToInt32(buffer, i + linkerTimestampOffset)
    	Dim dt = New DateTime(1970, 1, 1, 0, 0, 0)
    	dt = dt.AddSeconds(secondsSince1970)
    	dt = dt.AddHours(TimeZone.CurrentTimeZone.GetUtcOffset(dt).Hours)
    	Return dt
    End Function
    

    Please rate this snippet