how to use same name dll in one application - c#

To build an Autocad application I use C# 4.0.
My application has two module one for 2005 and another for 2010 autocad. it uses special dll's of autocad ,but face some difficulty of finishing it up .All should be universal for 2005 and 2010 autocad since dll's has the same name it was impossible for the app to differ autocad versions.it create problem for autocad interop dll's in reference.help me to use different dll for different module.
Application has two modules(2005,2010)
Special dll
2005 and 2010 dll has same name.
Application fail to distinguish dll
Help me to use different same name dll in one application.
Note:In individual project they work perfectly.
need help to use same name dll in one application .
If have any query please ask ,Thanks in advanced.

I've a similar application, it works for autocad from 2006 to 2013 (both x86 and x64) and for bricscad v12-v13.
To solve it I did a visual studio project for each architecture, each of those projects refers different .dll depending on autocad version. In particular each of those projects refers AcDbMgd.dll, AcMgd.dll, Autodesk.AutoCAD.Interop and Autodesk.AutoCAD.Interop.Common, those dll are specific for each autocad architecture.
You have to pay attention that all of the referenced dll are in copy local FALSE!
In my case all the projects are compiled in different folders but it's not obligatory if you assign a different assembly name for each project.
Thanks to the fact that AutoCAD API are the same from 2006 to 2012 (2013 has some differences), the source code is separated from those projects, each project include it as a linked source file (go to the project in the solution explorer -> right click -> add existing item -> select the source file and press "add as link"). In this way you have the same source code for all the projects but they are compiled including different autocad dlls.
In my case there were also some troubles because BricsCAD has sometimes different API with respect to AutoCAD. To solve this few cases I've set a conditional compilation symbol and used it like so:
#if BricsCad
CADAPI.ApplicationServices.Application.SystemVariableChanged += new CADAPI.ApplicationServices.SystemVariableChangedEventHandler(Application_SystemVariableChanged);
#else
CADDB.LayoutManager.Current.LayoutSwitched += new CADDB.LayoutEventHandler(Current_LayoutSwitched);
#endif
Tell me if you need further information. BTW I think your main problem is the copy local = true for autocad Dlls.

Related

The best way to reference different version of DLLs and generate Dll with different version

I am working on an AutoCAD add-in project, which will ref AutoCAD dll. One of the challenges is that we have different CAD versions on our laptops. So I have different solutions named in different versions so each solution can reference its related DLLs during the development.
For example:
Laptop 1 with AutoCAD 2018
Laptop 2 with AutoCAD 2019
Build two solutions named AutoCAD Plug-in 2018 and AutoCAD Plug-in 2019. Both of them are refering to different versions of AutoCAD dll. However, the code is pretty much the same way.
It doesn't bother me to refer to different DLLs because the DLL would not copy to the solution folder(AutoCAD requires that). It would use whatever version is in the AutoCAD folder. For example, I have AutoCAD 2018 installed at C:\Program. When AutoCAD loads a plug-in dll, the plug-in dll will use any related dll that is the same in the AutoCAD folder.
I desire to have one solution, that refers to different versions of dlls, and when you build the solution, you will compile the solution into different plug-ins with different version names.
So for example, Visual Studio would generate two dlls:
AutoCAD plug-in 2018
AutoCAD plug-in 2019
So that I don't need to maintain the same code in different solutions.
Would be possible to do this?
You are having same situation with me. What I did was using the Post Build/Pre Build Events to copy the DLL version that I need to the output folders
https://learn.microsoft.com/en-us/visualstudio/ide/reference/pre-build-event-post-build-event-command-line-dialog-box?view=vs-2022
Example:
echo $(ConfigurationName)
if "$(ConfigurationName)"=="Release" (copy $(SolutionDir)\dlls\file1.dll $(SolutionDir)bin\x86\Release\file1.dll)
if "$(ConfigurationName)"=="Any" (copy $(SolutionDir)\dlls\file2.dll $(SolutionDir)bin\x86\Release\file1.dll)
In addition, you can create a custom build batch file (.bat). I haven't tried this one but I see other projects using it to create builds for Fortify code-scan request.
https://learn.microsoft.com/en-us/visualstudio/ide/specifying-custom-build-events-in-visual-studio?view=vs-2022

C#.net DLL COM wrapper and installation

