Creating a VSTO Add in for multible applications - c#

Is it possible to create an VSTO add in for multible office applications?
Can I outsource the functions i want to have for every application and then create an Add-in for every application? If yes, is there a better way to achieve this?

I recommend making a solution with an add-in project for each Office application.
Then add a class library project to the solution and reference that from each of the add-on projects.
That way you can centralize code used in all add-ins.
If you need to interact with the active application or document, you can detect the type of the calling object and typecast it to the relevant application/document type.

Yes - you can just put your common functions into a shared DLL, just like any other application. Since each VSTO project targets a different application structure and potentially UI paradigm, I'd recommend having different VSTO projects in a single solution, and a shared assembly holding the common code.

VSTO doesn't support creating multi-host add-ins. You need to create separate projects for each host and use a class library for the shared code base.
Note, Add-in Express allows creating multi-host COM add-ins. So, a single add-in project can be run in multiple hosts. It comes from the IDTExtensibility2 interface. I don't know why VSTO creators didn't provide such feature to developers.

VSTO itself doesn't provide such an option. If you want to get single project for all application you can use shim add-in. That makes possible to run add-in in all applications from the same dll. The only issue -- your code need to handle what application started to call it to run separate logic or to call specific office API functions.

Related

Why can't I make a WinForms app register for COM interop?

I'm using Visual Studio 2015. I have successfully created a class library and selected:
Register form COM Interop
Make Assembly COM-visible
I've then managed to deploy this using a Setup Project to other users and it works great (although still don't understand why Intellisense doesn't work for it)
Now I'm trying to do the same for a WinForms application, but
Register form COM Interop
is not viable to apply, it's grayed out - should it be? And if so, why can't I register an application for COM Interop so I can manipulate it in other apps? (e.g. in Excel VBA)
The problem is that com registration normally makes only sense for assemblies (.dlls) and your WinForm application is normally a executable (.exe).
So I this case you should create a dll and move all the functions and classes that should be com visible into this assembly. Than make it Com visible and use it also from your executbale WinForms application.
To register a .NET assembly for COM Interop, the assembly has to be a class library, which is intended to be shared by applications.
A WinForms application, on the other hand, runs as a standalone program is not intended to be shared by other applications.
In this case, you can create a class library project, and creates a WinForms UserControl in the project, and expose the UserControl to other apps by making it COM visible.
Here is an old example, strangely it is hard to find more recent examples in my search.

How to creating an addin for multiple Office programs?

I want to develop addins for Office (Outlook,Word and Excel). The code will be almost the same. The difference is only for retrieve a document (mail for Outlook, document for Word,graphic/chart for Excel.
Should I develop 3 addins and therefore I will have 3 installations for my users. Or can I develop only 1 addin and add a condition somewhere?
Yes, that is possible. You possibly need 3 different AddIn classes, since every platform has it's own format and parameters and you might want to deviate some logic, though there is nothing to stop you integrating the three add-ins in one.
Another option is to make a class library that only uses the general Office assembly, and include that library into your other projects.
For the deployment: you can't use ClickOnce out of the box for that, since ClickOnce only supports a single Office program per installation. You can tweak the installation though, as explained on this article on MSDN: Deploying Multiple Office 2010 Projects in One Package.
VSTO doesn't supoport creating multi-host add-ins. The possible ways are:
Develop an add-in which implements IDTExtensibility2 interface without VSTO.
Use third-party tools such as Add-in Express that support creating multi-host add-ins.
Adding multiple AddIn classes to the extisting VSTO based add-ins is not a convinient way to go. At least, you will not be able to debug the code

Is it possible to create a portable VSTO app?

Is it possible to create a portable VSTO application ? (e.g without setup.exe, without admin rights, without clickonce, etc.)
Any vsto solution requires that:
The .net framework is installed on the target machine
The VSTO runtime is installed on the target machine
If you don't have those installed already the answer to your question is: No
If you define those as prerequisites then there are 2 kind of vsto solutions. It can be either a document based solution or an office add-in.
Document based solutions have the assemblies along side of the document and get automatically loaded with the excel file. There is no seperate setup required so you could call those 'portable' (depending on what your prereqs are).
Real office add-ins require registry keys to be created. I don't think there is any way you could get those running without some sort of setup/install procedure
For more information about document level solutions and how they are dealt with on runtime look here

Use c# windows application projects in a web application

How can I use some projects I created using Visual C# 2010 in a Web Application.
I want the projects all separated in the web application if possible
Thanks :)
Simply separate the parts of the application that are specific to Windows from the parts that are not specific. Similarly, separate the parts that are not web-specific from the rest. Put that parts not specific to any particular technology into one or more common class library projects.
Hint: these common class library projects should build with no references to System.Windows.Forms or to System.Web. Otherwise, they may not be general enough.
Are those projects class libraries? Most probably you can use them (except the windows application projects) as it is in the web application by adding references of them in the web application.
You can separate out the classes in those windows application in the class libraries and then you should be able to add the class libraries in the Web application which would use the class libraries.
If you are not looking to rewrite the application and would prefer a quick start on creating the web application then I'd investigate how useful the tool offerings are in this area.
A quick look on SharpToolbox reveals two candidates:
suite4.net
Visual Web GUI
I am not affiliated with any of these nor have I tried them and so cannot vouch for any of the claims they make about their products, but it might be worth trying them out.

C# COM Interop Library

I am currently porting a legacy VBA application to a .Net application. During this process the users of the existing VBA application need to have some features added. So instead of coding them in VBA & then later in C#, I’ve wrote the new functionality in C# and I want to expose this to the existing VBA application through COM, as well as also keeping it in the currently .Net application version.
The solution contain several projects, 1 project for the UI, 1 project for Business Logic, 1 project for the data access layer.
The new features are just a some new forms to modify data. So ideally they will click on a form command button in access which lunch these C# forms via COM interop.
How should I go about exposing this forms through COM Interop.
What I was hoping to do was just add another project, MyProject.COM, which will contain my Interface ICOMManager, for exposing methods to access to launch the required forms. My COMManager class will just instantiate the required forms in my .net application and show them.
This project MyProject.COM will have references to the UI layer & Business Logic Layers.
When I want to register this project using REGASM how will I include references to these other projects?
Thanks for any help or advice on how about doing this.
Ah ok so i see this is alot easier than i thought.
Once i looked at the reg file produced by regasm i could see that the tlb (Type Library) is just a pointer to where it can find the libraries to execute the .Net component.
So once i register the tlb and make sure its pointed to the install directory where the rest of the project files are located it works.

Categories