Home
%3CLINGO-SUB%20id%3D%22lingo-sub-1124865%22%20slang%3D%22en-US%22%3ESupporting%20a%20modular%20Windows%20application%20with%20MSIX%20and%20Optional%20Packages%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1124865%22%20slang%3D%22en-US%22%3E%3CP%3EMSIX%20aims%20to%20become%20the%20best%20packaging%20and%20deployment%20technology%20for%20Windows%20desktop%20applications%20and%2C%20on%20this%20blog%2C%20we%20have%20seen%20multiple%20times%20its%20advantages%3A%20the%20clean%20install%20%26amp%3B%20uninstall%20experience%2C%20the%20network%20bandwidth%20and%20disk%20space%20optimizations%2C%20the%20support%20to%20automatic%20updates%20even%20without%20using%20the%20Microsoft%20Store%2C%20etc.%20However%2C%20there%20is%20a%20category%20of%20applications%20for%20which%2C%20at%20first%20glance%2C%20adopting%20MSIX%20could%20be%20a%20challenge%3A%20modular%20applications.%20We're%20talking%20about%20applications%20that%20offers%20a%20set%20of%20core%20features%2C%20but%20that%20can%20be%20expanded%20with%20additional%20ones%20by%20installing%20additional%20components%2C%20like%20plug-ins%20or%20modules.%20There%20are%20many%20applications%20on%20the%20market%20that%20behave%20this%20way%3A%20Paint.NET%2C%20Office%2C%20etc.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20challenge%20comes%20from%20the%20fact%20that%20Win32%20applications%20packaged%20with%20MSIX%20run%20inside%20a%20lightweight%20container.%20It%20isn't%20a%20full%20sandbox%20like%20the%20one%20leveraged%20by%20Universal%20Windows%20Platform%20apps%2C%20but%20still%20helps%20to%20isolate%20some%20of%20the%20most%20critical%20aspects%20of%20an%20application%2C%20like%20the%20registry%20or%20the%20AppData%20folder%20in%20the%20file%20system.%20If%20this%20feature%20bring%20many%20security%20and%20reliability%20benefits%2C%20it%20can%20be%20a%20challenge%20for%20applications%20that%20need%20to%20be%20extended%20with%20additional%20modules.%20Since%20the%20registry%20and%20the%20file%20system%20are%20isolated%2C%20for%20a%20module%20it%20can%20be%20hard%20to%20interact%20with%20the%20main%20application.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20this%20blog%20post%20we're%20going%20to%20explore%20a%20couple%20of%20options%20to%20implement%20this%20scenario%20with%20MSIX.%20But%20first%2C%20let's%20introduce%20the%20application%20we're%20going%20to%20use%20to%20demonstrate%20the%20scenario.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22an-extensible-application%22%20id%3D%22toc-hId-1083523640%22%20id%3D%22toc-hId-1083523640%22%20id%3D%22toc-hId-1083523640%22%20id%3D%22toc-hId-1083523640%22%20id%3D%22toc-hId-1083523640%22%20id%3D%22toc-hId-1083523640%22%3EAn%20extensible%20application%3C%2FH3%3E%0A%3CP%3EThe%20starting%20point%20is%20a%20Windows%20Forms%20application%20built%20on%20top%20of%20.NET%20Framework%204.8%2C%20which%20is%20available%20on%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2FWindows-AppConsult-Samples-DesktopBridge%2Ftree%2Fmaster%2FBlog-OptionalPackages%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EGitHub%3C%2FA%3E.%20The%20application%2C%20called%20MyEmployees%2C%20is%20very%20simple%3A%20it%20displays%20a%20list%20of%20employees%20that%20is%20stored%20in%20a%20SQLite%20database%20which%20ships%20with%20the%20application%20itself.%20The%20data%20access%20layer%20is%20implemented%20using%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fsystem.data.sqlite.org%2Findex.html%2Fdoc%2Ftrunk%2Fwww%2Findex.wiki%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3ESystem.Data.SQLite%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Elibrary%2C%20which%20is%20an%20ADO.NET%20provider%20for%20SQLite.%20The%20frontend%2C%20instead%2C%20is%20made%20by%20a%20form%20which%20includes%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EDataGrid%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Econtrol%2C%20which%20is%20populated%20by%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EBindingSource%3C%2FCODE%3E.%20When%20the%20application%20starts%2C%20we%20execute%20a%20query%20on%20the%20SQLite%20database%20to%20retrieve%20all%20the%20employees.%20I%20won't%20go%20into%20the%20details%20in%20this%20post%20because%20it%20would%20be%20out%20of%20scope%20from%20the%20purpose%20of%20the%20article.%20The%20key%20feature%20we're%20interested%20to%20implement%20is%20extensions%20support.%20The%20application%20allows%20to%20export%20the%20list%20of%20employees%20in%20a%20CSV%20file.%20However%2C%20this%20feature%20isn't%20implemented%20directly%20in%20the%20main%20core%2C%20but%20in%20a%20separate%20plugin%20that%20can%20be%20installed%20independently.%20If%20this%20plugin%20is%20found%2C%20the%20application%20will%20enable%20the%20export%20option%3B%20otherwise%2C%20it%20will%20stay%20hidden.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELet's%20see%2C%20step%20by%20step%2C%20how%20it%20has%20been%20implemented.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH4%20id%3D%22define-a-common-interface%22%20id%3D%22toc-hId-1774085114%22%20id%3D%22toc-hId-1774085114%22%20id%3D%22toc-hId-1774085114%22%20id%3D%22toc-hId-1774085114%22%20id%3D%22toc-hId-1774085114%22%20id%3D%22toc-hId-1774085114%22%3EDefine%20a%20common%20interface%3C%2FH4%3E%0A%3CP%3EAs%20first%20step%2C%20we%20need%20to%20define%20a%20generic%20interface%20that%20describes%20a%20plugin.%20This%20interface%20must%20be%20implemented%20by%20every%20plugin%20and%20the%20main%20application%20must%20be%20aware%20of%20it.%20Every%20plugin%2C%20in%20fact%2C%20can%20offer%20different%20features%2C%20but%20it%20must%20provide%20a%20standard%20way%20to%20be%20leveraged%20by%20the%20main%20application.%20Since%20the%20interface%20must%20be%20shared%20between%20every%20plugin%20and%20the%20main%20application%2C%20we're%20going%20to%20create%20a%20dedicated%20Class%20Library%20to%20store%20it.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20is%20the%20purpose%20of%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EMyEmployees.PluginInterface%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eproject%20you%20can%20see%20in%20the%20Visual%20Studio%20solution.%20It%20contains%20just%20a%20single%20file%2C%20which%20defines%20a%20generic%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EIPlugin%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Einterface%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20id%3D%22pragma-line-23%22%20class%3D%22language-csharp%20hljs%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Epublic%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-keyword%22%3Einterface%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-title%22%3EIPlugin%3C%2FSPAN%3E%0A%7B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Estring%3C%2FSPAN%3E%20Name%20%7B%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eget%3C%2FSPAN%3E%3B%20%7D%0A%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Estring%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-title%22%3EGetDescription%3C%2FSPAN%3E()%3C%2FSPAN%3E%3B%0A%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Ebool%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-title%22%3EExecute%3C%2FSPAN%3E(%3CSPAN%20class%3D%22hljs-params%22%3EIList%20data%2C%20%3CSPAN%20class%3D%22hljs-keyword%22%3Estring%3C%2FSPAN%3E%20filePath%3C%2FSPAN%3E)%3C%2FSPAN%3E%3B%0A%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eevent%3C%2FSPAN%3E%20EventHandler%20OnExecute%3B%0A%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EThe%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EExecute()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod%20is%20the%20one%20which%20we're%20going%20to%20use%20to%20implement%20the%20export%20logic.%20It%20receives%2C%20as%20parameters%20from%20the%20main%20application%2C%20the%20list%20of%20employees%20and%20the%20path%20where%20to%20save%20the%20CSV%20file.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH4%20id%3D%22implement-the-plugin%22%20id%3D%22toc-hId--33369349%22%20id%3D%22toc-hId--33369349%22%20id%3D%22toc-hId--33369349%22%20id%3D%22toc-hId--33369349%22%20id%3D%22toc-hId--33369349%22%20id%3D%22toc-hId--33369349%22%3EImplement%20the%20plugin%3C%2FH4%3E%0A%3CP%3ENow%20that%20we%20have%20an%20interface%2C%20we%20can%20implement%20it.%20However%2C%20since%20the%20plugin%20is%20an%20extension%2C%20we're%20going%20to%20do%20it%20in%20another%20class%20library.%20It's%20the%20project%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EExportDataLibrary%3C%2FSTRONG%3E.%20Let's%20take%20a%20look%20at%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EExportData.cs%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efile%20included%20in%20the%20project%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20id%3D%22pragma-line-41%22%20class%3D%22language-csharp%20hljs%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Epublic%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eclass%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-title%22%3EExportData%3C%2FSPAN%3E%3A%20%3CSPAN%20class%3D%22hljs-title%22%3EIPlugin%3C%2FSPAN%3E%0A%7B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Epublic%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-keyword%22%3Estring%3C%2FSPAN%3E%20Name%20%3D%26gt%3B%20%3CSPAN%20class%3D%22hljs-string%22%3E%22Export%20Data%22%3C%2FSPAN%3E%3B%0A%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Epublic%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eevent%3C%2FSPAN%3E%20EventHandler%20OnExecute%3B%0A%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Epublic%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ebool%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-title%22%3EExecute%3C%2FSPAN%3E(%3CSPAN%20class%3D%22hljs-params%22%3EIList%20data%2C%20%3CSPAN%20class%3D%22hljs-keyword%22%3Estring%3C%2FSPAN%3E%20filePath%3C%2FSPAN%3E)%3C%2FSPAN%3E%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Etry%3C%2FSPAN%3E%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eusing%3C%2FSPAN%3E%20(TextWriter%20textWriter%20%3D%20File.CreateText(filePath))%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20CsvWriter%20csvWriter%20%3D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Enew%3C%2FSPAN%3E%20CsvWriter(textWriter)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20csvWriter.Configuration.Delimiter%20%3D%20%3CSPAN%20class%3D%22hljs-string%22%3E%22%3B%22%3C%2FSPAN%3E%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20csvWriter.WriteRecords(data)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ereturn%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-literal%22%3Etrue%3C%2FSPAN%3E%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ecatch%3C%2FSPAN%3E%20(Exception%20exc)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ereturn%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-literal%22%3Efalse%3C%2FSPAN%3E%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Epublic%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-keyword%22%3Estring%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-title%22%3EGetDescription%3C%2FSPAN%3E()%3C%2FSPAN%3E%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ereturn%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E%22Export%20data%20to%20CSV%22%3C%2FSPAN%3E%3B%0A%20%20%20%20%7D%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EWe're%20implementing%20every%20property%20and%20method%20exposed%20by%20the%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EIPlugin%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3Binterface.%20The%20core%20of%20the%20plugin%20is%20the%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EExecute()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3Bmethod%2C%20which%20contains%20the%20logic%20to%20export%20the%20CSV%20file.%20The%20task%20is%20achieved%20using%20a%20library%20called%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fjoshclose.github.io%2FCsvHelper%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3ECsvHelper%3C%2FA%3E%3CSPAN%3E%2C%20which%20makes%20the%20whole%20implementation%20really%20easy.%20We%20create%20a%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ETextWriter%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3Bobject%2C%20which%20is%20linked%20to%20the%20file%20path%20passed%20by%20the%20main%20application.%20We%20use%20it%20to%20initialize%20a%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ECsvWriter%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3Bobject.%20We%20setup%20the%20delimiter%20to%20use%20(a%20semi%20colon)%20and%20then%20we%20write%20the%20list%20of%20employees%20passed%20by%20the%20main%20application%20using%20the%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EWriteRecords()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3Bmethod.%20That's%20it!%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH4%20id%3D%22the-main-application%22%20id%3D%22toc-hId--1840823812%22%20id%3D%22toc-hId--1840823812%22%20id%3D%22toc-hId--1840823812%22%20id%3D%22toc-hId--1840823812%22%20id%3D%22toc-hId--1840823812%22%20id%3D%22toc-hId--1840823812%22%3EThe%20main%20application%3C%2FH4%3E%0A%3CP%3ELet's%20see%20now%20how%20we%20can%20load%20this%20plugin%20into%20the%20main%20application%20and%20leverage%20it.%20We're%20going%20to%20use%20reflection%20to%20dynamically%20load%20the%20DLL%20generated%20by%20our%20Class%20Library%20and%20discover%20the%20types%20and%20methods%20it%20implements.%20This%20is%20the%20required%20method%20to%20load%20the%20assembly%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20id%3D%22pragma-line-79%22%20class%3D%22language-csharp%20hljs%22%3E%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eprivate%3C%2FSPAN%3E%20IPlugin%20%3CSPAN%20class%3D%22hljs-title%22%3ELoadAssembly%3C%2FSPAN%3E(%3CSPAN%20class%3D%22hljs-params%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Estring%3C%2FSPAN%3E%20assemblyPath%3C%2FSPAN%3E)%3C%2FSPAN%3E%0A%7B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Estring%3C%2FSPAN%3E%20assembly%20%3D%20Path.GetFullPath(assemblyPath)%3B%0A%20%20%20%20Assembly%20ptrAssembly%20%3D%20Assembly.LoadFile(assembly)%3B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eforeach%3C%2FSPAN%3E%20(Type%20item%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ein%3C%2FSPAN%3E%20ptrAssembly.GetTypes())%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eif%3C%2FSPAN%3E%20(!item.IsClass)%20%3CSPAN%20class%3D%22hljs-keyword%22%3Econtinue%3C%2FSPAN%3E%3B%0A%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eif%3C%2FSPAN%3E%20(item.GetInterfaces().Contains(%3CSPAN%20class%3D%22hljs-keyword%22%3Etypeof%3C%2FSPAN%3E(IPlugin)))%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ereturn%3C%2FSPAN%3E%20(IPlugin)Activator.CreateInstance(item)%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ethrow%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-keyword%22%3Enew%3C%2FSPAN%3E%20Exception(%3CSPAN%20class%3D%22hljs-string%22%3E%22Invalid%20DLL%2C%20Interface%20not%20found!%22%3C%2FSPAN%3E)%3B%0A%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EThe%20parameter%20passed%20to%20the%20method%20is%20the%20path%20of%20the%20DLL.%20Once%20it%20has%20been%20loaded%20with%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ELoadFile()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod%20exposed%20by%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EAssembly%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eclass%2C%20we%20iterate%20through%20the%20types%20exposed%20by%20the%20library.%20Since%20we%20have%20defined%20a%20common%20interface%2C%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EIPlugin%3C%2FCODE%3E%2C%20we%20look%20specifically%20for%20types%20which%20implement%20it.%20Once%20we%20find%20it%2C%20we%20create%20an%20instance%20of%20the%20class%20using%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EActivator.CreateInstance()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod.%20Now%20we%20have%20a%20reference%20to%20the%20plugin%2C%20so%20we%20can%20use%20it%20through%20our%20application%20to%20invoke%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EExecute()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod%20so%20that%20we%20can%20perform%20the%20CSV%20export.%3C%2FP%3E%0A%3CP%3EThe%20application%20includes%20a%20menu%20to%20invoke%20the%20export%20feature.%20This%20is%20how%20the%20event%20handler%20connected%20to%20the%20menu%20item%20looks%20like%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20id%3D%22pragma-line-101%22%20class%3D%22language-csharp%20hljs%22%3E%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eprivate%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-keyword%22%3Evoid%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-title%22%3EexportAsCSVToolStripMenuItem_Click%3C%2FSPAN%3E(%3CSPAN%20class%3D%22hljs-params%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eobject%3C%2FSPAN%3E%20sender%2C%20EventArgs%20e%3C%2FSPAN%3E)%3C%2FSPAN%3E%0A%7B%0A%20%20%20%20SaveFileDialog%20saveFileDialog%20%3D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Enew%3C%2FSPAN%3E%20SaveFileDialog()%3B%0A%20%20%20%20saveFileDialog.Filter%20%3D%20%3CSPAN%20class%3D%22hljs-string%22%3E%22CSV%7C*.csv%22%3C%2FSPAN%3E%3B%0A%20%20%20%20saveFileDialog.Title%20%3D%20%3CSPAN%20class%3D%22hljs-string%22%3E%22Save%20a%20CSV%20file%22%3C%2FSPAN%3E%3B%0A%20%20%20%20saveFileDialog.ShowDialog()%3B%0A%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ebool%3C%2FSPAN%3E%20isFileSaved%20%3D%20plugin.Execute(employeeBindingSource.List%2C%20saveFileDialog.FileName)%3B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eif%3C%2FSPAN%3E%20(isFileSaved)%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20MessageBox.Show(%3CSPAN%20class%3D%22hljs-string%22%3E%22The%20CSV%20file%20has%20been%20exported%20with%20success%22%3C%2FSPAN%3E)%3B%0A%20%20%20%20%7D%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eelse%3C%2FSPAN%3E%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20MessageBox.Show(%3CSPAN%20class%3D%22hljs-string%22%3E%22The%20export%20operation%20has%20failed%22%3C%2FSPAN%3E)%3B%0A%20%20%20%20%7D%0A%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EThe%20application%20uses%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ESaveFileDialog%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eobject%20to%20let%20the%20user%20choose%20where%20he%20wants%20to%20save%20the%20generated%20CSV%20file.%20Then%20we%20invoke%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EExecute()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod%20exposed%20by%20the%20plugin%2C%20using%20the%20reference%20we%20have%20previously%20retrieved%20with%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ELoadAssembly()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod.%20We%20pass%20two%20parameters%3A%20the%20list%20of%20employees%20(stored%20in%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EList%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eproperty%20of%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EBindingSource%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eobject)%20and%20path%20of%20the%20file%20just%20selected%20by%20the%20user%2C%20which%20is%20stored%20in%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EFileName%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eproperty%20of%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ESaveFileDialog%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eobject.%3C%2FP%3E%0A%3CP%3EThat's%20it!%20We%20miss%20only%20one%20step%3A%20invoke%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ELoadAssembly()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod%20passing%20the%20path%20of%20the%20DLL%20which%20includes%20our%20plugin.%20We%20do%20this%20when%20the%20application%20is%20loaded%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20id%3D%22pragma-line-125%22%20class%3D%22language-csharp%20hljs%22%3E%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Epublic%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-keyword%22%3Evoid%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-title%22%3ELoadPlugins%3C%2FSPAN%3E()%3C%2FSPAN%3E%20%0A%7B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Etry%3C%2FSPAN%3E%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Estring%3C%2FSPAN%3E%20dllPath%20%3D%20%3CSPAN%20class%3D%22hljs-string%22%3E%24%22%3CSPAN%20class%3D%22hljs-subst%22%3E%7BEnvironment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)%7D%3C%2FSPAN%3E%5C%5CContoso%5C%5CMyEmployees%5C%5CPlugins%5C%5CExportDataLibrary.dll%22%3C%2FSPAN%3E%3B%0A%20%20%20%20%20%20%20%20plugin%20%3D%20LoadAssembly(dllPath)%3B%0A%20%20%20%20%20%20%20%20exportAsCsvButton.Visible%20%3D%20%3CSPAN%20class%3D%22hljs-literal%22%3Etrue%3C%2FSPAN%3E%3B%0A%20%20%20%20%7D%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ecatch%3C%2FSPAN%3E%20(Exception)%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20exportMenu.Visible%20%3D%20%3CSPAN%20class%3D%22hljs-literal%22%3Efalse%3C%2FSPAN%3E%3B%0A%20%20%20%20%7D%0A%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EThe%20application%20expects%20to%20find%20the%20plugin%20in%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EC%3A%5CProgram%20Files%20(x86)%5CContoso%5CMyEmployees%5CPlugins%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efolder.%20If%20it%20can%20find%20the%20DLL%20and%20load%20it%20properly%2C%20then%20the%20menu%20to%20export%20the%20CSV%20is%20made%20visible%3B%20otherwise%2C%20it%20stays%20hidden.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20solution%20contains%20also%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fmsix%2Fdesktop%2Fdesktop-to-uwp-packaging-dot-net%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EWindows%20Application%20Packaging%20Project%3C%2FA%3E%2C%20which%20is%20used%20to%20package%20the%20Windows%20Forms%20application%20with%20MSIX.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%20that%20we%20have%20an%20idea%20of%20the%20general%20architecture%20of%20the%20application%2C%20let's%20see%20how%20can%20we%20deploy%20the%20application%20and%20the%20plugin%20using%20the%20MSIX%20technology.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22the-first-option-modification-packages%22%20id%3D%22toc-hId--1851326916%22%20id%3D%22toc-hId--1851326916%22%20id%3D%22toc-hId--1851326916%22%20id%3D%22toc-hId--1851326916%22%20id%3D%22toc-hId--1851326916%22%20id%3D%22toc-hId--1851326916%22%3EThe%20first%20option%3A%20modification%20packages%3C%2FH3%3E%0A%3CP%3ELet's%20start%20with%20the%20simplest%20scenario%2C%20which%20doesn't%20require%20to%20change%20the%20code%20of%20the%20application.%20As%20such%2C%20we%20need%20to%20find%20a%20way%20to%20deploy%20the%20plugin%20in%20a%20separate%20way%20than%20the%20main%20application%20but%2C%20at%20the%20same%20time%2C%20make%20sure%20it%20can%20find%20it%20in%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EC%3A%5CProgram%20Files%20(x86)%5CContoso%5CMyEmployees%5CPlugins%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efolder.%20Let's%20introduce%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Emodification%20packages%3C%2FSTRONG%3E%2C%20which%20have%20already%20been%20discussed%20multiple%20times%20on%20this%20blog.%20A%20modification%20package%20is%20a%20special%20MSIX%20optional%20package%2C%20which%20doesn't%20contain%20a%20full%20application%2C%20but%20files%20and%20assets%20that%20can%20be%20leveraged%20by%20another%20application.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20key%20feature%20of%20modification%20packages%20is%20that%20they%20share%20the%20same%20identity%20of%20the%20main%20application.%20As%20such%2C%20when%20you%20leverage%20MSIX%20features%20like%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fmsix%2Fdesktop%2Fdesktop-to-uwp-behind-the-scenes%23file-system%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EVirtual%20File%20System%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eor%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fmsix%2Fdesktop%2Fdesktop-to-uwp-behind-the-scenes%23registry%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EVirtual%20Registry%3C%2FA%3E%2C%20Windows%20will%20treat%20them%20like%20if%20they%20belong%20to%20the%20same%20application.%20Let's%20see%20how%20this%20behavior%20can%20be%20leveraged%20for%20our%20scenario.%20We%20know%20that%20MSIX%20supports%20a%20feature%20called%20Virtual%20File%20System%2C%20which%20is%20implemented%20with%20a%20special%20folder%20called%20VFS%20that%20can%20be%20included%20inside%20a%20package.%20This%20folder%20can%20contain%20special%20folders%20(the%20full%20list%20is%20available%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fmsix%2Fdesktop%2Fdesktop-to-uwp-behind-the-scenes%23file-system%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E%2C%20which%20maps%20common%20system%20folders%2C%20like%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EC%3A%5CProgram%20Files%3C%2FCODE%3E%2C%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EC%3A%5CWindows%3C%2FCODE%3E%2C%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EC%3A%5CWindows%5CSystem32%3C%2FCODE%3E%2C%20etc.%20When%20the%20application%20runs%20and%20looks%20for%20files%20in%20a%20system%20folder%20(like%20a%20dependency)%2C%20Windows%20will%20look%20first%20in%20the%20VFS%20folder.%20This%20approach%20allows%20you%20to%20create%20self-contained%20MSIX%20packages%2C%20which%20don't%20require%20the%20user%20to%20manually%20install%20additional%20dependencies%20required%20by%20the%20application%3B%20additionally%2C%20it%20helps%20to%20solve%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FDLL_Hell%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EDLL%20Hell%20problem%3C%2FA%3E%2C%20when%20multiple%20versions%20of%20the%20same%20dependency%20must%20coexist%20on%20the%20same%20machine.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhen%20we%20install%20a%20modification%20package%2C%20Windows%20will%20treat%20the%20VFS%20folder%20included%20inside%20it%20like%20if%20belongs%20to%20the%20main%20application.%20This%20means%20that%2C%20if%20we%20include%20our%20plugin%20inside%20the%20folder%20which%20maps%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EC%3A%5CProgram%20Files%20(x86)%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E(which%20is%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EProgramFilesX86%3C%2FSTRONG%3E)%2C%20the%20application%20will%20be%20able%20to%20find%20it%20without%20needing%20any%20code%20change.%3C%2FP%3E%0A%3CP%3ELet's%20see%20the%20real%20modification%20package%2C%20so%20that%20we%20can%20fully%20understand%20what%20I've%20just%20explained.%20You%20can%20download%20it%20from%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2FWindows-AppConsult-Samples-DesktopBridge%2Ftree%2Fmaster%2FBlog-OptionalPackages%2FPlugin%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EGitHub%20repository%3C%2FA%3E.%20The%20easiest%20way%20to%20edit%20is%20to%20install%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fmsix%2Fpackaging-tool%2Fmpt-overview%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EMSIX%20Packaging%20Tool%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efrom%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fwww.microsoft.com%2Fp%2Fmsix-packaging-tool%2F9n5lw3jbcxkf%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ethe%20Microsoft%20Store%3C%2FA%3E.%20This%20way%2C%20you%20just%20need%20to%20right%20click%20on%20the%20package%20and%20choose%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EEdit%20with%20the%20MSIX%20Packaging%20Tool%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eto%20explore%20it.%3C%2FP%3E%0A%3CP%3ELet's%20start%20by%20taking%20a%20look%20at%20the%20manifest%20file%2C%20by%20clicking%20on%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EOpen%20file%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ebutton%20under%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EManifest%20file%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Esection%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20id%3D%22pragma-line-160%22%20class%3D%22language-xml%20hljs%22%3E%3CSPAN%20class%3D%22hljs-meta%22%3E%3C%2FSPAN%3E%0A%3CSPAN%20class%3D%22hljs-tag%22%3E%26lt%3B%3CSPAN%20class%3D%22hljs-name%22%3EPackage%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-attr%22%3Exmlns%3C%2FSPAN%3E%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22http%3A%2F%2Fschemas.microsoft.com%2Fappx%2Fmanifest%2Ffoundation%2Fwindows10%22%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-attr%22%3Exmlns%3Auap%3C%2FSPAN%3E%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22http%3A%2F%2Fschemas.microsoft.com%2Fappx%2Fmanifest%2Fuap%2Fwindows10%22%3C%2FSPAN%3E%20%20%3CSPAN%20class%3D%22hljs-attr%22%3Exmlns%3Auap4%3C%2FSPAN%3E%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22http%3A%2F%2Fschemas.microsoft.com%2Fappx%2Fmanifest%2Fuap%2Fwindows10%2F4%22%3C%2FSPAN%3E%26gt%3B%3C%2FSPAN%3E%0A%20%20%3CSPAN%20class%3D%22hljs-tag%22%3E%26lt%3B%3CSPAN%20class%3D%22hljs-name%22%3EIdentity%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-attr%22%3EName%3C%2FSPAN%3E%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22MyEmployees-ExportPlugin%22%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-attr%22%3EPublisher%3C%2FSPAN%3E%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22CN%3DMatteo%20Pagani%22%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-attr%22%3EVersion%3C%2FSPAN%3E%3D%3CSPAN%20class%3D%22hljs-string%22%3E%221.0.3.0%22%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-attr%22%3EProcessorArchitecture%3C%2FSPAN%3E%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22x64%22%3C%2FSPAN%3E%20%2F%26gt%3B%3C%2FSPAN%3E%0A%20%20%3CSPAN%20class%3D%22hljs-tag%22%3E%26lt%3B%3CSPAN%20class%3D%22hljs-name%22%3EProperties%3C%2FSPAN%3E%26gt%3B%3C%2FSPAN%3E%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-tag%22%3E%26lt%3B%3CSPAN%20class%3D%22hljs-name%22%3EDisplayName%3C%2FSPAN%3E%26gt%3B%3C%2FSPAN%3EMyEmployees%20(Export%20Plugin)%3CSPAN%20class%3D%22hljs-tag%22%3EDisplayName%3C%2FSPAN%3E%26gt%3B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-tag%22%3E%26lt%3B%3CSPAN%20class%3D%22hljs-name%22%3EPublisherDisplayName%3C%2FSPAN%3E%26gt%3B%3C%2FSPAN%3EContoso%3CSPAN%20class%3D%22hljs-tag%22%3EPublisherDisplayName%3C%2FSPAN%3E%26gt%3B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-tag%22%3E%26lt%3B%3CSPAN%20class%3D%22hljs-name%22%3EDescription%3C%2FSPAN%3E%26gt%3B%3C%2FSPAN%3EReserved%3CSPAN%20class%3D%22hljs-tag%22%3EDescription%3C%2FSPAN%3E%26gt%3B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-tag%22%3E%26lt%3B%3CSPAN%20class%3D%22hljs-name%22%3ELogo%3C%2FSPAN%3E%26gt%3B%3C%2FSPAN%3EAssets%5CStoreLogo.png%3CSPAN%20class%3D%22hljs-tag%22%3ELogo%3C%2FSPAN%3E%26gt%3B%0A%20%20%3CSPAN%20class%3D%22hljs-tag%22%3EProperties%3C%2FSPAN%3E%26gt%3B%0A%20%20%3CSPAN%20class%3D%22hljs-tag%22%3E%26lt%3B%3CSPAN%20class%3D%22hljs-name%22%3EResources%3C%2FSPAN%3E%26gt%3B%3C%2FSPAN%3E%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-tag%22%3E%26lt%3B%3CSPAN%20class%3D%22hljs-name%22%3EResource%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-attr%22%3ELanguage%3C%2FSPAN%3E%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22en-us%22%3C%2FSPAN%3E%20%2F%26gt%3B%3C%2FSPAN%3E%0A%20%20%3CSPAN%20class%3D%22hljs-tag%22%3EResources%3C%2FSPAN%3E%26gt%3B%0A%20%20%3CSPAN%20class%3D%22hljs-tag%22%3E%26lt%3B%3CSPAN%20class%3D%22hljs-name%22%3EDependencies%3C%2FSPAN%3E%26gt%3B%3C%2FSPAN%3E%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-tag%22%3E%26lt%3B%3CSPAN%20class%3D%22hljs-name%22%3ETargetDeviceFamily%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-attr%22%3EName%3C%2FSPAN%3E%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22Windows.Desktop%22%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-attr%22%3EMinVersion%3C%2FSPAN%3E%3D%3CSPAN%20class%3D%22hljs-string%22%3E%2210.0.17701.0%22%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-attr%22%3EMaxVersionTested%3C%2FSPAN%3E%3D%3CSPAN%20class%3D%22hljs-string%22%3E%2210.0.17763.0%22%3C%2FSPAN%3E%20%2F%26gt%3B%3C%2FSPAN%3E%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-tag%22%3E%26lt%3B%3CSPAN%20class%3D%22hljs-name%22%3Euap4%3AMainPackageDependency%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-attr%22%3EName%3C%2FSPAN%3E%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22MyEmployees%22%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-attr%22%3EPublisher%3C%2FSPAN%3E%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22CN%3DMatteo%20Pagani%22%3C%2FSPAN%3E%20%2F%26gt%3B%3C%2FSPAN%3E%0A%20%20%3CSPAN%20class%3D%22hljs-tag%22%3EDependencies%3C%2FSPAN%3E%26gt%3B%0A%3CSPAN%20class%3D%22hljs-tag%22%3EPackage%3C%2FSPAN%3E%26gt%3B%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EAs%20you%20can%20see%2C%20exactly%20like%20a%20traditional%20MSIX%20package%2C%20it%20has%20an%20identity%2C%20a%20publisher%2C%20a%20version%20number%2C%20etc.%20However%2C%20there%20are%20two%20major%20key%20differences%3A%3C%2FP%3E%0A%3CUL%20id%3D%22pragma-line-182%22%3E%0A%3CLI%20id%3D%22pragma-line-182%22%3EIt%20doesn't%20have%20an%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EApplication%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eentry.%20Since%20it%20doesn't%20contain%20a%20full%20application%2C%20this%20package%20doesn't%20have%20an%20entry%20point.%3C%2FLI%3E%0A%3CLI%20id%3D%22pragma-line-183%22%3EInside%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EDependencies%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Esection%20we%20can%20find%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EMainPackageDependency%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eentry%2C%20which%20specifies%20the%20name%20and%20the%20publisher%20of%20the%20main%20application%20it%20targets.%20If%20the%20application%20which%20identity%20is%20specified%20with%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EMainPackageDependency%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eentry%20is%20not%20installed%2C%20Windows%20will%20refuse%20to%20install%20the%20optional%20package.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EAnd%20what%20about%20the%20content%3F%20Move%20to%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EPackage%20files%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Esection%20to%20explore%20the%20content%20of%20the%20package.%20We%20can%20see%20that%20the%20output%20of%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EExportDataLibrary%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eclass%20library%20build%20has%20been%20copied%20inside%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EVFS%2FProgramFilesX86%2FContoso%2FMyEmployees%2FPlugins%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efolder.%20This%20is%20the%20folder%20where%20the%20original%20code%20of%20the%20application%20expects%20to%20find%20the%20plugin.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20786px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F166773iA5C49A26F1FCFBCA%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22VFS.png%22%20title%3D%22VFS.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ELet's%20see%20this%20in%20action.%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2FWindows-AppConsult-Samples-DesktopBridge%2Ftree%2Fmaster%2FBlog-OptionalPackages%2FMyEmployees-ModificationPackages%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EThis%20is%20the%20version%20of%20the%20app%20to%20use%3C%2FA%3E%3CSPAN%3E.%20Open%20the%20solution%20in%20Visual%20Studio%2C%20then%20right%20click%20on%20the%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EMyEmployees.Package%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3Bproject%20and%20choose%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EDeploy%3C%2FSTRONG%3E%3CSPAN%3E.%20Launch%20it%20and%20notice%20how%20the%20export%20menu%20is%20hidden%2C%20since%20the%20plugin%20DLL%20can't%20be%20found.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20802px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F166774i193693377B25154A%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22ExportMissing.png%22%20title%3D%22ExportMissing.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ENow%20double%20click%20on%20the%20modification%20package%20which%20you%20have%20just%20downloaded%20from%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2FWindows-AppConsult-Samples-DesktopBridge%2Ftree%2Fmaster%2FBlog-OptionalPackages%2FPlugin%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ethe%20repository%3C%2FA%3E.%20The%20installation%20will%20proceed%20like%20with%20a%20regular%20MSIX%20package%2C%20excepts%20that%20the%20Windows%20won't%20offer%20you%20the%20option%20to%20launch%20the%20application%20since%2C%20well...%20we%20didn't%20install%20an%20application%20%3D)%3C%2Fimg%3E%20For%20the%20same%20reason%2C%20if%20we%20open%20the%20Start%20menu%20we%20won't%20find%20the%20optional%20package%20listed%20in%20the%20list%20of%20programs.%20We%20will%20continue%20to%20find%20only%20the%20My%20Employees%20application.%20Where%20can%20we%20see%20the%20optional%20package%3F%20Right%20click%20on%20the%20My%20Employees%20entry%20in%20the%20Start%20menu%20and%20choose%26nbsp%3B%3CSTRONG%3EMore%20%E2%86%92%20App%20Settings%3C%2FSTRONG%3E.%20Scroll%20down%20the%20settings%20page%20until%20you%20see%20a%20section%20titled%26nbsp%3B%3CSTRONG%3EApp%20add-ons%20%26amp%3B%20downloadable%20content%3C%2FSTRONG%3E.%20Here%20is%20our%20plugin!%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20506px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F166775i25BD02B0E7324E21%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22PluginSettings.png%22%20title%3D%22PluginSettings.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ENow%20open%20the%20My%20Employees%20application.%20You%20can%20immediately%20see%20that%20the%20plugin%20has%20been%20recognized%2C%20since%20now%20the%20Export%20option%20is%20available%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20802px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F166776iBB79405CE57754D5%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22ExportAvailable.png%22%20title%3D%22ExportAvailable.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EAnd%20if%20you%20click%20on%20the%20option%2C%20you%20will%20start%20the%20process%20to%20create%20a%20CSV%20and%20export%20it%20on%20a%20file%20on%20your%20local%20PC.%20Everything%20is%20working%2C%20without%20needing%20us%20to%20touch%20the%20code%20of%20the%20original%20application.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22option-2-using-an-optional-package%22%20id%3D%22toc-hId-636185917%22%20id%3D%22toc-hId-636185917%22%20id%3D%22toc-hId-636185917%22%20id%3D%22toc-hId-636185917%22%20id%3D%22toc-hId-636185917%22%20id%3D%22toc-hId-636185917%22%3EOption%202%3A%20using%20an%20Optional%20Package%3C%2FH3%3E%0A%3CP%3EThe%20previous%20scenario%20is%20great%20for%20legacy%20applications%20or%20IT%20Pros%20who%20don't%20have%20access%20to%20the%20code%2C%20but%20it%20doesn't%20offer%20too%20much%20flexibility.%20We%20are%20required%20to%20leverage%20the%20Virtual%20File%20System%20to%20%22fake%22%20to%20the%20main%20application%20that%20our%20plugin%20is%20indeed%20installed%20in%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EC%3A%5CProgram%20Files%20(x86)%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efolder%2C%20which%20limits%20our%20opportunities%20to%20do%20more.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20we%20are%20developers%20there's%20a%20better%20way%20to%20use%20the%20optional%20package%20which%20contains%20our%20plugin.%20The%20Universal%20Windows%20Platform%2C%20in%20fact%2C%20offers%20a%20set%20of%20APIs%20to%20query%20all%20the%20optional%20packages%20that%20are%20installed%20for%20an%20application.%20For%20each%20of%20them%2C%20we%20can%20get%20the%20identity%2C%20we%20can%20access%20to%20all%20the%20included%20files%2C%20etc.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELet's%20start%20with%20analyzing%20the%20optional%20package.%20From%20an%20architectural%20point%20of%20view%2C%20there's%20no%20difference%20with%20the%20modification%20package%20we%20have%20seen%20before.%20A%20modification%20package%2C%20in%20fact%2C%20is%20just%20an%20optional%20package%20which%2C%20by%20leveraging%20the%20Virtual%20File%20System%20and%20the%20Virtual%20Registry%2C%20can%20make%20its%20content%20available%20to%20the%20main%20application%20without%20changing%20the%20code.%20A%20traditional%20optional%20package%2C%20in%20fact%2C%20doesn't%20need%20to%20leverage%20these%20features%3A%20the%20application%20is%20aware%20of%20the%20existence%20of%20optional%20packages%20and%2C%20as%20such%2C%20can%20freely%20load%20the%20files%20which%20are%20included.%20Other%20than%20that%2C%20they%20behave%20in%20the%20exact%20same%20way.%20They%20are%20both%20installed%20in%20the%20same%20way%3B%20they%20both%20appear%20in%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EApp%20add-ons%20%26amp%3B%20downloadable%20content%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Esection%20of%20the%20App%20Settings%3B%20they%20can%20be%20deployed%20independently%20from%20the%20main%20application.%3C%2FP%3E%0A%3CP%3EAlso%20in%20this%20case%20you%20can%20find%20the%20optional%20package%20in%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2FWindows-AppConsult-Samples-DesktopBridge%2Ftree%2Fmaster%2FBlog-OptionalPackages%2FPlugin%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ethe%20repository%3C%2FA%3E.%20If%20you%20edit%20it%20with%20the%20MSIX%20Packaging%20Tool%2C%20you%20will%20notice%20that%20it%20has%20the%20same%20exact%20manifest%20of%20the%20modification%20package.%20The%20only%20difference%20is%20the%20package%20content%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20786px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F166777iB8DFA20CEC727237%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22FilesOptionalPackage.png%22%20title%3D%22FilesOptionalPackage.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESince%20we%20don't%20need%20to%20leverage%20anymore%20the%20VFS%2C%20we%20can%20just%20include%20the%20files%20which%20belong%20to%20our%20plugin%20in%20the%20root%20of%20the%20package.%20Let's%20see%20now%20how%20we%20can%20use%20this%20optional%20package%20in%20the%20Windows%20Forms%20application.%20As%20first%20step%2C%20we%20need%20to%20use%20some%20Windows%2010%20APIs%2C%20so%20we%20need%20to%20install%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fwww.nuget.org%2Fpackages%2FMicrosoft.Windows.SDK.Contracts%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EMicrosoft.Windows.Sdk.Contracts%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Epackage%20from%20NuGet%2C%20which%20allows%20our%20.NET%20application%20to%20access%20to%20the%20API%20surface%20of%20the%20Universal%20Windows%20Platform.%20Once%20you%20have%20installed%20it%2C%20we%20can%20leverage%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EPackage%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eclass%20included%20in%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EWindows.ApplicationModel%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Enamespace%20to%20query%20our%20optional%20packages.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20is%20the%20code%20we're%20going%20to%20use%20to%20access%20to%20our%20plugin%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20id%3D%22pragma-line-221%22%20class%3D%22language-csharp%20hljs%22%3E%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eprivate%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-keyword%22%3Easync%3C%2FSPAN%3E%20Task%20%3CSPAN%20class%3D%22hljs-title%22%3ELoadOptionalPackagesAsync%3C%2FSPAN%3E()%3C%2FSPAN%3E%0A%7B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eif%3C%2FSPAN%3E%20(Package.Current.Dependencies.Count%20%26gt%3B%20%3CSPAN%20class%3D%22hljs-number%22%3E0%3C%2FSPAN%3E)%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eforeach%3C%2FSPAN%3E%20(%3CSPAN%20class%3D%22hljs-keyword%22%3Evar%3C%2FSPAN%3E%20package%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ein%3C%2FSPAN%3E%20Package.Current.Dependencies)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eif%3C%2FSPAN%3E%20(package.Id.Name.Contains(%3CSPAN%20class%3D%22hljs-string%22%3E%22ExportPlugin%22%3C%2FSPAN%3E))%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Evar%3C%2FSPAN%3E%20file%20%3D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eawait%3C%2FSPAN%3E%20package.InstalledLocation.GetFileAsync(%3CSPAN%20class%3D%22hljs-string%22%3E%22ExportDataLibrary.dll%22%3C%2FSPAN%3E)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20plugin%20%3D%20LoadAssembly(file.Path)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20exportAsCsvButton.Visible%20%3D%20%3CSPAN%20class%3D%22hljs-literal%22%3Etrue%3C%2FSPAN%3E%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eelse%3C%2FSPAN%3E%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20exportAsCsvButton.Visible%20%3D%20%3CSPAN%20class%3D%22hljs-literal%22%3Efalse%3C%2FSPAN%3E%3B%0A%20%20%20%20%7D%0A%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EAll%20the%20optional%20packages%20are%20available%20through%20a%20collection%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EDependencies%3C%2FCODE%3E%2C%20exposed%20by%20the%20singleton%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EPackage.Current%3C%2FCODE%3E.%20In%20our%20case%20we%20iterate%20through%20all%20the%20packages%20and%2C%20if%20we%20find%20one%20which%20name%20(stored%20in%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EId.Name%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eproperty)%20contains%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EExportPlugin%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Estring%2C%20it%20means%20we%20can%20enable%20the%20export%20feature.%20All%20the%20files%20included%20in%20the%20optional%20package%20are%20available%20through%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EInstalledLocation%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eproperty%2C%20which%20type%20is%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EStorageFolder%3C%2FCODE%3E.%20This%20means%20that%20we%20can%20use%20all%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fuwp%2Ffiles%2Findex%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EWindows%2010%20Storage%20APIs%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eto%20query%2C%20open%20and%20work%20with%20the%20files%20included%20in%20the%20optional%20package.%20In%20our%20case%2C%20we%20use%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EGetFileAsync()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod%20to%20get%20a%20reference%20to%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EExportDataLibrary.dll%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efile.%20Then%2C%20we%20use%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EPath%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eproperty%20as%20parameter%20to%20invoke%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ELoadAssembly()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod%20and%20we%20save%20a%20reference%20to%20the%20plugin%2C%20so%20that%20we%20can%20use%20it%20later%20when%20the%20we%20need%20to%20use%20the%20CSV%20export%20function.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAs%20you%20can%20see%2C%20these%20APIs%20offer%20more%20flexibility%20compared%20to%20the%20modification%20package%20scenario.%20The%20MyEmployees%20application%20is%20very%20simple%20and%20we%20have%20developed%20only%20one%20plugin%2C%20but%20think%20to%20an%20application%20which%20can%20have%20hundreds%20of%20plugins.%20Thanks%20to%20these%20APIs%20we%20could%20provide%20a%20UI%20that%20displays%20all%20the%20available%20optional%20packages%2C%20allowing%20to%20the%20user%20to%20enable%2C%20disable%20or%20manage%20them.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20want%20to%20try%20also%20this%20scenario%20on%20your%20machine%2C%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2FWindows-AppConsult-Samples-DesktopBridge%2Ftree%2Fmaster%2FBlog-OptionalPackages%2FMyEmployees-OptionalPackages%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ethis%20is%20the%20folder%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ewhich%20contains%20the%20MyEmployees%20version%20which%20uses%20the%20Optional%20Packages%20APIs.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22wrapping-up%22%20id%3D%22toc-hId--1171268546%22%20id%3D%22toc-hId--1171268546%22%20id%3D%22toc-hId--1171268546%22%20id%3D%22toc-hId--1171268546%22%20id%3D%22toc-hId--1171268546%22%20id%3D%22toc-hId--1171268546%22%3EWrapping%20up%3C%2FH3%3E%0A%3CP%3EIn%20this%20post%20we%20have%20seen%20two%20different%20options%20to%20support%20extensible%20applications%20with%20MSIX%3A%3C%2FP%3E%0A%3CUL%20id%3D%22pragma-line-254%22%3E%0A%3CLI%20id%3D%22pragma-line-254%22%3EUsing%20modification%20packages%2C%20which%20leverage%20the%20Virtual%20File%20System%20and%20the%20Virtual%20Registry%20provided%20by%20the%20platform.%20This%20allows%20to%20leverage%20MSIX%20for%20plugins%20without%20asking%20the%20developer%20to%20change%20the%20code%20of%20the%20application.%20However%2C%20this%20approach%20is%20limited%20by%20the%20way%20the%20developer%20has%20created%20the%20plugin%20support.%20We%20are%20forced%20to%20follow%20his%20constraints%20and%20it's%20not%20granted%20that%20the%20way%20he%20has%20implemented%20plugin%20support%20will%20be%20fully%20compliant%20with%20modification%20packages.%3C%2FLI%3E%0A%3CLI%20id%3D%22pragma-line-255%22%3EUsing%20optional%20packages%2C%20which%20require%20the%20developer%20to%20change%20the%20code%20of%20the%20application%20but%20they%20give%20you%20lot%20of%20flexibility.%20You%20can%20query%20for%20the%20installed%20optional%20packages%3B%20you%20can%20access%20to%20the%20included%20file%3B%20etc.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EBefore%20closing%20the%20post%2C%20there's%20an%20important%20caveat%20to%20keep%20in%20mind.%20You%20can't%20publish%20a%20modification%20package%20or%20an%20optional%20package%20on%20the%20Microsoft%20Store.%20As%20such%2C%20everything%20we%20have%20seen%20in%20this%20post%20applies%20only%20for%20enterprise%20distribution%20or%20sideloading.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAs%20usual%2C%20you%20can%20find%20the%20sample%20used%20in%20this%20post%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2FWindows-AppConsult-Samples-DesktopBridge%2Ftree%2Fmaster%2FBlog-OptionalPackages%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eon%20GitHub%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHappy%20coding!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1124865%22%20slang%3D%22en-US%22%3E%3CP%3ELearn%20how%20to%20load%20optional%20modules%20in%20a%20Win32%20application%20packaged%20with%20MSIX%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1127142%22%20slang%3D%22en-US%22%3ERe%3A%20Supporting%20a%20modular%20Windows%20application%20with%20MSIX%20and%20Optional%20Packages%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1127142%22%20slang%3D%22en-US%22%3EHow%20much%20of%20this%20technology%20is%20supported%20on%20Windows%207%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1127157%22%20slang%3D%22en-US%22%3ERe%3A%20Supporting%20a%20modular%20Windows%20application%20with%20MSIX%20and%20Optional%20Packages%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1127157%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%3C%2FP%3E%0A%3CP%3EI'm%20sorry%20but%20none%20of%20them.%20Regarding%20the%20modification%20packages%20scenario%2C%20with%20MSIX%20Core%20(%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fmsix%2Fmsix-core%2Fmsixcore%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fmsix%2Fmsix-core%2Fmsixcore%3C%2FA%3E)%20you%20can%20install%20MSIX%20packages%20on%20Windows%207%2C%20but%20they%20act%20as%20a%20traditional%20installers.%20All%20the%20specific%20MSIX%20features%20(like%20the%20Virtual%20File%20System%20and%20modification%20packages)%20are%20missing%2C%20since%20they%20would%20require%20deep%20OS%20changes%20that%20are%20included%20in%20Windows%2010.%3C%2FP%3E%0A%3CP%3EAs%20per%20the%20optional%20packages%2C%20instead%2C%20you%20need%20to%20use%20Windows%2010%20APIs%20to%20iterate%20and%20load%20the%20content%20of%20the%20packages%20and%2C%20as%20such%2C%20the%20application%20wouldn't%20work%20on%20Windows%207.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBest%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1131023%22%20slang%3D%22en-US%22%3EBetreff%3A%20Supporting%20a%20modular%20Windows%20application%20with%20MSIX%20and%20Optional%20Packages%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1131023%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F44595%22%20target%3D%22_blank%22%3E%40Matteo%20Pagani%3C%2FA%3E%26nbsp%3B%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eone%20question%20regarding%20your%20caveat%20at%20the%20end%20of%20your%20article%3A%20%22%3CSPAN%3EYou%20can't%20publish%20a%20modification%20package%20or%20an%20optional%20package%20on%20the%20Microsoft%20Store.%22%3CBR%20%2F%3EWhy%20the%20heck%20this%20restriction%3F%20It%20is%20obviously%20not%20a%20technical%20thing%2C%20since%20optional%20packages%20and%20related%20API%20are%20already%20around%20for%20a%20while%20in%20UWP.%20Documation%20mentions%20also%20nice%20things%20like%20separate%20licensing%20for%20those%20optional%20packages%20(which%20would%20be%20great%2C%20shipping%20optional%20packages%20only%20when%20users%20really%20need%20them%20and%20bought%20an%20associated%20in-app%20purchase!)%3CBR%20%2F%3E%3CBR%20%2F%3E%22To%20submit%20an%20app%20that%20uses%20optional%20packages%20and%2For%20related%20sets%20to%20the%20Microsoft%20Store%2C%20you%20will%20need%20permission.%26nbsp%3B%22%3CBR%20%2F%3E%5B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fmsix%2Fpackage%2Foptional-packages%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fmsix%2Fpackage%2Foptional-packages%3C%2FA%3E%5D%3CBR%20%2F%3E%3CBR%20%2F%3EOnce%20again%2C%20this%20is%20a%20store%20feature%20that%20is%20available%20-%20but%20not%20for%20everyone.%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1133614%22%20slang%3D%22en-US%22%3ERe%3A%20Supporting%20a%20modular%20Windows%20application%20with%20MSIX%20and%20Optional%20Packages%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1133614%22%20slang%3D%22en-US%22%3E%3CP%3EHello%20and%20thanks%20for%20your%20feedback.%20I%20will%20share%20it%20with%20the%20Microsoft%20Store%20team.%20Unfortunately%2C%20I%20don't%20have%20an%20answer%20on%20why%20this%20feature%20isn't%20open%20to%20all%20the%20developers.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Microsoft

