Context: In our application, there are two separate DLLs that are repositories of variables configured for different types of equipment. These DLLs have the same name and refer to our application. Now every time we want to test different types of hardware, we have to copy the corresponding dlls to the place where the application is running. I am looking for a workaround.
Links: I saw the following topics,
1) .csproj several hints ways to build
2) https://whathecode.wordpress.com/2012/10/07/conditional-project-or-library-reference-in-visual-studio/
Question: Can I declare a variable in a text file, say <hardware> type1 </hardware> , and import this text file into a csproj file and assign an appropriate link to my application?
Any help ..
The following is a test application that replicates our project. SignalPool1, SignalPool2 have the same class name and are repositories for two different hardware configurations available in two different places in our project. If we wanted to test hardware1, we would delete the current link and add a signal pool link, which is the same as for hardware2. Now, to avoid this manual work, I wanted to automate this process to declare a variable in XML and access the variable in the csproj file to decide who to contact at compile / runtime.
Currently, to avoid this problem, I have a separate exe that reads xml and decides to copy them to one shared folder. This exe will be called during the prebuild event in our project.
// Signal pool file 1
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace SignalPool { public abstract class SignalPool { public abstract string PreExec(); public abstract string PostExec(); public abstract string VnVExec(); public static string HWVar1 = "HWVar1"; public static string HWVar2 = "HWVar2"; public static string HWVar3 = "HWVar3"; public static string HWVar4 = "HWVar4"; }
}
// Signal Pool 2
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace SignalPool { public abstract class SignalPool { public abstract string PreExec(); public abstract string PostExec(); public abstract string VnVExec(); public static string HWVar1 = "HWVar5"; public static string HWVar2 = "HWVar6"; public static string HWVar3 = "HWVar7"; public static string HWVar4 = "HWVar8"; } }
// Access to pool variables
Main file
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml.Linq; namespace TestLibraries { class Program { static void Main(string[] args) { AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; Testhardware th = new Testhardware(); th.functionToValues(); } private static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) { if (args.Name.Contains("SignalPool"))
}
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace TestLibraries { class Testhardware : SignalPool.SignalPool { public override string PostExec() { return string.Empty; } public override string PreExec() { return string.Empty; } public override string VnVExec() { return string.Empty; } public string functionToValues() {