Appcast library

For our Slido integration with Microsoft PowerPoint on macOS we used the Sparkle library to do automatic updates of our main Slido application. Our code also runs inside PowerPoint and we need to do checks if new versions are available. Unfortunately we cannot use the full Sparkle framework because of technical limitations for add-ins running in Office apps on macOS.

Sparkle framework uses the Appcast format for updates. This is an RSS document with additional Sparkle data to facilitate minimum system requirements, critical updates and delta updates information. Sparkle is written in ObjectiveC language and it does not provide a library target just for the Appcast implementation in their Swift package definition.

Our app and addin code is written mostly in Swift and we would prefer to integrate a Swift code for parsing Appcast documents. The authors of Sparkle project would like to keep it Objective C only for compatibility with very old OS X versions. Otherwise we would provide class-by-class migration from Objective C to Swift pull requests back to the Sparkle project.

Individual library

I have decided to write a new Appcast parsing library in pure Swift. The original Appcast code is very stable so the new library can be kept compatible with Sparkle code.

The RSS format and Sparkle extensions are quite simple and the original Appcast code in Objective C is small so rewriting it in Swift was easy.

The first preview release will parse the Appcast document and provide simple data in the AppcastItem structure. This proves we can create modern library which works in our Slido integration with Microsoft PowerPoint.

Integration tests

Sparkle framework has a large integration tests suite for parsing Appcast files. Their integration tests are in a single large test suite. To get better picture about features implemented in the new Appcast library I had to refactor large tests into small test function focused to just do single and focused checks.

I have followed the Definition of a Unit Test from Roy Osherove when refactoring tests. The The Art of Unit Testing book is a great guide for writing tests, refactoring legacy code and ensuring the trustworthiness of tests.

Refactoring of tests is available in the slidoapp/Appcast@test/appcast branch.

What's next?

The new library needs to implement the same logic for resolving the best available update in the Appcast file to match the behavior of Sparkle framework. As we don't need the delta updates (our DMG is just 8MB large) we will skip implementing information about delta updates in first releases.

NetOffice.Core v1.7.4.11: System.NullReferenceException

TLDR: To fix this issue, migrate your project to use our official packages which are named NetOfficeFw and are published by netoffice account.

> This bug does not exists in the NetOfficeFw.Core v1.7.4.11 package and it is not a bug in the official NetOffice source code.

Symptoms

When you use packages like NetOffice.Word, NetOffice.Excel, NetOffice.Oulook and others published by netofficedotnet on NuGet.org, you will encounter error System.NullRe­ferenceExcepti­on: ‚Object reference not set to an instance of an object.‘ when using NetOffice code. (Note the missing Fw in package names.)

In Output window you will see an exception is thrown when calling NetOffice code:

Exception thrown: 'System.NullReferenceException' in NetOffice.dll
Object reference not set to an instance of an object.

This exception is thrown by method NetOffice.Core.TryLoadAssembly(string fileName):

NetOffice.dll!NetOffice.Core.TryLoadAssembly(string fileName)
NetOffice.dll!NetOffice.Core.Initialize(NetOffice.CacheOptions cacheOptions)
NetOffice.dll!NetOffice.Core.CreateKnownObjectFromComProxy(NetOffice.COMObject caller, object comProxy, System.Type wrapperClassType)
ExcelApi.dll!NetOffice.ExcelApi._Application.Workbooks.get()

Cause

There are fake packages on NuGet published by Erika LeBlanc (GitHub account erikaleblanc88, NuGet account netofficedotnet). These fake NetOffice assemblies does not work properly. That account is doing a lot of shady stuff in the https://github.com/netoffice organization (rewriting code history, deleting comments and issues, to name a few).

Because the published packages contain fake assemblies, you will encounter this exception by using NetOffice.Core v1.7.4.11.

Read more in our NetOffice Migration Guide

Official Releases

You will find official releases wither on NetOffice on OSDN or at GitHub

Run InspectCode in your GitHub Actions

When you build .NET projects and you are using GitHub Actions to build your code, you cna now run code inspections with InspectCode without hassle.

InspectCode is a tool from the free ReSharper Command Line Tools (CTL). It can do solution-wide analysis of .NET code.

To use it in GitHub Actions, just add this code to your workflow file:

steps:
- uses: goit/setup-resharper@v1
with:
version: '2020.1'
- run: InspectCode SolutionFile.sln