MSIX aims to become the best packaging and deployment technology for Windows desktop applications and, on this blog, we have seen multiple times its advantages: the clean install & uninstall experience, the network bandwidth and disk space optimizations, the support to automatic updates even without using the Microsoft Store, etc. However, there is a category of applications for which, at first glance, adopting MSIX could be a challenge: modular applications. We're talking about applications that offers a set of core features, but that can be expanded with additional ones by installing additional components, like plug-ins or modules. There are many applications on the market that behave this way: Paint.NET, Office, etc.

 

The challenge comes from the fact that Win32 applications packaged with MSIX run inside a lightweight container. It isn't a full sandbox like the one leveraged by Universal Windows Platform apps, but still helps to isolate some of the most critical aspects of an application, like the registry or the AppData folder in the file system. If this feature bring many security and reliability benefits, it can be a challenge for applications that need to be extended with additional modules. Since the registry and the file system are isolated, for a module it can be hard to interact with the main application.

 

In this blog post we're going to explore a couple of options to implement this scenario with MSIX. But first, let's introduce the application we're going to use to demonstrate the scenario.

 

An extensible application

The starting point is a Windows Forms application built on top of .NET Framework 4.8, which is available on GitHub. The application, called MyEmployees, is very simple: it displays a list of employees that is stored in a SQLite database which ships with the application itself. The data access layer is implemented using the System.Data.SQLite library, which is an ADO.NET provider for SQLite. The frontend, instead, is made by a form which includes a DataGrid control, which is populated by a BindingSource. When the application starts, we execute a query on the SQLite database to retrieve all the employees. I won't go into the details in this post because it would be out of scope from the purpose of the article. The key feature we're interested to implement is extensions support. The application allows to export the list of employees in a CSV file. However, this feature isn't implemented directly in the main core, but in a separate plugin that can be installed independently. If this plugin is found, the application will enable the export option; otherwise, it will stay hidden.

 

