Deploying a C# COM dll using an installer - c#

I have made a C# class library, which uses other dll's made by others in the company, for COM interop. It is being used with MS Excel 2013 and works fine on my development machine.
To test it on other machines, i have copied the output (dll's and .tlb file) to my system 32 folder. I have then registered the dll's using regasm (using the /codebase argument). Finally, i added the reference to the .tlb in the Excel VBA editor. Allthough it is a little tedious with 6 dll's, the regasm works fine.
The next step is to distribute the Excel sheet to relevant users in the company, where most are located in different parts of the world in different deparments. This means i do not know what programs that are installed that are needed(for example .net 4.5). Also, since most people in the company know little about the command line, using the above procedure is not only a little tedious, but scares people. I therefore would like to make an installer.
Since i use VS2013, i have installed a plug in that allows me to make a setup file.
I have found this question, which is almost the same as mine, but i don't need the GAC part. How do i modify the procedure to my needs? - i have tried to follow the procedure given, but i get an error stating one of the dll's i use in my own, does not have a strong name and cannot be in the GAC. Build therefore fails. How do i rectify the above? - do i need to fix the dll or can i do this without the GAC-part?
How do i automate the installation process of my dll(s)? - The alternative right now is to roll out VS2013 to the users and make them run the project and register that way (Does VS express suffice?).
Thanks in advance - i started this project with little experience, so learning curve is a bit steep.

It's not clear to me exactly what you want to do, but that link does tell you how to register Dlls - just look at the properties of each Dll and set the register property. You can also add your tlb file to your setup, and mark that to be registered too. If that isn't what you're trying to do then edit the question.
p.s. Don't put tham in the system folder - pout them in your company's/app's common files folder.

Related

How to easily register an COM DLL (C#) on multiple computers?

A while a go I have created a COM DLL for my office application (Access). This application is being used on multiple computers.
The DLL is being changed regularly and because of that I have to re-register the DLL (on all the computers) every time it has been updated.
The re-registering is now being done by copying the DLL files from the server to the local machines and executing the RegAsm.exe with a power-shell script (this mechanism is build in the start-up BATCH script of the application, which compares version numbers.
However, I find this process very unwieldy since I need to manually update my version text file each time I update the DLL.
Is there perhaps an easier way to just run/update my DLL with a single click so that it updates the DLL on all the computers in my network? I have full control over the company's server/computers. Perhaps with the InstallShield or something? (I haven't done much with it so my knowledge about the InstallShield is very limited).
Thanks in advance!
Like you said, single click is what inspired devs at MS and the evolution of the OneClick Deployment Woohoo!!
What you need is a thorough go through of the article Simplifying Deployment and Solving DLL Hell with the .NET Framework
Of course it does mention of COM also, so happy reading!
Also this Choosing Between ClickOnce and Windows Installer

How to clean up my VS2015 release files

I'm new to c#, and i'm stunned by the amount of files that are generated by my release output.
I wrote a REALLY simple program that i want to distribute, no external assets or anything special.
but still, there are 10-15 files generated (.dlls, .pdbs, .configs, etc. etc.)
I did a little research yesterday and i got the impression that it is simply not possible to clean up this mess without a REALLY big hassle?
i tried Fody (didn't work at all) and Tidybin (or something like that?) (created a lib folder and put everything there, which was nice, but the program stopped working and threw errors about the missing files)
I'm looking for a way to generate a clean release version.
ideally with JUST my exe, with all the dlls and other stuff embedded, but everything i read about that was just way above my head and overly complicated (why isn't this super easy to do???)
if that's not possible, i'd be happy with moving everything except the .exe in a lib folder. but that didn't seem to work. how do i update the path inside my application, so that those files can still be found? like i said, that plugin seemed to do half the job, while leaving all links like they were.
(side note: why is there not ANY KIND of ducomentation for all of these plugins? i really don't have the SLIGHTEST idea what to do)
thanks
If you have a simple application, there shouldn't really be that much in the folder.
Actually, there should be:
1 exe, 1 pdb (only for debug build), 1 exe.config file for the application
1 exe, 1 pdb (only for debug build), 1 exe.config file for the Visual Studio Host Process
If there is the System.Net.Http library referenced, this could create a folder with many localizations. If you don't use it: Remove the reference.
Please note that you do not need to deploy all these files! If the application only references framework DLLs, all you need is the .exe and .exe.config file.
DLLs will not be embedded, but if they are framework libraries, they should not be added to the output folder unless you set the "Copy Local" property of the reference. And you don't need to deploy them along with your application, as obviously they are installed along with the .NET framework on the target system anyway.
If you reference any DLLs that do not belong to the .NET Framework, you normally deploy them along with your application. It's easiest to put them in the folder along with your application, but you can also put them in the global assembly cache on the target system.
There are solutions that package the executable, third party DLLs and stuff into an EXE wrapper that is unpacked every time you start the application, but I advise against this. The user won't expect this to happen, virus scanners may block this and builtin mechanisms like .NET settings may not work properly for those solutions.
The easiest way to distribute your code is using InstallShield Visual Studio edition. (That is available with your Visual Studio license)
Download and register, then add a new distribution project to your solution.
InstallShield Limited Edition for Visual Studio
A wizard will help you by selecting the main distribution files. And it is a useful tool distributing new releases of your application.
As a second option I use is ClickOnce (Microsoft), but for specific internal applications.
ClickOnce Deployement

How to make a software portable with C#?

I'm coding a simple application that I need to be portable (the user can just run it by clicking on the .exe without having to run a installer).
All the other questions on this subject that I found on StackOverflow wants to make .NET Framework "bundable" with the software, but I don't need that.
A workaround that I found is going to /bin/Debug on the project folder and use the .exe there, but that seems "wrong". Is there another way to make a software written in C# portable?
Thanks!
EDIT: Okay, I'm really dumb and I asked all the wrong questions. However, your answers pointed me to the right direction. I wanted to know how to generate the .exe to send to my friends. What I had to do is change this to "Release" and press F6. I added this so if someone with the same "doubts" that I had can find the answer easly. Thanks!
Going to bin/Debug and using the DLL there is wrong.
Instead, build and copy the one from bin/Release.
If there's anything else inside the folder, though (except *.pdb), then beware. Your application might need those additional files. For example, the app.config.
All .NET applications are "portable" as long as the machine you are running it on has the version of .NET you are targeting (or a compatible version). The key here is to make sure that your application does not depend on things that an installer would take care of for you to make your application work. Examples include: registered DLLs (like Interop assemblies), registry keys, or components that must be found in certain locations (such as having something stored in user's AppData folder).
As long as the machine you want to run it on has .NET framework, you can make any .NET application portable. If the app you're making has no dependencies other than .NET then it's fully portable already. Even if it does have dependencies just include those with the executable.
To expand on Zerkms's comment:
Every software is portable by default. Installers are a way of telling to program to search for resources in a certain place, meaning that if the place isn't there, eg: C:\Windows then the program won't be able to run.
So as long as you have the application have the resources already within the exe or a root folder search (so where the program is, rather then where it should be) then you'll be fine.
If you're using default controls, it should be fine as long as your software's running framework version is installed on the computer. If you're using 3rd party controls, you can emded the dll's into the .exe upon compiling. Do note that the more dll's you embed, the bigger the .exe file will be.

Deploying .NET COM dlls, issues when used on another computer

I'm kinda new to C# programming, and I'd like your help on something.
A quick review of what I have to do first.
I have to create : - A DLL that produces several .h5 files (HDF5 format) and one xml file
- A WPF viewer for the graphs that are written in these HDF5 files.
The problem is mainly that they are going to be used in a software called Panorama E², which basically manages DLLs, in a very restrictive way. For instance, it does not allow .NET framework 4 (Which makes me use the 3.5 version of the framework).
More info on Panorama : http://uk.codra.net/panorama/panorama-e2-information-system
I'm using HDF5DotNet.dll, that I compiled in x64 for .NET 3.5, and DynamicDataDisplay for my WPF application.
All my DLLs are going to be used by another computer, where Panorama is installed, and where Visual Studio isn't (only the 3.5 .NET framework and some required tools are).
What's the problem ?
Well, first, my WPF application isn't really one, Panorama doesn't seem to support WPF, only Windows Forms, and only as DLLs. Which means I created a WPF UserControl, that I embed in a Windows Form DLL.
I basically have 2 DLLs, one which is the WPF control, and one that uses this control in a winform. This is the last one that I have to integrate in Panorama. On my computer, the one I'm coding with, Panorama recognizes correctly the DLL and there's no problem.
But when I try to give these DLLs to my colleague, with his Panorama without Visual Studio installed, it doesn't work. After some tests, I noticed that it only works if the project (the DLLs) have been compiled on the same computer.
The same problem goes for the other DLL, the one that creates files. As I said, it uses HDF5DotNet.dll, but it seems it doesn't create it correctly. I guess it's the same problem, the DLL is not recognized.
What I tried.
I thought that maybe the DLLs weren't exported correctly. Maybe the referenced DLLs or assemblies aren't given, which are when you compile on the same computer. They're COM DLLs, because they're used in Panorama, and I can't manage to export them correctly.
I tried creating setup projects, so that they would be installed with their dependencies, but I couldn't find a way. Only the DLLs are installed. I tried looking at my DLLs with DependancyWalker, and there are some where dependancies are missing. Even if I try adding them manually, nothing changes.
I also know that regsvr32 doesn't work with .NET DLLs, because there is no entry point. That's why i thought about GAC, but I can't manage to register them (with strong name and everything), because I can't generate them directly.
So yeah, sorry for the long post, I tried to explain my train of thoughts and what I actually tried to do, but I can't find a way to give my projects to my colleague so that he can use them on his computer.
"Self Registration" ( be it RegSvr32, RegAsm or other ) is not a Windows Installer Best Practice. This injects out of process dependencies into the installation critical path that the installer is not aware of, that can fail and can't be rolled back or uninstalled.
The better approach is to use RegAsm /regfile to harvest the COM metadata for the ComVisible assembly and then author those registry values into your MSI's Registry table. This way Windows Installer merely has to copy the DLL and apply the registry values to register your component. It's far less likely to break and can be uninstalled and repaired cleanly.
How you do this exactly depends on the tool you are using to author your MSI. In WiX you'd use Heat to harvest this information. In InstallShield you'd set the .NET ComVisible attribute to True.
The end result is the same.
Hi try the following in command prompt instead of regsvr32 try the following :
"RegAsm.exe acxMaterialClassificationMerge.dll /codebase " where acxMaterialClassificationMerge.dll is your dll. You should do this on every pc thats going to use the dll. RegAsm is located in C:\Windows\Microsoft.NET\Framework\v2.0.50727
1: install first dotnet framework version 2 or newer on the computer
2: in command prompt :"RegAsm.exe acxMaterialClassificationMerge.dll /codebase " where acxMaterialClassificationMerge.dll is your dll. You should do this on every pc thats going to use the dll. RegAsm is located in C:\Windows\Microsoft.NET\Framework\v2.0.50727.

Package library in the final exec file

I'm developping with visual studio 2008 and I use several project library used by several application project. There is also external dependency.
When I distribute the program, all the DLL appears in the program files folder which would make very easy to hack my program.
Is is possible to bundle all the project library into one exec file?
Well, if you sign your assemblies it will be near impossible to "hack" your program. Read about signing assemblies here. There is a program called ILMerge that you can use to bundle your assemblies into one, but I don't see the need really... at least not to avoid that someone hacks your codez :-)
Yes, there is. There is a tool called ILMerge. For more info see http://blogs.msdn.com/brad_mccabe/archive/2005/08/19/453703.aspx

Categories

Resources