From 06891d39973eb7bbf080657a57acd6180d4d85ae Mon Sep 17 00:00:00 2001 From: Sander van der Burg Date: Tue, 13 Sep 2011 15:47:54 +0000 Subject: Improved the wrapper: it is now a separate component invoking the executable's main method through the refelection API svn path=/nixpkgs/trunk/; revision=29239 --- pkgs/build-support/dotnetenv/Wrapper/Wrapper.sln | 20 ++++++ .../Wrapper/Wrapper/Properties/AssemblyInfo.cs | 36 ++++++++++ .../dotnetenv/Wrapper/Wrapper/Wrapper.cs.in | 78 ++++++++++++++++++++++ .../dotnetenv/Wrapper/Wrapper/Wrapper.csproj.in | 57 ++++++++++++++++ 4 files changed, 191 insertions(+) create mode 100644 pkgs/build-support/dotnetenv/Wrapper/Wrapper.sln create mode 100644 pkgs/build-support/dotnetenv/Wrapper/Wrapper/Properties/AssemblyInfo.cs create mode 100755 pkgs/build-support/dotnetenv/Wrapper/Wrapper/Wrapper.cs.in create mode 100644 pkgs/build-support/dotnetenv/Wrapper/Wrapper/Wrapper.csproj.in (limited to 'pkgs/build-support/dotnetenv/Wrapper') diff --git a/pkgs/build-support/dotnetenv/Wrapper/Wrapper.sln b/pkgs/build-support/dotnetenv/Wrapper/Wrapper.sln new file mode 100644 index 000000000000..f2e7d4cf8b2c --- /dev/null +++ b/pkgs/build-support/dotnetenv/Wrapper/Wrapper.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wrapper", "Wrapper\Wrapper.csproj", "{D01B3597-E85E-42F4-940A-EF5AE712942F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D01B3597-E85E-42F4-940A-EF5AE712942F}.Debug|x86.ActiveCfg = Debug|x86 + {D01B3597-E85E-42F4-940A-EF5AE712942F}.Debug|x86.Build.0 = Debug|x86 + {D01B3597-E85E-42F4-940A-EF5AE712942F}.Release|x86.ActiveCfg = Release|x86 + {D01B3597-E85E-42F4-940A-EF5AE712942F}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/pkgs/build-support/dotnetenv/Wrapper/Wrapper/Properties/AssemblyInfo.cs b/pkgs/build-support/dotnetenv/Wrapper/Wrapper/Properties/AssemblyInfo.cs new file mode 100644 index 000000000000..633d23c05ff2 --- /dev/null +++ b/pkgs/build-support/dotnetenv/Wrapper/Wrapper/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Wrapper")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Philips Healthcare")] +[assembly: AssemblyProduct("Wrapper")] +[assembly: AssemblyCopyright("Copyright © Philips Healthcare 2011")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("2045ce22-78c7-4cd6-ad0a-9367f8a49738")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/pkgs/build-support/dotnetenv/Wrapper/Wrapper/Wrapper.cs.in b/pkgs/build-support/dotnetenv/Wrapper/Wrapper/Wrapper.cs.in new file mode 100755 index 000000000000..4ea0d6ee6fab --- /dev/null +++ b/pkgs/build-support/dotnetenv/Wrapper/Wrapper/Wrapper.cs.in @@ -0,0 +1,78 @@ +using System; +using System.Reflection; +using System.IO; + +namespace @NAMESPACE@Wrapper +{ + class @MAINCLASSNAME@Wrapper + { + private String[] AssemblySearchPaths = { @ASSEMBLYSEARCHPATH@ }; + + private String ExePath = @"@EXEPATH@"; + + private String MainClassName = "@NAMESPACE@.@MAINCLASSNAME@"; + + private Assembly exeAssembly; + + public @MAINCLASSNAME@Wrapper(string[] args) + { + // Attach the resolve event handler to the AppDomain so that missing library assemblies will be searched + AppDomain currentDomain = AppDomain.CurrentDomain; + currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler); + + // Dynamically load the executable assembly + exeAssembly = Assembly.LoadFrom(ExePath); + + // Lookup the main class + Type mainClass = exeAssembly.GetType(MainClassName); + + // Lookup the main method + MethodInfo mainMethod = mainClass.GetMethod("Main"); + + // Invoke the main method + mainMethod.Invoke(this, new Object[] {args}); + } + + static void Main(string[] args) + { + new @MAINCLASSNAME@Wrapper(args); + } + + private Assembly MyResolveEventHandler(object sender, ResolveEventArgs args) + { + //This handler is called only when the common language runtime tries to bind to the assembly and fails. + + //Retrieve the list of referenced assemblies in an array of AssemblyName. + Assembly MyAssembly; + string assemblyPath = ""; + + AssemblyName[] referencedAssemblies = exeAssembly.GetReferencedAssemblies(); + + //Loop through the array of referenced assembly names. + foreach (AssemblyName assemblyName in referencedAssemblies) + { + //Check for the assembly names that have raised the "AssemblyResolve" event. + if (assemblyName.FullName.Substring(0, assemblyName.FullName.IndexOf(",")) == args.Name.Substring(0, args.Name.IndexOf(","))) + { + //Retrieve the name of the assembly from where it has to be loaded. + String dllName = args.Name.Substring(0, args.Name.IndexOf(",")) + ".dll"; + + //Search for the right path of the library assembly + foreach (String currentAssemblyPath in AssemblySearchPaths) + { + assemblyPath = currentAssemblyPath + "/" + dllName; + if (File.Exists(assemblyPath)) + break; + } + } + } + + //Load the assembly from the specified path. + MyAssembly = Assembly.LoadFrom(assemblyPath); + + //Return the loaded assembly. + return MyAssembly; + } + + } +} diff --git a/pkgs/build-support/dotnetenv/Wrapper/Wrapper/Wrapper.csproj.in b/pkgs/build-support/dotnetenv/Wrapper/Wrapper/Wrapper.csproj.in new file mode 100644 index 000000000000..a991bcb6933a --- /dev/null +++ b/pkgs/build-support/dotnetenv/Wrapper/Wrapper/Wrapper.csproj.in @@ -0,0 +1,57 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {D01B3597-E85E-42F4-940A-EF5AE712942F} + Exe + Properties + @ROOTNAMESPACE@ + @ASSEMBLYNAME@ + v4.0 + Client + 512 + + + x86 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + \ No newline at end of file -- cgit 1.4.1