Let's see, step by step, how it has been implemented.

 

Define a common interface

As first step, we need to define a generic interface that describes a plugin. This interface must be implemented by every plugin and the main application must be aware of it. Every plugin, in fact, can offer different features, but it must provide a standard way to be leveraged by the main application. Since the interface must be shared between every plugin and the main application, we're going to create a dedicated Class Library to store it.

 

This is the purpose of the MyEmployees.PluginInterface project you can see in the Visual Studio solution. It contains just a single file, which defines a generic IPlugin interface:

 

public interface IPlugin
{
    string Name { get; }

    string GetDescription();

    bool Execute(IList data, string filePath);

    event EventHandler OnExecute;
}

The Execute() method is the one which we're going to use to implement the export logic. It receives, as parameters from the main application, the list of employees and the path where to save the CSV file.

 

Implement the plugin

Now that we have an interface, we can implement it. However, since the plugin is an extension, we're going to do it in another class library. It's the project called ExportDataLibrary. Let's take a look at the ExportData.cs file included in the project:

 

public class ExportData: IPlugin
{
    public string Name => "Export Data";

    public event EventHandler OnExecute;

    public bool Execute(IList data, string filePath)
    {
        try
        {
            using (TextWriter textWriter = File.CreateText(filePath))
            {
                CsvWriter csvWriter = new CsvWriter(textWriter);
                csvWriter.Configuration.Delimiter = ";";
                csvWriter.WriteRecords(data);
            }

            return true;
        }
        catch (Exception exc)
        {
            return false;
        }
    }