I'm making a load of code bits that will eventually be used in another C# program long term, but I may want to use it in various other apps, and I need to use it easily now as it gradually develops. So I've written a few C#.net DLLs in Visual Studio Express 2017. Two of which reference a 3rd-party DLL (one of which was installed by other software, one of which I just pointed at in Visual Studio), and one of my DLLs references my other 2 DLLs. I've ticked the boxes to COM register my ones and I'm now happily using them from Excel/VBA.
But how do I install it on another Win10 machine in simple steps though, so I can use the same spreadsheets and automation on those computers? (preferably with some explanation of what the steps are actually doing?) I haven't had any luck with the other options I've googled, maybe they're not "idiot proof" enough for me, or my DLLs have dependencies on other DLLs, or I'm getting them from the wrong place.
I assume these are 64-bit DLLs (they're complied for 'Any CPU') so I
want to copy them into the 64-bit place (syswow64)? Or should they go
in system32 as well?
I guess I get them from my 'release', not 'debug' folders?
I also have .pdb and .tlb as well as .dll. Do I need these? Maybe they're the missing piece of the jigsaw?
What's the difference between regsvr and regasm and what should I be using? (Or both).
Also is there a simple way to make a DLL copying and COM registering installer app? And if yes, does that still apply if it's VS Express
2017?
Thanks for the help!

How can we debug DLL (bulit with native C/C++) source with WPF/C# executable?

Assume we have WPF/C# Project called A (A.exe).
It's using DLL built with C++/CLI ;which is project B (B.Dll)
And project B depends upon project D, which also a DLL built with native C/C++( D.Dll).
Simply A.exe -> uses B.Dll -> uses D.Dll
Here is my native environment is - Windows 10 ,Visual Studio 2017 ,Visual C/C++ 141 .NET 4.6.1/4.7.1.
Note that C++/CLI (CLR) project is a wrapper for native C/C++ functions, which means it's being used as a mediator between native C/C++ and WPF/C# and also all projects built under one Visual Studio Solution, therefore respective project was added as reference to other project.
Startup program is A.exe as mentioned above which is WPF/C# project.
Problem is I cannot debug C/C++ while running the project through Visual Studio 2017.
Following things I have already tried:
Set up working directory to built path(All DLLs,PDBs and exe there) in all projects.
Set up Symbol path in Visual Studio 2017.
Set Debugger Type to Mixed within respective projects (under Project properties -> Debugging).
Set(checked) Use Managed Compatibility Mode(under Visual Studio Debug->Options->Debugging).
Set(checked) Enable native code debugging option in WPF project(Project properties->Debug->Debugger engines).
I couldn't break the execution at least on single breakpoint marked on C++ code.
Please help to solve this issue.
Thank you.
Target output file name for each project should be differ,
else firstly loaded module's symbols will be visible to debugger.
In my case A and D had similar target out file names(not implies project names). Since A is the target executable,its pdb overwrites Projects D's pdb.
Nevertheless,it's wise to configure things I mentioned in my questions.

Moving Visual Studio Installshield project from Windows XP to Windows 7

I have a Visual Studio project that compiles correctly on a Windows XP computer. I have copied the entire project to another PC running Windows 7 and it generates compilation errors.
The application uses .NET Framework 4.0 and Visual C++ redistributables, installed locally. It couldn't find these.
I realised that it was looking for the Microsoft.net in
c:\Program Files\Installshield\2012SpringLE\SetupPrerequisites
By right-clicking on the Microsoft .NET Framework 4.0 entry in the Redistributables (Installshield) window I was able to search for the merge module and corrected it to
c:\Program Files (x86)\Installshield\2012SpringLE\SetupPrerequisites
That overcame the .NET Framework 4.0 problem
However, I can't find the merge modules for the Visual C++ entry in the Redistributables (Installshield) window. Can anyone tell me where they are?
This is one of the big reasons that I suggest not only building on your machine. A proper CI build system should run on any number of build servers.
For merge modules you need to look at your merge module search path found in Tools | Options | Merge Modules Search those directories for your merge modules and copy them over to your new server.
For pretty much everything else you need to be aware of the Path Variables view (abstraction) what they are set to and how they are being used by various tables such as Binary, File, Icon and so on.
Personally I'm very meticulous when it comes to managing this and making sure everything is checked into source control properly. InstallShield will allow you to do very bad things in this area and not warn you what you are doing is problematic.

Skip DLL files in .NET setup project

everyone, I am having a question or problem when building a setup project for an add-in (both are developed in c#). The add-in is used for a big software, and it needs a DLL from the software. If I just build the add-in and use it, it is fine. But if I install it using a setup project, the DLL provided by the software should also be copied to make the add-in work. But since if the client who uses the software, has already the DLL (coming along with the software), so I wanted to skip this DLL, so exclude it from the setup. But if I do so, I will get error 1001 when installing the add-in, saying at least one type from the assembly (the add-in) cannot be loaded. If I include everything (all the dependencies), it works.
So does anyone have idea about this? How can I skip the already available DLL that comes along with the software?
you can use web deployment project to build your application instead of the default publish in visual studio and before building it right click on the WDP and select Open Project File:
inside the .wdproj file search for item group <ItemGroup></ItemGroup> tag and add the following
<ExcludeFromBuild Include=”$(SourceWebPhysicalPath)\FolderName\**\*.*” />

Categories