Index: Doc/Extra/Provider/environment.html
==================================================================
--- Doc/Extra/Provider/environment.html
+++ Doc/Extra/Provider/environment.html
@@ -57,13 +57,22 @@
%PreLoadSQLite_XmlConfigDirectory% |
If this token (which is case-sensitive and must include
the percent characters) is present within a setting value
Index: System.Data.SQLite/Configurations/System.Data.SQLite.dll.config
==================================================================
--- System.Data.SQLite/Configurations/System.Data.SQLite.dll.config
+++ System.Data.SQLite/Configurations/System.Data.SQLite.dll.config
@@ -20,10 +20,18 @@
case-sensitive and must include the percent characters) is
present within a setting value being returned, it will be
replaced with the qualified name of the directory containing the
System.Data.SQLite assembly. If the name of the directory is not
available, the token will not be replaced.
+
+ NOTE: %PreLoadSQLite_TargetFramework% - If this token (which is
+ case-sensitive and must include the percent characters) is
+ present within a setting value being returned, it will be
+ replaced with an abbreviation of the target framework attribute
+ value for the System.Data.SQLite assembly. If the target
+ framework attribute value is not available, the token will not be
+ replaced.
NOTE: %PreLoadSQLite_XmlConfigDirectory% - If this token (which is
case-sensitive and must include the percent characters) is
present within a setting value being returned, it will be
replaced with the qualified name of the directory containing the
Index: System.Data.SQLite/UnsafeNativeMethods.cs
==================================================================
--- System.Data.SQLite/UnsafeNativeMethods.cs
+++ System.Data.SQLite/UnsafeNativeMethods.cs
@@ -21,13 +21,17 @@
#if !PLATFORM_COMPACTFRAMEWORK
using System.Security;
#endif
using System.Runtime.InteropServices;
+
+#if (NET_40 || NET_45 || NET_451 || NET_452 || NET_46 || NET_461 || NET_462) && !PLATFORM_COMPACTFRAMEWORK
+ using System.Runtime.Versioning;
+#endif
#if !PLATFORM_COMPACTFRAMEWORK
- using System.Text;
+ using System.Text;
#endif
#if !PLATFORM_COMPACTFRAMEWORK || COUNT_HANDLE
using System.Threading;
#endif
@@ -600,10 +604,19 @@
/// This is the environment variable token that will be replaced with
/// the qualified path to the directory containing this assembly.
///
private static readonly string AssemblyDirectoryToken =
"%PreLoadSQLite_AssemblyDirectory%";
+
+ /////////////////////////////////////////////////////////////////////////
+ ///
+ /// This is the environment variable token that will be replaced with an
+ /// abbreviation of the target framework attribute value associated with
+ /// this assembly.
+ ///
+ private static readonly string TargetFrameworkToken =
+ "%PreLoadSQLite_TargetFramework%";
#endif
#endregion
/////////////////////////////////////////////////////////////////////////
@@ -947,10 +960,88 @@
}
/////////////////////////////////////////////////////////////////////////
#if !PLATFORM_COMPACTFRAMEWORK
+ ///
+ /// Attempts to determine the target framework attribute value that is
+ /// associated with the specified managed assembly, if applicable.
+ ///
+ ///
+ /// The managed assembly to read the target framework attribute value
+ /// from.
+ ///
+ ///
+ /// The value of the target framework attribute value for the specified
+ /// managed assembly -OR- null if it cannot be determined. If this
+ /// assembly was compiled with a version of the .NET Framework prior to
+ /// version 4.0, the value returned MAY reflect that version of the .NET
+ /// Framework instead of the one associated with the specified managed
+ /// assembly.
+ ///
+ private static string GetAssemblyTargetFramework(
+ Assembly assembly
+ )
+ {
+ if (assembly != null)
+ {
+#if (NET_40 || NET_45 || NET_451 || NET_452 || NET_46 || NET_461 || NET_462) && !PLATFORM_COMPACTFRAMEWORK
+ try
+ {
+ if (assembly.IsDefined(
+ typeof(TargetFrameworkAttribute), false))
+ {
+ TargetFrameworkAttribute targetFramework =
+ (TargetFrameworkAttribute)
+ assembly.GetCustomAttributes(
+ typeof(TargetFrameworkAttribute), false)[0];
+
+ return targetFramework.FrameworkName;
+ }
+ }
+ catch
+ {
+ // do nothing.
+ }
+#elif NET_35
+ return ".NETFramework,Version=v3.5";
+#elif NET_20
+ return ".NETFramework,Version=v2.0";
+#endif
+ }
+
+ return null;
+ }
+
+ /////////////////////////////////////////////////////////////////////////
+
+ ///
+ /// Accepts a long target framework attribute value and makes it into a
+ /// much shorter version, suitable for use with NuGet packages.
+ ///
+ ///
+ /// The long target framework attribute value to convert.
+ ///
+ ///
+ /// The short target framework attribute value -OR- null if it cannot
+ /// be determined or converted.
+ ///
+ private static string AbbreviateTargetFramework(
+ string value
+ )
+ {
+ if (String.IsNullOrEmpty(value))
+ return value;
+
+ value = value.Replace(".NETFramework,Version=v", "net");
+ value = value.Replace(".", String.Empty);
+
+ return value;
+ }
+
+ /////////////////////////////////////////////////////////////////////////
+
///
/// If necessary, replaces all supported environment variable tokens
/// with their associated values.
///
///
@@ -985,12 +1076,71 @@
#if !NET_COMPACT_20 && TRACE_SHARED
try
{
Trace.WriteLine(HelperMethods.StringFormat(
CultureInfo.CurrentCulture, "Native library " +
- "pre-loader failed to replace environment " +
- "variable tokens: {0}", e)); /* throw */
+ "pre-loader failed to replace assembly " +
+ "directory token: {0}", e)); /* throw */
+ }
+ catch
+ {
+ // do nothing.
+ }
+#endif
+ }
+ }
+
+ Assembly assembly = null;
+
+ try
+ {
+ assembly = Assembly.GetExecutingAssembly();
+ }
+#if !NET_COMPACT_20 && TRACE_SHARED
+ catch (Exception e)
+#else
+ catch (Exception)
+#endif
+ {
+#if !NET_COMPACT_20 && TRACE_SHARED
+ try
+ {
+ Trace.WriteLine(HelperMethods.StringFormat(
+ CultureInfo.CurrentCulture, "Native library " +
+ "pre-loader failed to obtain executing " +
+ "assembly: {0}", e)); /* throw */
+ }
+ catch
+ {
+ // do nothing.
+ }
+#endif
+ }
+
+ string targetFramework = AbbreviateTargetFramework(
+ GetAssemblyTargetFramework(assembly));
+
+ if (!String.IsNullOrEmpty(targetFramework))
+ {
+ try
+ {
+ value = value.Replace(
+ TargetFrameworkToken, targetFramework);
+ }
+#if !NET_COMPACT_20 && TRACE_SHARED
+ catch (Exception e)
+#else
+ catch (Exception)
+#endif
+ {
+#if !NET_COMPACT_20 && TRACE_SHARED
+ try
+ {
+ Trace.WriteLine(HelperMethods.StringFormat(
+ CultureInfo.CurrentCulture, "Native library " +
+ "pre-loader failed to replace target " +
+ "framework token: {0}", e)); /* throw */
}
catch
{
// do nothing.
}
Index: Tests/tkt-d4728aecb7.eagle
==================================================================
--- Tests/tkt-d4728aecb7.eagle
+++ Tests/tkt-d4728aecb7.eagle
@@ -23,23 +23,25 @@
moveSystemDataSQLiteDllConfig false
###############################################################################
set d472_binary_directory [string map [list \\ /] [getBinaryDirectory]]
+set d472_target_framework [string map [list Fx ""] [getBuildNetFx]]
###############################################################################
runTest {test tkt-d4728aecb7-1.1 {tokens in environment variable} -setup \
[getAppDomainPreamble] -body {
package require Eagle.Library
package require Eagle.Test
package require System.Data.SQLite.Test
- saveEnvironmentVariables [list d472_1 d472_2] savedEnv
+ saveEnvironmentVariables [list d472_1 d472_2 d472_3] savedEnv
set env(d472_1) {prfx1/%PreLoadSQLite_AssemblyDirectory%/sufx1}
- set env(d472_2) {prfx2/%PreLoadSQLite_XmlConfigDirectory%/sufx2}
+ set env(d472_2) {prfx2/%PreLoadSQLite_TargetFramework%/sufx2}
+ set env(d472_3) {prfx3/%PreLoadSQLite_XmlConfigDirectory%/sufx3}
object load -loadtype File [file join \
[getBinaryDirectory] System.Data.SQLite.dll]
set result [list]
@@ -48,19 +50,22 @@
System.Data.SQLite.UnsafeNativeMethods GetSettingValue d472_1 null]]
lappend result [string map [list \\ /] [object invoke -flags +NonPublic \
System.Data.SQLite.UnsafeNativeMethods GetSettingValue d472_2 null]]
+ lappend result [string map [list \\ /] [object invoke -flags +NonPublic \
+ System.Data.SQLite.UnsafeNativeMethods GetSettingValue d472_3 null]]
+
set result
} -cleanup {
- restoreEnvironmentVariables [list d472_1 d472_2] savedEnv
+ restoreEnvironmentVariables [list d472_1 d472_2 d472_3] savedEnv
unset -nocomplain result
} -isolationLevel AppDomain -constraints {eagle command.object\
compile.ISOLATED_INTERPRETERS System.Data.SQLite} -result [list [appendArgs \
-prfx1/ $d472_binary_directory /sufx1] \
-prfx2/%PreLoadSQLite_XmlConfigDirectory%/sufx2]}
+prfx1/ $d472_binary_directory /sufx1] [appendArgs prfx2/ \
+$d472_target_framework /sufx2] prfx3/%PreLoadSQLite_XmlConfigDirectory%/sufx3]}
###############################################################################
runTest {test tkt-d4728aecb7-1.2 {tokens in XML configuration file} -setup \
[getAppDomainPreamble] -body {
@@ -78,11 +83,13 @@
+ value="prfx2/%PreLoadSQLite_TargetFramework%/sufx2" />
+
}]
object load -loadtype Bytes [base64 encode [readFile [file join \
@@ -94,10 +101,13 @@
System.Data.SQLite.UnsafeNativeMethods GetSettingValue d472_1 null]]
lappend result [string map [list \\ /] [object invoke -flags +NonPublic \
System.Data.SQLite.UnsafeNativeMethods GetSettingValue d472_2 null]]
+ lappend result [string map [list \\ /] [object invoke -flags +NonPublic \
+ System.Data.SQLite.UnsafeNativeMethods GetSettingValue d472_3 null]]
+
set result
} -cleanup {
catch {file delete $fileName}
unset -nocomplain result fileName
@@ -104,19 +114,20 @@
moveSystemDataSQLiteDllConfig true
} -isolationLevel AppDomain -constraints {eagle command.object\
compile.ISOLATED_INTERPRETERS System.Data.SQLite} -result [list [appendArgs \
prfx1/ $d472_binary_directory /sufx1] [appendArgs prfx2/ \
-$d472_binary_directory /sufx2]]}
+$d472_target_framework /sufx2] [appendArgs prfx3/ $d472_binary_directory \
+/sufx3]]}
###############################################################################
-unset -nocomplain d472_binary_directory
+unset -nocomplain d472_target_framework d472_binary_directory
###############################################################################
moveSystemDataSQLiteDllConfig true
###############################################################################
runSQLiteTestEpilogue
runTestEpilogue
|