    public string GetDescription()
    {
        return "Export data to CSV";
    }
}

 

We're implementing every property and method exposed by the IPlugin interface. The core of the plugin is the Execute() method, which contains the logic to export the CSV file. The task is achieved using a library called CsvHelper, which makes the whole implementation really easy. We create a TextWriter object, which is linked to the file path passed by the main application. We use it to initialize a CsvWriter object. We setup the delimiter to use (a semi colon) and then we write the list of employees passed by the main application using the WriteRecords() method. That's it!

 

The main application

Let's see now how we can load this plugin into the main application and leverage it. We're going to use reflection to dynamically load the DLL generated by our Class Library and discover the types and methods it implements. This is the required method to load the assembly:

 

private IPlugin LoadAssembly(string assemblyPath)
{
    string assembly = Path.GetFullPath(assemblyPath);
    Assembly ptrAssembly = Assembly.LoadFile(assembly);
    foreach (Type item in ptrAssembly.GetTypes())
    {
        if (!item.IsClass) continue;
        if (item.GetInterfaces().Contains(typeof(IPlugin)))
        {
            return (IPlugin)Activator.CreateInstance(item);
        }
    }
    throw new Exception("Invalid DLL, Interface not found!");
}

The parameter passed to the method is the path of the DLL. Once it has been loaded with the LoadFile() method exposed by the Assembly class, we iterate through the types exposed by the library. Since we have defined a common interface, IPlugin, we look specifically for types which implement it. Once we find it, we create an instance of the class using the Activator.CreateInstance() method. Now we have a reference to the plugin, so we can use it through our application to invoke the Execute() method so that we can perform the CSV export.