The goit/setup-resharper action will download the ReSharper CTL and cache it locally (using the actions/tool-cache). ReSharper tools will be added to the %PATH% variable so you can use them anywhere in your build scripts.

As ReSharper CTL tools are supported on Windows, Linux and macOS (versions 2019.3 and newer) you can use the also for non-Windows builds. The setup action supports any ReSharper CTL newer then 2018.2.

Go to GitHub Marketplace to use this action, or checkout the source code at goit/setup-resharper

NetOffice – develop solutions for Microsoft Office apps easily

NetOffice is a great .NET library which can be used to develop solutions for Microsoft Office apps. The library supports automation and extension scenarios.

Automation

Use the NetOffice library to automate Microsoft Office apps. You can generate Office documents, transform and print them.

You can automate repetitive actions like adding signatures and pictures to Word documents, or generating Excel spreadsheets which must use the same Excel formulas you would manually create.

Extensions

NetOffice has first class support for Microsoft Office Add-ins – rich extensions which can modify user interface inside Office application and allow users to access complex features.

NetOffice add-ins are written in managed .NET code so the development is easy, productive and you can debug them from Visual Studio.

NetOffice documentation is available at https://netoffice.io/ and you can join the development community on GitHub at https://github.com/NetOfficeFw

.gitattributes templates

gitattributes.io is a service for generating .gitattribute files from templates. The service is inspired by gitignore.io where you can quickly bootstrap your .gitignore files.

Choose templates on web interface, or use the very simple API to list template names and generate new .gitattribute file content.

To generate .gitattributes file for you web project, just call:

https://gitattributes.io/api/web

Working on a C++ project in Visual Studio? Separate multiple template names with a comma:

https://gitattributes.io/api/c++,visualstudio

The list of all template names is available at api/list endpoint:

https://gitattributes.io/api/list

This service was made possible by the project from alexkaratarakis who created the original alexkaratarakis/gi­tattributes repository with .gitattributes templates. You can contribute to gitattributes.io project at github.com/gi­tattributes

Digital signatures for binaries in open source projects

Digital signatures provides proof that the file was authored by a trusted entity. They allow to verify the integrity of applications distributed in binary form. On Windows, software authors use Authenticode to sign the application and its setup package so Windows can verify who made the application and it allows IT adminstrators to create policies for running only trusted applications.

Open source applications (for Windows) usually are not signed because the Authenticode certificates are expensive and the learning curve for signing is quite steap.

I chose Certum to get certificate for my open source applications. The Authenticode certificate from Certum costs only around 28 EUR. If you does not have any compatible smart card which would store the certificate private key, you can buy one from Certum, but this makes the certificate a bit expensive (for hobby purposes) – the smart card costs 80 EUR and shipping is 30 EUR.

