VSTO

From Blue-IT.org Wiki

Revision as of 13:21, 5 June 2017 by Apos (talk | contribs) (Reset VS settings)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Why

So, why VSTO here in an OpenSource themed wiki?

Since 2015 .NET and C# is opensource (really):

And:

  • You can get the Visual Studio Comunity Edition for free (really free also for commercial use, if you are not working for a > 250 men company)
  • Word an Excel are running fine with wine (see #MSOffice_2010_and_Wine) - Outlook not tested yet,

I am really (!) impressed about the statement from Microsoft for doing this. The world really changes:

[...]
As a .NET developer you were able to build & run code on more than just Windows for a while now, including Linux, MacOS, iOs and Android.
The challenge is that the Windows implementation has one code base while Mono has a completely separate code base. The Mono community was essentially forced to re-implement .NET because no open source implementation was available. Sure, the source code was available since Rotor but we didn’t use an OSI approved open source license, which made Rotor a non-starter. Customers have reported various mismatches, which are hard to fix because neither side can look at the code of the other side. This also results in a lot of duplicated work in areas that aren’t actually platform specific. A recent example is immutable collections.
The best way to build a cross-platform stack is to build a single stack, in a collaborative manner. And the best way to do exactly that is by open sourcing it.
[...]
Source: MSDN blogpost from November 2014

In most cases Word, Excel and Powerpoint are the most often used programs in business for daily communication. It is like it is. Beeing able - now - without any restrictions, to program MS-Office legally also for commercial usage. The only "drawback" is: you HAVE TO register the application and therefore create a microsoft account to be able to work with it.

And hey: if I can play in both worlds -using MS in virtualbox ;-) and having my data save on linux (sorry MS), why not!

Now lets make ...

Troubleshooting

Clickonce

Clear the cache

Pre- and post build

Uninstall vsto plugin via command line

If you are developing you Addins with Visual Studio and you like to test your AddIn on the same machine, this won't work. VS complains when starting the AddIn, that it is already installed ;-(

Also this is Ok, it is very annoying when developing and testing on a single machine. The easiest way is to uninstall the plugin, before you test your applications:

You get the uninstall string if you search your registry (regedit.exe) in:

"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall" 

which you can easyly do in cmd with:

REG QUERY HKCU /v "*YOUR_PLUGIN_NAME.vsto"  /s

or

REG QUERY HKCU /v "*.vsto"  /s

The location of the VSTOInstaller.exe you can search for with

dir /s /b VSTOInstaller.exe

Put this into your Project directory as a .bat file and edit $(ProjectDir)"UninstallPlugin.bat" like this:

"c:\Program Files\Common Files\Microsoft Shared\VSTO\10.0\VSTOInstaller.exe" /Uninstall "file:///C:/Test/ExcelTemplateTest.vsto"
 CMD /C EXIT /B 0

The CMD sets the errorlevel to 0, so the batch file will alway end successfull ...

You should then put this in the post build settings:

 $(ProjectDir)"UninstallPlugin.bat"

You could also program this with C#

Cannot create Excel projects

Most likely: You have an PERSONAL.xslb File in the XSLT start folder (see above posts).

Certificate Issues

Creating self made codesigning certificates

Be aware: this needs a Windows 2008 Server with a fully configured Certificaton Authority. You can download a Windows Server 2008 Eval, use the 180 day evaluation license and install it within a virtual machine environment - no need to do updates other stuff. If you are not familiar with such a routine then this could take you a whole workday! If this is not possible you have to buy a valid certificate from e. g. verisign.

Create your own PKF certificate

  • PFX-Format (Personal Information Exchange), also known as PKCS #12

From here to there I look over the boarder and use Visual Studio 2013 to develop applications in C#. E. g. for Office VSTO Addins. I was confronted with the problem, that I could not start my own developed applications. Office merely refused to open and run the AddIn. To make a (very) long story short, this article saved my life:

Who is affected by the same problem can also follow this guide and use a valid certificate - which you have to buy:

I don't comment this behaviour of Windows in this case. Certainly it is good to have a strong certificate chain in a company. But hey microsoft, in some cases one simple just want to develop and share software in trusted environments without such a huge impact ;-) I am fulfilled with the believe, that MS sometimes thinks not only big, but practical.

When you successfully created your code signing certificate (.pfk) then put it on a secure place.

Create your public and private keys for signing

You have now to extract the public key of the certificate:

Create the public key (.snk file) for signing your assemblies with sn.exe. You can find the path to sn.exe on your lokal drive with

cd c:\
dir /b /s sn.exe

This could then look like this:

"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\sn.exe" -p keypair.pfx key.snk

Now put the two files on an usb stick and go to the machine where you like to publish your software.

Install the certificate as a trusted publisher an mark it as non exportable!

Now you can sign your assemblies in Visual Studio with the key.snk.

Signtool

Thanks this article, I could solve a lot of problems.

You basically can find the path to signtool.exe searching within the MS Visual Studio installation directory:

cd C:\Program Files (x86)
dir /s /b signtool.exe

which leads to:

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Bin\signtool.exe
C:\Program Files (x86)\Windows Kits\8.0\bin\x64\signtool.exe
C:\Program Files (x86)\Windows Kits\8.0\bin\x86\signtool.exe
C:\Program Files (x86)\Windows Kits\8.1\bin\arm\signtool.exe
C:\Program Files (x86)\Windows Kits\8.1\bin\x64\signtool.exe
C:\Program Files (x86)\Windows Kits\8.1\bin\x86\signtool.exe


set MySignTool="C:\Program Files (x86)\Windows Kits\8.1\bin\x86\signtool.exe"
set PathToKeyFilePfx= ...
set ProjectDir= ...
set TargetFileName= PATH_TO_DLL
"%MySignTool" sign /f %PathToKeyFilePfx%" /p MY_PASSWORD /v "%ProjectDir%\obj\Debug\%TargetFileName%"

Reset VS settings

[Update 5/2017: I also encountered this problem after update my Windows 7 machines to Windows 10. After that either my VS 2013 nor the newly installed VS 2017 did work.]

  • As admin: startmenu -> VS2013 -> VS-Tools -> Developer Command Prompt VS2103 (not native!)
devenv /resetuserdata
devenv /setup
  • As user: Open Developer Command Prompt VS2103 (not native!)
devenv /resetuserdata 
devenv /setup 
devenv /resetsettings