The application includes a menu to invoke the export feature. This is how the event handler connected to the menu item looks like:

 

private void exportAsCSVToolStripMenuItem_Click(object sender, EventArgs e)
{
    SaveFileDialog saveFileDialog = new SaveFileDialog();
    saveFileDialog.Filter = "CSV|*.csv";
    saveFileDialog.Title = "Save a CSV file";
    saveFileDialog.ShowDialog();

    bool isFileSaved = plugin.Execute(employeeBindingSource.List, saveFileDialog.FileName);
    if (isFileSaved)
    {
        MessageBox.Show("The CSV file has been exported with success");
    }
    else
    {
        MessageBox.Show("The export operation has failed");
    }
}

The application uses a SaveFileDialog object to let the user choose where he wants to save the generated CSV file. Then we invoke the Execute() method exposed by the plugin, using the reference we have previously retrieved with the LoadAssembly() method. We pass two parameters: the list of employees (stored in the List property of the BindingSource object) and path of the file just selected by the user, which is stored in the FileName property of the SaveFileDialog object.

That's it! We miss only one step: invoke the LoadAssembly() method passing the path of the DLL which includes our plugin. We do this when the application is loaded:

 

public void LoadPlugins() 
{
    try
    {
        string dllPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\\Contoso\\MyEmployees\\Plugins\\ExportDataLibrary.dll";
        plugin = LoadAssembly(dllPath);
        exportAsCsvButton.Visible = true;
    }
    catch (Exception)
    {
        exportMenu.Visible = false;
    }
}