Ordering the certificate from Certum was a bit complicated and painful process as their website likes to switch to Polish language out of a sudden. Authenticode certificates must be issued to natural persons (or legal entities) so the process is not automated (as with Let's Encrypt domain validation) and you must provide them your ID card and some utility bills or bank statement to verify you identity.

Out of the box, you can use the certificate to sign applications (EXE, DLL and MSI files) with signtool.exe using the default SHA1 algorithms. You must run the proCertum CardManager application so signtool.exe can communicate with the smart card when signing binaries. Each time you are signing a file, CardManager will ask for a PIN to the certificate.

Sign application

To sign application named VCardSplitter.exe using certificate named Open Source Developer, Jozef Izso, use this command:

signtool.exe sign /n "Open Source Developer, Jozef Izso" VCardSplitter.exe

This will just sign the file. You must also add the timestamp to the signature so the signature will remain valid even after certificate expires.

signtool.exe sign /n "Open Source Developer, Jozef Izso" /fd sha1 /t http://timestamp.verisign.com/scripts/timstamp.dll VCardSplitter.exe

Signing using SHA256 algorithm

Microsoft requires new applications to be signed using SHA256 algorithm. When you configure signtool.exe to use SHA256, you will receive error when signing files. To resolve this issue, open proCertum CardManager, click Options, enable EV Code Signing – replace CSP with minidriver library and click Ok. This will reconfigure the system and the SHA256 algorithms will work correctly. Note: the certificate for open source developers from Certum is not the EV (Extended Validation) certificate. It just hapens the CSP method of signing with smart card is only compatible with the old SHA1 signatures.

With minidriver mode enable, you can sign your binaries like this:

signtool.exe sign /n "Open Source Developer, Jozef Izso" /fd sha256 /tr http://timestamp.comodoca.com VCardSplitter.exe

Signing NuGet packages

NuGet 4.6 enables signing of nuget packages. It requires the signature to be SHA256 so make sure you enabled the minidriver mode. Signing is similar to the signtool.exe process:

nuget.exe sign library.1.0.0.nupkg -CertificateSubjectName "Open Source Developer, Jozef Izso" -Timestamper http://timestamp.comodoca.com

Switching the CSP and minidrive mode in proCertum CardManager

The proCertum CardManager uses special app called cryptoCardRegister.exe to switch between the CSP and minidriver modes of signing. This can be change from the proCertum CardManager user interface:

  1. Open proCertum CardManager application
  2. Click Options button
  3. Enable or disable the EV Code Signing – replace CSP with minidriver library checkbox
  4. Click Ok

If you have troubles with using the UI to change the mode, you can execute cryptoCardRegister.exe directly from command prompt.

To enable CSP mode manually, use administrative prompt to run:

"C:\Program Files (x86)\Certum\proCertum CardManager\cryptoCardRegister.exe" csp

To enable minidriver mode manually, use administrative prompt to run:

"C:\Program Files (x86)\Certum\proCertum CardManager\cryptoCardRegister.exe" md

Conclusion

Digital signatures can ensure your Windows binaries can be verified to come from trusted source. As open source developer, you must invest about 100–150 EUR to get the first certificate. The certificate from Certum will be issued to you as a natural person and it will be named Open Source Developer, <Your Name>. After correctly changing the CardManager configuration, you can sign you Windows applications, libraries, installation packages and also nuget packages. Signing cannot be automated as you must enter the PIN each time you sign a file. This prohibits scenarios like automatic signing of build output on continous integrations services like AppVeyor.

I hope code signing certificates will get more available to open source developers and projects and cloud services could be used to automate signing as part of the build process. This would make the ecosystem of open source libraries for Windows more trusted.

Číslovanie strán v Microsoft Word

Jedným z najúspešnejších článkov môjho blogu je Číslovanie strán od určitej strany v MS Word, ktorý má najvyššiu návštevnosť hlavne v apríli, keď najviac študentov píše diplomové práce.

Tento článok však dlhú dobu nemal dostupné obrázky znázorňujúce kontrétne kroky v Microsoft Word 2003 pre nastavenie číslovania strán, pretože som pri aktualizácii WordPress systému zabudol presunúť niektoré obrázky zo starého priečinku do nového.

Dnes je už chyba opravená a študenti majú dostupný celý manuál, ktorý im pomôže v očíslovaní ich diplomoviek a iných záverečných prác. Teraz už chýba iba príručka ako nastaviť číslovanie v nových verziách Word-u, ktoré majú ribbon rozhranie.

Google Tag Manager

Google Tag Manager je zaujímavý nástroj pre spravovanie rôznych analytických a marketingových JavaScriptových kódov. Priamo podporuje Google Analytics a Adwords a vďaka Custom HTML Tags si môžete zadefinovať HTML a JavaScript kód pre iné meracie systémy.

Do stránky vkladáte kód pre Google Tag Manager, ktorý následne stiahne ďalšie meracie kódy, napr. Google Analytics. Google Tag Manager je tak určený pre web stránky, ktoré potrebujú flexibilne meniť meriace kódy na stránkach, ale zmena stránky a jej aktualizácia by si vo firme vyžadovala zdĺhavú birokraciu. Pravidlá v Google Tag Manageri vám umožnia vložiť iné meracie kódy podľa URL adresy web stránky.

Microsoft Virtual Academy Logo

Kurzy o virtualizácii na Microsoft Virtual Academy zdarma

Microsoft Virtual Academy (MVA) je portál s kurzami, kde sa môžete naučiť používať technológie Microsoft-u súvisiace s cloud-om. Kurzy sú dostupné zdarma a od decembra tu nájdete aj kruzy v českom jazyku zamerané na virtualizačné riešenia Hyper-V, System Center a privátny cloud. Kurzy sú dostupné pre používateľov z Čiech a Slovenska.

Via: České kurzy zdarma na MVA!

Automatizované buildovanie softvéru

V bývalej práci som sa naučil, že je výborné mať na softvérovom projekte bug tracker (používali sme, a ešte stále používam(e) FogBugz), verziovanie zdrojového kódu (Subversion alebo Mercurial Hg) a automatické buildy (CuiseControl­.NET). Mám skúsenosť s tým, že firmy používajú repozitár so zdrojovým kódom a bug tracker systém, ale málokedy majú nainštalovaný a funkčný systém, ktorý zautomatizuje kompiláciu a nasadenie aplikácie. Súvisí to aj s tým, že buildovacie systémy sa komplikovane nastavujú a treba sa o ne starať viacej, ako Subversion repozitár či bug tracker.

Pri mojich prvých automatických buildoch, ktoré som mal možnosť konfigurovať, som používal NAnt. Kolega bol expert na Ant, NAnt a ostatné veci okolo projektového manažmentu a pred niekoľkým rokmi bol NAnt jediný spôsob, ako jednoducho napísať skript, ktorý skompiluje zdrojový kód, spustí unit testy, vytvorí balíček aplikácie (ZIP so súbormi webovej aplikácie, alebo spustí nástroje pre vytvorenie inštalačného balíčku) a zarchivuje výsledný build. Toto sú základné veci, ktoré sa zídu snáď na každom projekte a v dobe .NET 1.0 a 1.1 bolo v NAnt-e potrebné skriptovať kompiláciu na úrovni jednotlivých zdrojový súborov a manuálneho volania. V prípade C# projektu to znamenalo zobrať všetky .cs súbory a použiť csc.exe kompilátor, nájsť výslednú DLL/EXE assembly a niečo s ňou spraviť. Nevýhoda tohto postupu bola, že treba všetko ručne písať a Visual Studio robilo vlastnú kompiláciu podľa projektového súboru .csproj a NAnt robil druhú podľa vlastných nastavení. Bol to však vynikajúci a silný nástroj, ako celý proces zautomatizovať.

S .NET Frameworkom 2.0 prišiel systém MSBuild, ktorý sa stal základom pre kompiláciu nielen zdrojového kódu, ale celého projektu. MSBuild spracuváva projektové súbory (.csproj, .vbproj) vo formáte XML a okrem kompilovania dokáže aj spracovať resource súbory .resx, XAML súbory, digitálne podpísať assemblies a skopírovať výsledné súbory do výstupného priečinku. MSBuild obsahuje pre každý typ projektu vlastnú sadu úloh, ktoré vedia, ako správne konkrétny typ projektu spracovať. Windows aplikácie teda dokáže správne pripraviť na Click-Once nasadenie a webové aplikácie zase zabaliť do balíčku, ktorý je možné poslať na IIS a nasadiť tak aplikáciu na web. A ani poslanie tohto balíčku nemusíte robiť ručne – MSBuild obsahuje úlohu, ktorá automaticky pošle balíček na IIS server.

Visual Studio a MSBuild sú spolu integrované a preto čo zmeníte vo Visual Studiu, to sa prejaví v projektovom súbore a MSBuild ho rovnako spracuje aj pri spustení z príkazového riadku. Vývojári teda po zmene nastavení projektu môžu zmenený projektový súbor uložiť do repozitáru a keď sa na serveri spustí automatický build, tak si môžu byť istý, že bude spustený s novými nastaveniami a nemusia pracne prekonfigurovávať a prepisovať buildovacie skripty. MSBuild je súčasťou základnej inštalácie .NET Frameworku a nie je potrebné mať nainštalované Visual Studio pre jeho použitie. Toto sa však týka použitia základných úloh dostupných v MSBuild. Po nainštalovaní si Visual Studia a Windows SDK sa do MSBuild pridajú nový typy úloh, ktoré vedia pracovať s novými funkciami potrebnými pre správne zbuildovanie projektov (napr. sa nainštalujú nástroje pre kompiláciu Entity Framework súborov). Na build serveri teda je potrebné mať nainštalované Visual Studio a Windows SDK a udržiavať ich aktuálne – podľa toho, ako to vyžadujú použité funkcie v projektoch – ale integrácia s build systémami je veľmi jednoduchá, pretože na skomplikovanie projektu stačí spustiť msbuild.exe z príkazového riadku.

Priamu podporu pre MSBuild má CruiseControl.NET a aj TeamCity a samozrejme Team Foundation Server (a určite aj ďalšie systémy, ja však poznám iba tieto).