The application expects to find the plugin in the C:\Program Files (x86)\Contoso\MyEmployees\Plugins folder. If it can find the DLL and load it properly, then the menu to export the CSV is made visible; otherwise, it stays hidden.

 

The solution contains also a Windows Application Packaging Project, which is used to package the Windows Forms application with MSIX.

 

Now that we have an idea of the general architecture of the application, let's see how can we deploy the application and the plugin using the MSIX technology.

 

The first option: modification packages

Let's start with the simplest scenario, which doesn't require to change the code of the application. As such, we need to find a way to deploy the plugin in a separate way than the main application but, at the same time, make sure it can find it in the C:\Program Files (x86)\Contoso\MyEmployees\Plugins folder. Let's introduce modification packages, which have already been discussed multiple times on this blog. A modification package is a special MSIX optional package, which doesn't contain a full application, but files and assets that can be leveraged by another application.

 

The key feature of modification packages is that they share the same identity of the main application. As such, when you leverage MSIX features like the Virtual File System or the Virtual Registry, Windows will treat them like if they belong to the same application. Let's see how this behavior can be leveraged for our scenario. We know that MSIX supports a feature called Virtual File System, which is implemented with a special folder called VFS that can be included inside a package. This folder can contain special folders (the full list is available here, which maps common system folders, like C:\Program Files, C:\Windows, C:\Windows\System32, etc. When the application runs and looks for files in a system folder (like a dependency), Windows will look first in the VFS folder. This approach allows you to create self-contained MSIX packages, which don't require the user to manually install additional dependencies required by the application; additionally, it helps to solve the DLL Hell problem, when multiple versions of the same dependency must coexist on the same machine.

 

When we install a modification package, Windows will treat the VFS folder included inside it like if belongs to the main application. This means that, if we include our plugin inside the folder which maps C:\Program Files (x86) (which is called ProgramFilesX86), the application will be able to find it without needing any code change.

Let's see the real modification package, so that we can fully understand what I've just explained. You can download it from the GitHub repository. The easiest way to edit is to install the MSIX Packaging Tool from the Microsoft Store. This way, you just need to right click on the package and choose Edit with the MSIX Packaging Tool to explore it.

Let's start by taking a look at the manifest file, by clicking on the Open file button under the Manifest file section:

 

<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"  xmlns:uap4="http://schemas.microsoft.com/appx/manifest/uap/windows10/4">
  <Identity Name="MyEmployees-ExportPlugin" Publisher="CN=Matteo Pagani" Version="1.0.3.0" ProcessorArchitecture="x64" />
  <Properties>
    <DisplayName>MyEmployees (Export Plugin)</DisplayName>
    <PublisherDisplayName>Contoso</PublisherDisplayName>
    <Description>Reserved</Description>
    <Logo>Assets\StoreLogo.png</Logo>
  </Properties>
  <Resources>
    <Resource Language="en-us" />
  </Resources>
  <Dependencies>
    <TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17701.0" MaxVersionTested="10.0.17763.0" />
    <uap4:MainPackageDependency Name="MyEmployees" Publisher="CN=Matteo Pagani" />
  </Dependencies>
</Package>

As you can see, exactly like a traditional MSIX package, it has an identity, a publisher, a version number, etc. However, there are two major key differences:

  • It doesn't have an Application entry. Since it doesn't contain a full application, this package doesn't have an entry point.
  • Inside the Dependencies section we can find a MainPackageDependency entry, which specifies the name and the publisher of the main application it targets. If the application which identity is specified with the MainPackageDependency entry is not installed, Windows will refuse to install the optional package.

And what about the content? Move to the Package files section to explore the content of the package. We can see that the output of the ExportDataLibrary class library build has been copied inside the VFS/ProgramFilesX86/Contoso/MyEmployees/Plugins folder. This is the folder where the original code of the application expects to find the plugin.

 

VFS.png

Let's see this in action. This is the version of the app to use. Open the solution in Visual Studio, then right click on the MyEmployees.Package project and choose Deploy. Launch it and notice how the export menu is hidden, since the plugin DLL can't be found.

 

ExportMissing.png

 

Now double click on the modification package which you have just downloaded from the repository. The installation will proceed like with a regular MSIX package, excepts that the Windows won't offer you the option to launch the application since, well... we didn't install an application =) For the same reason, if we open the Start menu we won't find the optional package listed in the list of programs. We will continue to find only the My Employees application. Where can we see the optional package? Right click on the My Employees entry in the Start menu and choose More → App Settings. Scroll down the settings page until you see a section titled App add-ons & downloadable content. Here is our plugin!

 

PluginSettings.png

Now open the My Employees application. You can immediately see that the plugin has been recognized, since now the Export option is available:

 

ExportAvailable.png

And if you click on the option, you will start the process to create a CSV and export it on a file on your local PC. Everything is working, without needing us to touch the code of the original application.

 

Option 2: using an Optional Package

The previous scenario is great for legacy applications or IT Pros who don't have access to the code, but it doesn't offer too much flexibility. We are required to leverage the Virtual File System to "fake" to the main application that our plugin is indeed installed in the C:\Program Files (x86) folder, which limits our opportunities to do more.

 

If we are developers there's a better way to use the optional package which contains our plugin. The Universal Windows Platform, in fact, offers a set of APIs to query all the optional packages that are installed for an application. For each of them, we can get the identity, we can access to all the included files, etc.

 

Let's start with analyzing the optional package. From an architectural point of view, there's no difference with the modification package we have seen before. A modification package, in fact, is just an optional package which, by leveraging the Virtual File System and the Virtual Registry, can make its content available to the main application without changing the code. A traditional optional package, in fact, doesn't need to leverage these features: the application is aware of the existence of optional packages and, as such, can freely load the files which are included. Other than that, they behave in the exact same way. They are both installed in the same way; they both appear in the App add-ons & downloadable content section of the App Settings; they can be deployed independently from the main application.

Also in this case you can find the optional package in the the repository. If you edit it with the MSIX Packaging Tool, you will notice that it has the same exact manifest of the modification package. The only difference is the package content:

 

FilesOptionalPackage.png

 

Since we don't need to leverage anymore the VFS, we can just include the files which belong to our plugin in the root of the package. Let's see now how we can use this optional package in the Windows Forms application. As first step, we need to use some Windows 10 APIs, so we need to install the Microsoft.Windows.Sdk.Contracts package from NuGet, which allows our .NET application to access to the API surface of the Universal Windows Platform. Once you have installed it, we can leverage the Package class included in the Windows.ApplicationModel namespace to query our optional packages.

 

This is the code we're going to use to access to our plugin:

 

private async Task LoadOptionalPackagesAsync()
{
    if (Package.Current.Dependencies.Count > 0)
    {
        foreach (var package in Package.Current.Dependencies)
        {
            if (package.Id.Name.Contains("ExportPlugin"))
            {
                var file = await package.InstalledLocation.GetFileAsync("ExportDataLibrary.dll");
                plugin = LoadAssembly(file.Path);
                exportAsCsvButton.Visible = true;
            }
        }
    }
    else
    {
        exportAsCsvButton.Visible = false;
    }
}

All the optional packages are available through a collection called Dependencies, exposed by the singleton Package.Current. In our case we iterate through all the packages and, if we find one which name (stored in the Id.Name property) contains the ExportPlugin string, it means we can enable the export feature. All the files included in the optional package are available through the InstalledLocation property, which type is StorageFolder. This means that we can use all the Windows 10 Storage APIs to query, open and work with the files included in the optional package. In our case, we use the GetFileAsync() method to get a reference to the ExportDataLibrary.dll file. Then, we use the Path property as parameter to invoke the LoadAssembly() method and we save a reference to the plugin, so that we can use it later when the we need to use the CSV export function.

 

As you can see, these APIs offer more flexibility compared to the modification package scenario. The MyEmployees application is very simple and we have developed only one plugin, but think to an application which can have hundreds of plugins. Thanks to these APIs we could provide a UI that displays all the available optional packages, allowing to the user to enable, disable or manage them.

 

If you want to try also this scenario on your machine, this is the folder which contains the MyEmployees version which uses the Optional Packages APIs.

 

Wrapping up

In this post we have seen two different options to support extensible applications with MSIX:

  • Using modification packages, which leverage the Virtual File System and the Virtual Registry provided by the platform. This allows to leverage MSIX for plugins without asking the developer to change the code of the application. However, this approach is limited by the way the developer has created the plugin support. We are forced to follow his constraints and it's not granted that the way he has implemented plugin support will be fully compliant with modification packages.
  • Using optional packages, which require the developer to change the code of the application but they give you lot of flexibility. You can query for the installed optional packages; you can access to the included file; etc.

Before closing the post, there's an important caveat to keep in mind. You can't publish a modification package or an optional package on the Microsoft Store. As such, everything we have seen in this post applies only for enterprise distribution or sideloading.

 

As usual, you can find the sample used in this post on GitHub.

 

Happy coding!

4 Comments
Regular Visitor
How much of this technology is supported on Windows 7?
Microsoft

Hello,

I'm sorry but none of them. Regarding the modification packages scenario, with MSIX Core (https://docs.microsoft.com/en-us/windows/msix/msix-core/msixcore) you can install MSIX packages on Windows 7, but they act as a traditional installers. All the specific MSIX features (like the Virtual File System and modification packages) are missing, since they would require deep OS changes that are included in Windows 10.

As per the optional packages, instead, you need to use Windows 10 APIs to iterate and load the content of the packages and, as such, the application wouldn't work on Windows 7.

 

Best

Frequent Visitor

Hi @Matteo Pagani ,

 

one question regarding your caveat at the end of your article: "You can't publish a modification package or an optional package on the Microsoft Store."
Why the heck this restriction? It is obviously not a technical thing, since optional packages and related API are already around for a while in UWP. Documation mentions also nice things like separate licensing for those optional packages (which would be great, shipping optional packages only when users really need them and bought an associated in-app purchase!)

"To submit an app that uses optional packages and/or related sets to the Microsoft Store, you will need permission. "
[https://docs.microsoft.com/en-us/windows/msix/package/optional-packages]

Once again, this is a store feature that is available - but not for everyone.

Microsoft

Hello and thanks for your feedback. I will share it with the Microsoft Store team. Unfortunately, I don't have an answer on why this feature isn't open to all the developers.