%3CLINGO-SUB%20id%3D%22lingo-sub-1133602%22%20slang%3D%22en-US%22%3EMSIX%3A%20how%20to%20copy%20data%20outside%20the%20installation%20folder%20during%20the%20deployment%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1133602%22%20slang%3D%22en-US%22%3E%3CP%3EWhen%20you%20deploy%20a%20MSIX%20package%20on%20Windows%2010%2C%20all%20the%20files%20are%20copied%20in%20a%20special%20folder%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EC%3A%5CProgram%20Files%5CWindowsApps%3C%2FCODE%3E.%20Each%20application%20has%20its%20own%20folder%2C%20which%20name%20is%20represented%20by%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EPackage%20Full%20Name%3C%2FSTRONG%3E%2C%20which%20is%20composed%20by%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EThe%20Package%20Family%20Name%20(which%20is%20composed%20by%20Publisher%20and%20Name)%3C%2FLI%3E%0A%3CLI%3EThe%20version%20number%3C%2FLI%3E%0A%3CLI%3EThe%20target%20CPU%20architecture%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EFor%20example%2C%20if%20you%20download%20the%20MSIX%20Packaging%20Tool%20from%20the%20Microsoft%20Store%2C%20it%20will%20be%20deployed%20in%20the%20folder%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-plaintext%20hljs%22%3EC%3A%5CProgram%20Files%5CWindowsApps%5CMicrosoft.MsixPackagingTool_1.2019.1220.0_x64__8wekyb3d8bbwe%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EIn%20order%20to%20track%20all%20the%20files%20which%20belong%20to%20the%20application%20more%20efficiently%2C%20Windows%20doesn't%20allow%20to%20deploy%20files%20outside%20this%20folder.%20However%2C%20you%20might%20have%20a%20scenario%20where%20you%20actually%20need%20to%20do%20this.%20For%20example%2C%20you%20must%20copy%20a%20dependency%20in%20a%20system%20folder%3B%20or%20your%20application%20comes%20with%20a%20set%20of%20data%20or%20configuration%20files%20you%20need%20to%20deploy%20in%20the%20local%20AppData%20folder%20of%20the%20user.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20overcome%20this%20requirement%2C%20MSIX%20provides%20a%20feature%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EVirtual%20File%20System%3C%2FSTRONG%3E%2C%20which%20gives%20you%20the%20possibility%20to%20map%20the%20most%20common%20system%20folders%20(like%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EC%3A%5CWindows%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eor%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EC%3A%5CProgram%20Files%3C%2FCODE%3E)%20inside%20a%20special%20folder%20inside%20the%20package%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EVFS%3C%2FSTRONG%3E.%20When%20the%20application%20looks%20for%20a%20file%20inside%20these%20folders%2C%20Windows%20will%20redirect%20the%20call%20to%20the%20VFS%20folder%20and%20will%20try%20to%20see%20if%20the%20file%20is%20included%20in%20the%20Virtual%20File%20System.%20This%20feature%20provides%20two%20main%20benefits%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EYou%20get%20the%20opportunity%20to%20create%20truly%20standalone%20MSIX%20packages.%20Even%20if%20your%20application%20has%20one%20or%20more%20dependencies%2C%20you%20can%20bundle%20everything%20together%2C%20without%20asking%20to%20the%20user%20to%20manually%20install%20a%20framework%20or%20a%20library%20your%20application%20depends%20on.%3C%2FLI%3E%0A%3CLI%3EIt%20helps%20to%20minimize%20the%20problem%20known%20as%20DLL%20Hell%2C%20which%20happens%20when%20you%20have%20multiple%20applications%20depending%20on%20different%20version%20of%20the%20same%20framework.%20Typically%20this%20framework%20can%20be%20installed%20only%20system-wide%2C%20so%20you%20can't%20keep%20multiple%20versions%20of%20the%20same%20one%20on%20the%20machine.%20This%20means%20that%2C%20if%20the%20most%20recent%20version%20contains%20some%20breaking%20changes%2C%20your%20applications%20which%20depends%20on%20older%20versions%20might%20brake.%20With%20the%20Virtual%20File%20System%20you%20can%20include%2C%20inside%20the%20package%2C%20the%20specific%20version%20of%20the%20dependency%20you%20need%20and%20it%20won't%20interfere%20with%20the%20already%20installed%20ones.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EThe%20Virtual%20File%20System%20is%20a%20great%20way%20to%20overcome%20this%20MSIX%20limitation%20when%20it%20comes%20to%20deploy%20a%20dependency.%20But%20what%20about%20when%20you%20need%20to%20copy%20data%20or%20configuration%20files%20in%20the%20local%20AppData%20folder%20or%20a%20library%20like%20Documents%3F%20In%20this%20case%2C%20the%20Virtual%20File%20System%20can't%20really%20help%20since%2C%20as%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%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eper%20the%20documentation%3C%2FA%3E%2C%20it%20supports%20mostly%20system%20folders%2C%20not%20user's%20folder%20(except%20the%20generic%20C%3A%5CProgramData%20one).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELet's%20see%20which%20options%20we%20have.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22the-sample-app%22%20id%3D%22toc-hId-1084415257%22%20id%3D%22toc-hId-1084415260%22%20id%3D%22toc-hId-1084415260%22%20id%3D%22toc-hId-1084415260%22%20id%3D%22toc-hId-1084415260%22%20id%3D%22toc-hId-1084415260%22%3EThe%20sample%20app%3C%2FH3%3E%0A%3CP%3EAs%20a%20starting%20point%2C%20we're%20going%20to%20use%20a%20simple%20Windows%20Forms%20application%2C%20which%20retrieves%20a%20list%20of%20employees%20from%20a%20local%20SQLite%20database.%20The%20whole%20code%20is%20available%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2FWindows-AppConsult-Samples-DesktopBridge%2Ftree%2Fmaster%2FBlog-Scripting%2FMyEmployees%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E.%20The%20connection%20with%20the%20database%20is%20handled%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%22nofollow%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%2C%20the%20popular%20self-contained%20database.%20When%20the%20application%20starts%2C%20it%20uses%20a%20class%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ESQLiteConnection%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eto%20establish%20a%20connection%20with%20a%20local%20SQLIte%20file.%20Then%2C%20using%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ESQLiteCommand%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eobject%2C%20it%20performs%20a%20SELECT%20query%20on%20the%20database%20to%20retrieve%20the%20list%20of%20employees.%20In%20the%20end%2C%20using%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ESQLDataReader%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eobject%2C%20it%20iterates%20through%20all%20the%20resulting%20rows%20and%20it%20adds%20them%20to%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EBindingSource%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eobject%2C%20which%20is%20connected%20to%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EDataGrid%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Econtrol%20in%20the%20UI.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20is%20the%20complete%20code%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%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%3ELoadData%3C%2FSPAN%3E()%3C%2FSPAN%3E%0A%7B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Estring%3C%2FSPAN%3E%20dbPath%20%3D%20%3CSPAN%20class%3D%22hljs-string%22%3E%24%22%3CSPAN%20class%3D%22hljs-subst%22%3E%7BEnvironment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)%7D%3C%2FSPAN%3E%5C%5CMyEmployees%5C%5CEmployees.db%22%3C%2FSPAN%3E%3B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eif%3C%2FSPAN%3E%20(File.Exists(dbPath))%0A%20%20%20%20%7B%0A%0A%20%20%20%20%20%20%20%20SQLiteConnection%20connection%20%3D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Enew%3C%2FSPAN%3E%20SQLiteConnection(%3CSPAN%20class%3D%22hljs-string%22%3E%24%22Data%20Source%3D%20%3CSPAN%20class%3D%22hljs-subst%22%3E%7BdbPath%7D%3C%2FSPAN%3E%22%3C%2FSPAN%3E)%3B%0A%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eusing%3C%2FSPAN%3E%20(SQLiteCommand%20command%20%3D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Enew%3C%2FSPAN%3E%20SQLiteCommand(connection))%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20connection.Open()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20command.CommandText%20%3D%20%3CSPAN%20class%3D%22hljs-string%22%3E%22SELECT%20*%20FROM%20Employees%22%3C%2FSPAN%3E%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eusing%3C%2FSPAN%3E%20(SQLiteDataReader%20reader%20%3D%20command.ExecuteReader())%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%3Ewhile%3C%2FSPAN%3E%20(reader.Read())%0A%20%20%20%20%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%20%20%20%20Employee%20employee%20%3D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Enew%3C%2FSPAN%3E%20Employee%0A%20%20%20%20%20%20%20%20%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%20%20%20%20%20%20%20%20EmployeeId%20%3D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eint%3C%2FSPAN%3E.Parse(reader%5B%3CSPAN%20class%3D%22hljs-number%22%3E0%3C%2FSPAN%3E%5D.ToString())%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20FirstName%20%3D%20reader%5B%3CSPAN%20class%3D%22hljs-number%22%3E1%3C%2FSPAN%3E%5D.ToString()%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20LastName%20%3D%20reader%5B%3CSPAN%20class%3D%22hljs-number%22%3E2%3C%2FSPAN%3E%5D.ToString()%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Email%20%3D%20reader%5B%3CSPAN%20class%3D%22hljs-number%22%3E3%3C%2FSPAN%3E%5D.ToString()%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20employeeBindingSource.Add(employee)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%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%0A%20%20%20%20%20%20%20%20dataGridView1.DataSource%20%3D%20employeeBindingSource%3B%0A%20%20%20%20%7D%0A%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EAs%20you%20can%20see%20from%20the%20first%20line%20of%20the%20method%2C%20the%20application%20is%20expecting%20to%20find%20the%20SQLite%20database%20in%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EC%3A%5CProgramData%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efolder.%20The%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EEnvironment.SpecialFolder.CommonApplicationData%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efolder%20is%20translated%20with%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3E%25PROGRAMDATA%25%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eenvironment%20variable.%20This%20means%20that%20the%20application%20looks%20for%20the%20database%20in%20the%20path%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EC%3A%5CProgramData%5CMyEmployees%5CEmployees.db%3C%2FCODE%3E.%20The%20package%20of%20the%20application%20includes%20a%20file%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EEmployees.db%3C%2FCODE%3E%2C%20which%20we%20want%20to%20copy%20in%20this%20folder.%20Without%20doing%20this%2C%20the%20app%20would%20display%20an%20empty%20DataGrid%20when%20it%20starts.%20However%2C%20this%20is%20a%20task%20that%20we%20can't%20achieve%20directly%20with%20MSIX%2C%20since%20the%20content%20of%20the%20package%20(including%20our%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EEmployees.db%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efile)%20will%20be%20copied%20only%20in%20the%20special%20folder%20under%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EC%3A%5CProgram%20Files%5CWindowsApps%3C%2FCODE%3E.%20We%20could%20use%20the%20Virtual%20File%20System%2C%20since%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EC%3A%5CProgramData%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eis%20one%20of%20the%20mapped%20folders%2C%20but%20we%20want%20our%20database%20to%20be%20modifiable.%20If%20we%20leave%20it%20in%20the%20package%20folder%2C%20it%20would%20be%20read-only%20instead.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22option-1-copy-the-files-when-the-application-starts%22%20id%3D%22toc-hId--723039206%22%20id%3D%22toc-hId--723039203%22%20id%3D%22toc-hId--723039203%22%20id%3D%22toc-hId--723039203%22%20id%3D%22toc-hId--723039203%22%20id%3D%22toc-hId--723039203%22%3EOption%201%3A%20copy%20the%20files%20when%20the%20application%20starts%3C%2FH3%3E%0A%3CP%3EThis%20might%20seem%20obvious%2C%20but%20it's%20the%20best%20option%20if%20we're%20talking%20about%20an%20application%20which%20is%20still%20actively%20developed.%20When%20the%20application%20starts%20for%20the%20first%20time%2C%20we%20can%20just%20copy%20the%20file%20into%20the%20local%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EC%3A%5CProgramData%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efolder.%20We%20can%20use%20multiple%20ways%20to%20detect%20if%20the%20it's%20the%20first%20launch%3A%20we%20can%20add%20a%20key%20in%20the%20registry%3B%20we%20can%20store%20the%20information%20in%20a%20configuration%20file%3B%20or%20we%20can%20simply%20look%20if%20the%20database%20already%20exists%20in%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EC%3A%5CProgramData%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efolder.%3C%2FP%3E%0A%3CP%3EHere%20is%20an%20example%20of%20a%20method%20that%20we%20can%20add%20to%20our%20application%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%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%3ECopyDatabase%3C%2FSPAN%3E()%3C%2FSPAN%3E%0A%7B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Estring%3C%2FSPAN%3E%20result%20%3D%20Assembly.GetExecutingAssembly().Location%3B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eint%3C%2FSPAN%3E%20index%20%3D%20result.LastIndexOf(%3CSPAN%20class%3D%22hljs-string%22%3E%22%5C%5C%22%3C%2FSPAN%3E)%3B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Estring%3C%2FSPAN%3E%20dbPath%20%3D%20%3CSPAN%20class%3D%22hljs-string%22%3E%24%22%3CSPAN%20class%3D%22hljs-subst%22%3E%7Bresult.Substring(%3CSPAN%20class%3D%22hljs-number%22%3E0%3C%2FSPAN%3E%2C%20index)%7D%3C%2FSPAN%3E%5C%5CEmployees.db%22%3C%2FSPAN%3E%3B%0A%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Estring%3C%2FSPAN%3E%20destinationPath%20%3D%20%3CSPAN%20class%3D%22hljs-string%22%3E%24%22%3CSPAN%20class%3D%22hljs-subst%22%3E%7BEnvironment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)%7D%3C%2FSPAN%3E%5C%5CMyEmployees%5C%5CEmployees.db%22%3C%2FSPAN%3E%3B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Estring%3C%2FSPAN%3E%20destinationFolder%20%3D%20%3CSPAN%20class%3D%22hljs-string%22%3E%24%22%3CSPAN%20class%3D%22hljs-subst%22%3E%7BEnvironment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)%7D%3C%2FSPAN%3E%5C%5CMyEmployees%5C%5C%22%3C%2FSPAN%3E%3B%0A%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eif%3C%2FSPAN%3E%20(!File.Exists(destinationPath))%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20Directory.CreateDirectory(destinationFolder)%3B%0A%20%20%20%20%20%20%20%20File.Copy(dbPath%2C%20destinationPath%2C%20%3CSPAN%20class%3D%22hljs-literal%22%3Etrue%3C%2FSPAN%3E)%3B%0A%20%20%20%20%7D%0A%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EFirst%20we%20get%20a%20reference%20to%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EEmployees.db%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efile%20which%20is%20included%20in%20the%20package%20folder.%20We%20use%20reflection%20since%2C%20when%20an%20application%20runs%20as%20packaged%2C%20the%20Current%20Working%20Directory%20is%20mapped%20with%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EC%3A%5CWindows%5CSystem32%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eor%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EC%3A%5CWindows%5CSysWOW64%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efolder.%20As%20such%2C%20we%20can't%20simply%20use%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EDirectory.GetCurrentDirectory()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EAPI%20to%20achieve%20this%20task.%20Once%20we%20have%20the%20path%20of%20the%20database%20file%2C%20we%20use%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EEnvironment.SpecialFolder.CommonApplicationData%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eproperty%20to%20compose%20the%20full%20path%20of%20the%20destination%20folder.%20In%20this%20case%2C%20we%20want%20to%20copy%20the%20database%20inside%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EC%3A%5CProgramData%5CMyEmployees%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efolder.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20the%20end%2C%20if%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EEmployees.db%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efile%20doesn't%20exist%20in%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EC%3A%5CProgramData%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efolder%2C%20it%20means%20that%20it's%20the%20first%20execution%20of%20the%20app.%20As%20such%2C%20we%20go%20on%20and%20we%20copy%20the%20database%20from%20the%20package%20inside%20the%20destination%20folder.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThat's%20it.%20Now%20we%20just%20need%20to%20make%20sure%20that%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ECopyDatabase()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod%20we%20have%20just%20defined%20is%20invoked%20before%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ELoadData()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eone%20we%20have%20previously%20seen.%20This%20is%20how%20the%20event%20handler%20of%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ELoad%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eevent%20of%20the%20form%20will%20look%20like%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%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%3EForm1_Load%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%20CopyDatabase()%3B%0A%20%20%20%20LoadData()%3B%20%20%20%20%20%20%20%20%0A%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ENow%20we%20can%20package%20our%20application%20with%20MSIX%20by%20adding%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%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EWindows%20Application%20Packaging%20Project%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eto%20our%20solution.%20If%20we%20did%20everything%20properly%2C%20when%20we%20launch%20the%20application%20we%20will%20see%20the%20list%20of%20the%20employees%20in%20the%20DataGrid.%20And%20if%20we%20use%20File%20Explorer%20to%20open%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EC%3A%5CProgramData%5CMyEmployees%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Epath%2C%20we%20will%20see%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EEmployees.db%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efile%20we%20have%20copied.%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%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F167728iB34AD67F708225E3%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22DatabaseFile.png%22%20title%3D%22DatabaseFile.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22option-2-copy-the-files-with-a-powershell-script%22%20id%3D%22toc-hId-1764473627%22%20id%3D%22toc-hId-1764473630%22%20id%3D%22toc-hId-1764473630%22%20id%3D%22toc-hId-1764473630%22%20id%3D%22toc-hId-1764473630%22%20id%3D%22toc-hId-1764473630%22%3EOption%202%3A%20copy%20the%20files%20with%20a%20PowerShell%20script%3C%2FH3%3E%0A%3CP%3EIn%20some%20cases%2C%20we%20might%20not%20be%20able%20to%20change%20the%20code%20of%20our%20application.%20It%20might%20be%20because%20you%20aren't%20a%20developer%2C%20but%20you%20manage%20the%20deployment%20of%20applications%20in%20your%20enterprise%20and%2C%20as%20such%2C%20you%20don't%20have%20the%20source%20code%3B%20or%20it's%20a%20legacy%20app%20built%20with%20a%20very%20old%20technology%20and%20it%20would%20be%20risky%20to%20make%20any%20change.%20In%20this%20scenario%2C%20we%20can%20leverage%20a%20feature%20that%20has%20been%20recently%20added%20to%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fmsix%2Fpsf%2Fpackage-support-framework-overview%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EPackage%20Support%20Framework%3C%2FA%3E%3A%20scripting%20support.%20We%20have%20already%20talked%20about%20this%20framework%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fwindows-dev-appconsult%2Fsolving-common-desktop-bridge-blockers-with-the-package-support%2Fba-p%2F317457%22%20target%3D%22_blank%22%3Eon%20this%20blog%3C%2FA%3E%3A%20it's%20an%20open%20source%20framework%20which%20provides%20support%20to%20fixups%2C%20which%20are%20DLLs%20that%20are%20able%20to%20change%20the%20behavior%20of%20your%20application%20at%20runtime.%20This%20way%2C%20you%20can%20solve%20common%20MSIX%20blockers%20(like%20apps%20which%20write%20to%20the%20installation%20folder%20or%20need%20to%20access%20to%20the%20current%20working%20directory)%20without%20changing%20the%20code.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESince%20a%20few%20months%2C%20the%20Package%20Support%20Framework%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fmsix%2Fpsf%2Frun-scripts-with-package-support-framework%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehas%20added%20supports%20to%20script%3C%2FA%3E.%20You%20can%20include%20inside%20your%20package%20one%20or%20more%20PowerShell%20scripts%20and%20execute%20them%20on%20various%20conditions%3A%20when%20the%20application%20starts%20or%20closes%2C%20only%20the%20first%20time%20after%20the%20MSIX%20package%20has%20been%20deployed%20or%20every%20time%2C%20etc.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20feature%20is%20a%20great%20fit%20for%20our%20scenario%3A%20we%20can%20include%20inside%20the%20package%20a%20script%20that%20takes%20care%20of%20copying%20the%20database%20file%20to%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EC%3A%5CProgramData%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efolder%2C%20without%20having%20to%20change%20the%20code.%20Let's%20see%20how%20to%20do%20it.%20We're%20going%20to%20use%20Visual%20Studio%20and%20the%20Windows%20Application%20Packaging%20Project%20since%20I'm%20a%20developer%2C%20but%20you%20can%20perform%20also%20the%20following%20steps%20manually%2C%20by%20unpacking%20the%20MSIX%20package%2C%20injecting%20the%20Package%20Support%20Framework%20and%20then%20repackaging%20it%20again.%20This%20way%2C%20you%20can%20leverage%20the%20same%20approach%20even%20if%20you%20aren't%20a%20developer%20or%20you%20don't%20use%20Visual%20Studio.%20This%20approach%20is%20described%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fmsix%2Fpsf%2Fpackage-support-framework%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ein%20the%20official%20documentation%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH4%20id%3D%22step-1-create-the-powershell-script%22%20id%3D%22toc-hId--1839932195%22%20id%3D%22toc-hId--1839932192%22%20id%3D%22toc-hId--1839932192%22%20id%3D%22toc-hId--1839932192%22%20id%3D%22toc-hId--1839932192%22%20id%3D%22toc-hId--1839932192%22%3EStep%201%3A%20create%20the%20PowerShell%20script%3C%2FH4%3E%0A%3CP%3EAs%20first%20step%2C%20let's%20create%20the%20PowerShell%20script%20which%20is%20going%20to%20copy%20the%20database%20from%20the%20package%20to%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EC%3A%5CProgramData%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efolder.%20You%20can%20use%20any%20text%20editor%2C%20from%20Notepad%20to%20Visual%20Studio%20code.%20This%20is%20the%20script%20to%20copy%20and%20paste%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-powershell%20hljs%22%3E%3CSPAN%20class%3D%22hljs-built_in%22%3ENew-Item%3C%2FSPAN%3E%20-Path%20%3CSPAN%20class%3D%22hljs-variable%22%3E%24env%3AProgramData%3C%2FSPAN%3E%20-Name%20%3CSPAN%20class%3D%22hljs-string%22%3E%22MyEmployees%22%3C%2FSPAN%3E%20-ItemType%20%3CSPAN%20class%3D%22hljs-string%22%3E%22directory%22%3C%2FSPAN%3E%0A%3CSPAN%20class%3D%22hljs-built_in%22%3ECopy-Item%3C%2FSPAN%3E%20-Path%20%3CSPAN%20class%3D%22hljs-string%22%3E%22Employees.db%22%3C%2FSPAN%3E%20-Destination%20%3CSPAN%20class%3D%22hljs-string%22%3E%22%3CSPAN%20class%3D%22hljs-variable%22%3E%24env%3AProgramData%3C%2FSPAN%3E%5CMyEmployees%22%3C%2FSPAN%3E%20-Recurse%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EFirst%20we%20use%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ENew-Item%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ecommand%20to%20create%20a%20new%20folder%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EMyEmployees%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ein%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EC%3A%5CProgramData%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Epath.%20Then%20we%20use%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ECopy-Item%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ecommand%20to%20copy%20the%20file%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EEmployees.db%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eto%20the%20folder%20we%20have%20just%20created.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH4%20id%3D%22step-2-add-the-package-support-framework%22%20id%3D%22toc-hId-647580638%22%20id%3D%22toc-hId-647580641%22%20id%3D%22toc-hId-647580641%22%20id%3D%22toc-hId-647580641%22%20id%3D%22toc-hId-647580641%22%20id%3D%22toc-hId-647580641%22%3EStep%202%3A%20add%20the%20Package%20Support%20Framework%3C%2FH4%3E%0A%3CP%3EFirst%20we%20need%20to%20download%20the%20Package%20Support%20Framework%2C%20which%20is%20distributed%20through%20NuGet.%20However%2C%20it%20isn't%20a%20traditional%20library%2C%20so%20we%20won't%20have%20to%20add%20it%20to%20a%20project%20in%20Visual%20Studio%2C%20but%20we're%20going%20to%20download%20it%20and%20copy%20some%20files%20inside%20our%20Visual%20Studio%20solution.%20The%20easiest%20way%20to%20achieve%20this%20task%20is%20by%20using%20the%20NuGet%20CLI%2C%20which%20can%20be%20downloaded%20from%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fwww.nuget.org%2Fdownloads%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ethe%20official%20website%3C%2FA%3E.%20Download%20the%20most%20recent%20Windows%20x86%20command%20line%20version%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%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F167729i582D26A62379B183%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22NuGet.png%22%20title%3D%22NuGet.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOnce%20you%20have%20downloaded%20and%20copied%20it%20somewhere%20on%20your%20computer%2C%20open%20a%20command%20prompt%20on%20that%20location%20and%20run%20the%20following%20command%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-powershell%20hljs%22%3Enuget%20install%20Microsoft.PackageSupportFramework%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EAt%20the%20end%20of%20the%20process%2C%20you%20will%20find%20in%20the%20same%20location%20a%20folder%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EMicrosoft.PackageSupportFramework%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efollowed%20by%20the%20version%20number%20of%20the%20most%20recent%20version.%20For%20example%2C%20at%20the%20moment%20of%20writing%20this%20post%2C%20the%20folder%20is%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EMicrosoft.PackageSupportFramework.1.0.200102.1%3C%2FSTRONG%3E.%20Go%20inside%20it%20and%20move%20to%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Ebin%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efolder.%20We're%20going%20to%20copy%20a%20few%20files%20inside%20the%20Windows%20Application%20Packaging%20Project%2C%20by%20dragging%20them%20from%20File%20Explorer%20to%20the%20WAP%20project%20in%20Visual%20Studio.%20If%20your%20application%20is%20compiled%20for%20x86%2C%20copy%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EPsfLauncher32.exe%3C%2FSTRONG%3E%2C%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EPsfRunDll32.exe%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EPsfRuntime32.dll%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efiles.%20If%20instead%2C%20it's%20compiled%20for%20x64%2C%20copy%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EPsfLauncher64.exe%3C%2FSTRONG%3E%2C%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EPsfRunDll64.exe%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EPsfRuntime64.dll%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efiles.%20My%20sample%20on%20GitHub%20is%20compiled%20for%2064%20bits%2C%20so%20I've%20added%20the%20files%20with%2064%20suffix.%3C%2FP%3E%0A%3CP%3EThe%20next%20step%20is%20to%20include%20inside%20the%20package%20a%20PowerShell%20script%2C%20which%20is%20used%20by%20the%20Package%20Support%20Framework%20to%20invoke%20the%20other%20custom%20scripts%20you%20include.%20This%20file%20is%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EStartingScriptWrapper.ps1%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%20it's%20included%20in%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Ebin%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efolder%20as%20well.%20However%2C%20unlike%20for%20the%20previous%20files%2C%20it%20doesn't%20have%20to%20be%20included%20in%20the%20root%20of%20the%20package%2C%20but%20in%20the%20same%20folder%20which%20contains%20the%20main%20executable%20of%20the%20application.%20In%20some%20cases%20the%20two%20things%20might%20coincide%2C%20but%20you%20can't%20take%20it%20for%20granted.%20For%20example%2C%20in%20case%20you're%20using%20the%20Windows%20Application%20Packaging%20Project%2C%20Visual%20Studio%20will%20put%20the%20main%20application's%20executable%20and%20the%20DLLs%20inside%20a%20sub-folder%20of%20the%20package%2C%20with%20the%20same%20name%20of%20the%20application.%20For%20instance%2C%20my%20sample%20app%20is%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EMyEmployees%3C%2FSTRONG%3E%2C%20so%20the%20main%20executable%20and%20files%20of%20the%20application%20will%20be%20stored%20in%20a%20folder%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EMyEmployees%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Einside%20the%20package.%20This%20is%20where%20we%20need%20to%20copy%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EStartingScriptWrapper.ps1%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efile.%20To%20achieve%20this%20goal%2C%20it's%20enough%20to%20manually%20add%20a%20folder%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EMyEmployees%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Einside%20the%20Windows%20Application%20Packaging%20Project.%20It%20will%20be%20merged%20with%20the%20one%20generated%20by%20Visual%20Studio.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EInside%20this%20folder%20we%20have%20to%20include%20also%20the%20PowerShell%20script%20that%20we%20have%20created%20at%20Step%201.%20This%20is%20how%20the%20final%20project%20should%20look%20like%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%20313px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F167730i158E3D15034C3D94%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22ProjectFile.png%22%20title%3D%22ProjectFile.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH4%20id%3D%22step-3-configure-the-package-support-framework%22%20id%3D%22toc-hId--1159873825%22%20id%3D%22toc-hId--1159873822%22%20id%3D%22toc-hId--1159873822%22%20id%3D%22toc-hId--1159873822%22%20id%3D%22toc-hId--1159873822%22%20id%3D%22toc-hId--1159873822%22%3EStep%203%3A%20configure%20the%20Package%20Support%20Framework%3C%2FH4%3E%0A%3CP%3EThe%20last%20step%20is%20to%20configure%20the%20Package%20Support%20Framework.%20So%20far%20we%20have%20just%20injected%20the%20required%20files%2C%20but%20we%20didn't%20set%20it%20up.%20If%20we%20would%20create%20a%20MSIX%20package%20now%20out%20from%20the%20Windows%20Application%20Packaging%20Project%2C%20we%20won't%20notice%20any%20difference.%20The%20main%20application%20would%20simply%20be%20launched%2C%20as%20before.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20configure%20the%20framework%20we%20need%20to%20include%20a%20file%20inside%20the%20Windows%20Application%20Packaging%20Project%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Econfig.json%3C%2FSTRONG%3E.%20Then%20copy%20and%20paste%20the%20following%20content%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-json%20hljs%22%3E%7B%0A%20%20%3CSPAN%20class%3D%22hljs-attr%22%3E%22applications%22%3C%2FSPAN%3E%3A%20%5B%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-attr%22%3E%22id%22%3C%2FSPAN%3E%3A%20%3CSPAN%20class%3D%22hljs-string%22%3E%22App%22%3C%2FSPAN%3E%2C%0A%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-attr%22%3E%22executable%22%3C%2FSPAN%3E%3A%20%3CSPAN%20class%3D%22hljs-string%22%3E%22MyEmployees%2FMyEmployees.exe%22%3C%2FSPAN%3E%2C%0A%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-attr%22%3E%22workingDirectory%22%3C%2FSPAN%3E%3A%20%3CSPAN%20class%3D%22hljs-string%22%3E%22MyEmployees%22%3C%2FSPAN%3E%2C%0A%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-attr%22%3E%22stopOnScriptError%22%3C%2FSPAN%3E%3A%20%3CSPAN%20class%3D%22hljs-literal%22%3Etrue%3C%2FSPAN%3E%2C%0A%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-attr%22%3E%22startScript%22%3C%2FSPAN%3E%3A%20%7B%0A%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-attr%22%3E%22scriptPath%22%3C%2FSPAN%3E%3A%20%3CSPAN%20class%3D%22hljs-string%22%3E%22CopyDatabase.ps1%22%3C%2FSPAN%3E%2C%0A%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-attr%22%3E%22showWindow%22%3C%2FSPAN%3E%3A%20%3CSPAN%20class%3D%22hljs-literal%22%3Efalse%3C%2FSPAN%3E%2C%0A%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-attr%22%3E%22waitForScriptToFinish%22%3C%2FSPAN%3E%3A%20%3CSPAN%20class%3D%22hljs-literal%22%3Etrue%3C%2FSPAN%3E%2C%0A%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-attr%22%3E%22runOnce%22%3C%2FSPAN%3E%3A%20%3CSPAN%20class%3D%22hljs-literal%22%3Etrue%3C%2FSPAN%3E%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%5D%0A%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ELet's%20take%20a%20look%20at%20the%20most%20important%20settings%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%0A%3CP%3E%3CCODE%3Eid%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eis%20the%20identifier%20of%20the%20application.%20We%20can%20find%20it%20by%20right%20clicking%20on%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EPackage.appxmanifest%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efile%20and%20choosing%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EView%20code%3C%2FSTRONG%3E.%20Look%20for%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EApplication%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eentry%2C%20which%20will%20look%20like%20this%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-xml%20hljs%22%3E%3CSPAN%20class%3D%22hljs-tag%22%3E%26lt%3B%3CSPAN%20class%3D%22hljs-name%22%3EApplication%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-attr%22%3EId%3C%2FSPAN%3E%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22App%22%3C%2FSPAN%3E%0A%20%20%3CSPAN%20class%3D%22hljs-attr%22%3EExecutable%3C%2FSPAN%3E%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22%24targetnametoken%24.exe%22%3C%2FSPAN%3E%0A%20%20%3CSPAN%20class%3D%22hljs-attr%22%3EEntryPoint%3C%2FSPAN%3E%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22%24targetentrypoint%24%22%3C%2FSPAN%3E%26gt%3B%3C%2FSPAN%3E%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EThe%20identifier%20of%20the%20application%20is%20the%20value%20of%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EId%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eattribute.%20If%20you're%20using%20a%20standard%20Windows%20Application%20Packaging%20Project%2C%20its%20default%20value%20is%20always%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EApp%3C%2FCODE%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3C%2FLI%3E%0A%3CLI%3E%0A%3CP%3E%3CCODE%3Eexecutable%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eis%20the%20main%20executable%20of%20the%20application.%20You%20need%20to%20specify%20the%20full%20path%20starting%20from%20the%20root%20of%20the%20package%2C%20in%20my%20case%20it's%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EMyEmployees%5CMyEmployees.exe%3C%2FCODE%3E.%3C%2FP%3E%0A%3C%2FLI%3E%0A%3CLI%3E%0A%3CP%3EIn%20order%20to%20redirect%20all%20the%20file%20system%20calls%20to%20the%20Current%20Working%20Directory%2C%20you%20need%20to%20specify%20it%20through%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EworkingDirectory%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eproperty.%20It%20must%20be%20the%20path%20of%20the%20folder%20which%20contains%20the%20main%20executable%2C%20in%20my%20case%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EMyEmployees%3C%2FCODE%3E.%3C%2FP%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EThe%20other%20settings%20are%20dedicated%20to%20configure%20the%20scripting%20support.%20These%20are%20just%20some%20settings%2C%20but%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fmsix%2Fpsf%2Frun-scripts-with-package-support-framework%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ein%20the%20documentation%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eyou'll%20find%20all%20of%20them.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EWe%20include%20the%20configuration%20of%20the%20script%20inside%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EstartScript%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Esection%2C%20since%20we%20want%20to%20run%20it%20when%20the%20application%20starts.%3C%2FLI%3E%0A%3CLI%3E%3CCODE%3EscriptPath%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eis%20the%20name%20of%20the%20PowerShell%20script%20we%20have%20created%20in%20Step%201.%3C%2FLI%3E%0A%3CLI%3E%3CCODE%3EshowWindow%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eis%20set%20to%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Efalse%3C%2FCODE%3E%2C%20since%20we%20want%20the%20script%20to%20be%20completely%20transparent%20to%20the%20user.%20We%20want%20him%20to%20just%20see%20the%20main%20application%20starting%20up.%20However%2C%20for%20testing%20purposes%2C%20it%20might%20be%20helpful%20to%20keep%20it%20to%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Etrue%3C%2FCODE%3E.%3C%2FLI%3E%0A%3CLI%3E%3CCODE%3EwaitForScriptToFinish%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eis%20set%20to%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Etrue%3C%2FCODE%3E%2C%20since%20we%20don't%20want%20to%20start%20the%20MyEmployees%20application%20until%20the%20script%20has%20finished%20to%20copy%20the%20database%2C%20otherwise%20the%20data%20won't%20be%20loaded%20properly.%3C%2FLI%3E%0A%3CLI%3E%3CCODE%3ErunOnce%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eis%20set%20to%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Etrue%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ebecause%20we%20don't%20want%20to%20repeat%20the%20script%20every%20time%20the%20application%20starts.%20We%20want%20to%20copy%20the%20database%20only%20the%20first%20time%20after%20the%20deployment.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH4%20id%3D%22step-4-configure-the-manifest%22%20id%3D%22toc-hId-1327639008%22%20id%3D%22toc-hId-1327639011%22%20id%3D%22toc-hId-1327639011%22%20id%3D%22toc-hId-1327639011%22%20id%3D%22toc-hId-1327639011%22%20id%3D%22toc-hId-1327639011%22%3EStep%204%3A%20configure%20the%20manifest%3C%2FH4%3E%0A%3CP%3EThe%20last%20step%20is%20to%20change%20the%20entry%20point%20of%20the%20application.%20When%20it%20starts%2C%20it%20doesn't%20have%20to%20launch%20anymore%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EMyEmployees.exe%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eexecutable%2C%20but%20the%20Package%20Support%20Framework.%20It%20will%20be%20up%20to%20it%20to%20load%20the%20required%20DLLs%20and%20then%20execute%20the%20main%20application.%20This%20is%20why%2C%20in%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Econfig.json%3C%2FCODE%3E%2C%20we%20have%20specified%20the%20main%20executable%20in%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Eexecutable%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eproperty.%20However%2C%20if%20we're%20using%20Visual%20Studio%20and%20the%20Windows%20Application%20Packaging%20Project%2C%20we%20can't%20do%20it%20directly%20in%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EPackage.appxmanifest%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efile.%20Even%20if%20we%20manually%20change%20it%20in%20the%20manifest%2C%20in%20fact%2C%20Visual%20Studio%20will%20always%20replace%20it%20with%20the%20entry%20point%20set%20in%20the%20WAP%20project%20during%20the%20MSIX%20generation.%20As%20such%2C%20we%20have%20first%20to%20generate%20the%20package%20and%20then%20make%20the%20changes.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20generate%20the%20package%2C%20you%20just%20need%20to%20follow%20the%20normal%20procedure.%20Right%20click%20on%20the%20WAP%20project%2C%20choose%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EPublish%20%E2%86%92%20Create%20app%20package%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%20follow%20the%20wizard.%20Some%20important%20notes%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%0A%3CP%3EYou%20can%20skip%20the%20package%20signing%20at%20this%20point%2C%20because%20we'll%20need%20to%20sign%20it%20again%20after%20having%20changed%20the%20manifest.%3C%2FP%3E%0A%3C%2FLI%3E%0A%3CLI%3E%0A%3CP%3EIn%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ESelect%20and%20configure%20packages%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Esection%20make%20sure%20to%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ESet%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EGenerate%20bundle%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eto%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ENever%3C%2FSTRONG%3E%2C%20since%20we%20want%20a%20plain%20MSIX%20package%3C%2FLI%3E%0A%3CLI%3EIn%20the%20configuration%20mappings%2C%20include%20only%20the%20CPU%20architecture%20which%20matches%20the%20same%20one%20you've%20used%20for%20the%20Package%20Support%20Framework.%3CBR%20%2F%3E%3CBR%20%2F%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%2F167731iD9BDA8F8CB22076D%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22PublishPackage.png%22%20title%3D%22PublishPackage.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EOnce%20you%20complete%20the%20wizard%20and%20you%20have%20a%20MSIX%20package%2C%20you%20need%20to%20edit%20it.%20The%20easiest%20way%20to%20do%20it%20is%20to%20have%20the%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%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EMSIX%20Packaging%20Tool%3C%2FA%3E%3CSPAN%3E%26nbsp%3Binstalled%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%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Efrom%20the%20Microsoft%20Store%3C%2FA%3E%3CSPAN%3E.%20Once%20you%20have%20installed%20it%2C%20you%20can%20just%20right%20click%20on%20the%20MSIX%20package%20and%20choose%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EEdit%20with%20MSIX%20Packaging%20Tool%3C%2FSTRONG%3E%3CSPAN%3E.%20As%20first%20thing%20we%20need%20to%20change%20the%20entry%20point%2C%20so%20click%20on%20the%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EOpen%20file%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3Bbutton%20under%20the%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EManifest%20file%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3Bsection.%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%20786px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F167732i930B32B991BAA7DA%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22MSIXPackagingTool.png%22%20title%3D%22MSIXPackagingTool.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20manifest%20will%20be%20opened%20in%20your%20favorite%20text%20editor%20and%20any%20change%20you're%20going%20to%20make%20will%20be%20automatically%20included%20back%20in%20the%20main%20package.%20Look%20again%20for%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EApplication%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eentry%2C%20which%20will%20look%20like%20this%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-xml%20hljs%22%3E%3CSPAN%20class%3D%22hljs-tag%22%3E%26lt%3B%3CSPAN%20class%3D%22hljs-name%22%3EApplication%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-attr%22%3EId%3C%2FSPAN%3E%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22App%22%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-attr%22%3EExecutable%3C%2FSPAN%3E%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22MyEmployees%5CMyEmployees.exe%22%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-attr%22%3EEntryPoint%3C%2FSPAN%3E%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22Windows.FullTrustApplication%22%3C%2FSPAN%3E%26gt%3B%3C%2FSPAN%3E%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EYou%20must%20replace%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EExecutable%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eattribute%20with%20the%20path%20of%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EPsfLauncher64.exe%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efile%20(or%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EPsfLauncher32.exe%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eif%20your%20application%20is%2032-bit).%20This%20is%20how%20the%20manifest%20should%20look%20like%20after%20the%20change%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-xml%20hljs%22%3E%3CSPAN%20class%3D%22hljs-tag%22%3E%26lt%3B%3CSPAN%20class%3D%22hljs-name%22%3EApplication%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-attr%22%3EId%3C%2FSPAN%3E%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22App%22%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-attr%22%3EExecutable%3C%2FSPAN%3E%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22PsfLauncher64.exe%22%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-attr%22%3EEntryPoint%3C%2FSPAN%3E%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22Windows.FullTrustApplication%22%3C%2FSPAN%3E%26gt%3B%3C%2FSPAN%3E%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ESave%20and%20close%20the%20text%20editor.%20Now%20we%20need%20to%20sign%20the%20package%2C%20otherwise%20we%20won't%20be%20able%20to%20install%20it.%20From%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ESigning%20preference%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Edropdown%20choose%20the%20option%20which%20works%20best%20for%20you.%20For%20example%2C%20if%20you're%20used%20to%20sign%20your%20MSIX%20package%20with%20a%20certificate%2C%20choose%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ESign%20with%20a%20certificate%20(.pfx)%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eoption%20and%20select%20if%20from%20your%20hard%20drive.%20Then%20provide%20the%20password%20in%20the%20new%20field%20that%20will%20appear.%20Regardless%20of%20the%20option%20you%20choose%2C%20once%20you%20have%20configured%20the%20signing%20you%20can%20generate%20an%20updated%20package%20by%20pressing%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ESave%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ebutton.%20The%20tool%20will%20propose%20you%20to%20upgrade%20the%20version%20number.%20It%20isn't%20really%20required%20in%20our%20case%20since%20we%20aren't%20creating%20an%20update%2C%20so%20feel%20free%20to%20choose%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ENo%3C%2FSTRONG%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22test-the-package%22%20id%3D%22toc-hId-1317135904%22%20id%3D%22toc-hId-1317135907%22%20id%3D%22toc-hId-1317135907%22%20id%3D%22toc-hId-1317135907%22%20id%3D%22toc-hId-1317135907%22%20id%3D%22toc-hId-1317135907%22%3ETest%20the%20package%3C%2FH3%3E%0A%3CP%3EThat's%20it!%20Now%20double%20click%20on%20the%20MSIX%20package%20you%20have%20just%20created%20with%20the%20MSIX%20Packaging%20Tool%20and%20install%20it.%20At%20the%20end%2C%20Windows%20will%20launch%20automatically%20the%20application.%20If%20everything%20went%20well%2C%20you%20should%20see%20the%20list%20of%20employees%20displayed%20in%20the%20main%20window.%20And%2C%20as%20a%20confirm%2C%20you%20should%20find%20also%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EEmployees.db%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efile%20inside%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EC%3A%5CProgramData%5CMyEmployees%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efolder.%20All%20of%20this%20without%20changing%20the%20code%20of%20the%20main%20application.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22what-about-the-appdata-folder%22%20id%3D%22toc-hId--490318559%22%20id%3D%22toc-hId--490318556%22%20id%3D%22toc-hId--490318556%22%20id%3D%22toc-hId--490318556%22%20id%3D%22toc-hId--490318556%22%20id%3D%22toc-hId--490318556%22%3EWhat%20about%20the%20AppData%20folder%3F%3C%2FH3%3E%0A%3CP%3EIn%20some%20scenarios%20the%20data%20might%20be%20stored%20in%20the%20local%20AppData%20folder.%20Can%20we%20use%20the%20same%20approach%20also%20in%20this%20scenario%3F%20The%20answer%20is%20yes!%20You%20just%20need%20to%20take%20in%20consideration%20that%20the%20AppData%20folder%20is%20virtualized%20by%20Windows%20when%20an%20application%20is%20packaged%20as%20MSIX.%20This%20means%20that%20every%20time%20the%20application%20tries%20to%20read%20or%20write%20a%20file%20from%20the%20AppData%20folder%2C%20the%20operation%20is%20redirected%20to%20the%20local%20storage%20of%20the%20application.%20This%20approach%20helps%20Windows%20to%20maintain%20a%20clean%20installation.%20When%20the%20application%20is%20uninstalled%2C%20Windows%20will%20simply%20delete%20the%20local%20storage%2C%20without%20leaving%20leftovers%20behind.%3C%2FP%3E%0A%3CP%3EThis%20means%20that%20if%20your%20application%20copies%20some%20files%20from%20the%20package%20to%20the%20AppData%20folder%2C%20the%20operation%20will%20work%20just%20fine%20but%20you%20won't%20actually%20find%20the%20files%20in%20the%20real%20AppData%20folder%20of%20the%20user%2C%20but%20you%20will%20have%20to%20look%20in%20the%20local%20folder%20of%20the%20application%2C%20which%20is%20stored%20in%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3E%25LOCALAPPDATA%25%5CPackages%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efolder.%20For%20example%2C%20in%20case%20of%20the%20MyEmployees%20applications%2C%20files%20would%20be%20copied%20in%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3E%25LOCALAPPDATA%25%5CLocal%5CPackages%5CMyEmployees_mfkd8f81tn1vy%5CLocalCache%5CLocal%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efolder.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22wrapping-up%22%20id%3D%22toc-hId-1997194274%22%20id%3D%22toc-hId-1997194277%22%20id%3D%22toc-hId-1997194277%22%20id%3D%22toc-hId-1997194277%22%20id%3D%22toc-hId-1997194277%22%20id%3D%22toc-hId-1997194277%22%3EWrapping%20up%3C%2FH3%3E%0A%3CP%3EHaving%20an%20application%20which%20comes%20with%20a%20default%20set%20of%20data%20that%20must%20be%20deployed%20to%20a%20folder%20like%20ProgramData%20or%20AppData%20is%20a%20common%20scenario.%20MSIX%2C%20out%20of%20the%20box%2C%20isn't%20able%20to%20directly%20support%20it%2C%20since%20all%20the%20files%20included%20in%20the%20package%20can%20be%20deployed%20only%20to%20a%20special%20folder%20where%20Windows%20keeps%20all%20the%20packaged%20apps.%20In%20this%20post%20we%20have%20seen%20a%20couple%20of%20options%20to%20overcome%20this%20limitation%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EIf%20we're%20talking%20about%20an%20application%20which%20is%20actively%20developed%2C%20we%20can%20just%20add%20some%20code%20to%20copy%20the%20files%20the%20first%20time%20the%20application%20launches.%3C%2FLI%3E%0A%3CLI%3EIf%20you%20don't%20have%20the%20opportunity%20to%20make%20code%20changes%2C%20either%20because%20you%20don't%20own%20it%20or%20you're%20unable%20to%20them%2C%20you%20can%20leverage%20the%20Package%20Support%20Framework%20and%20the%20recently%20added%20scripting%20support.%20Thanks%20to%20a%20PowerShell%20script%2C%20you%20can%20copy%20the%20files%20you%20need%20in%20the%20destination%20folder%20only%20the%20first%20time%20the%20application%20starts%20after%20it%20has%20been%20deployed.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EAs%20usual%2C%20you%20will%20find%20the%20sample%20used%20in%20this%20blog%20post%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2FWindows-AppConsult-Samples-DesktopBridge%2Ftree%2Fmaster%2FBlog-Scripting%2FMyEmployees%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eon%20GitHub%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3EHappy%20coding!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1133602%22%20slang%3D%22en-US%22%3E%3CP%3ELet's%20see%20how%20to%20copy%20data%20outside%20the%20installation%20folder%20as%20part%20of%20the%20deployment%20of%20an%20application%20packaged%20with%20MSIX%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1463261%22%20slang%3D%22en-US%22%3ERe%3A%20MSIX%3A%20how%20to%20copy%20data%20outside%20the%20installation%20folder%20during%20the%20deployment%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1463261%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%20for%20the%20post.%26nbsp%3B%20How%20can%20one%20edit%20an%20.appxbundle%3F%26nbsp%3B%20The%20MSIX%20Packaging%20Tool%20only%20works%20with%20msix%2C%20appx%2C%20and%20.msixbundle%2C%20correct%3F%26nbsp%3B%20Is%20the%20only%20option%20to%20repackage%20via%20CLI%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3CP%3EErnie%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1672481%22%20slang%3D%22en-US%22%3ERe%3A%20MSIX%3A%20how%20to%20copy%20data%20outside%20the%20installation%20folder%20during%20the%20deployment%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1672481%22%20slang%3D%22en-US%22%3E%3CP%3EThis%20post%20is%20great%20but%20you%20should%20really%20consider%20updating%20its%20content%20to%20better%20integrate%20with%20VS%20as%20explained%20in%20the%20linked%20(probably%20newer)%20docs%20here%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fmsix%2Fpsf%2Fpackage-support-framework-vs%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%2Fpsf%2Fpackage-support-framework-vs%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1672507%22%20slang%3D%22en-US%22%3ERe%3A%20MSIX%3A%20how%20to%20copy%20data%20outside%20the%20installation%20folder%20during%20the%20deployment%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1672507%22%20slang%3D%22en-US%22%3E%3CP%3EHello%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F431558%22%20target%3D%22_blank%22%3E%40LuKePicci%3C%2FA%3E%26nbsp%3Bthanks%20for%20the%20tip!%20I%20can%20definitely%20include%20a%20reference%20on%20the%20Visual%20Studio%20approach%20in%20the%20post.%20The%20reason%20I%20have%20focused%20on%20the%20manual%20approach%20(the%20one%20explained%20here%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fmsix%2Fpsf%2Fpackage-support-framework%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EFix%20issues%20that%20prevent%20your%20desktop%20application%20from%20running%20in%20an%20MSIX%20container%20-%20MSIX%20%7C%20Microsoft%20Docs%3C%2FA%3E)%20is%20that%2C%20typically%2C%20the%20Package%20Support%20Framework%20is%20geared%20more%20towards%20IT%20Pro%20who%20needs%20to%20repackage%20apps%20and%20they%20don't%20have%20access%20to%20the%20source%20code.%3C%2FP%3E%0A%3CP%3EIf%20you're%20a%20developer%20and%20you%20have%20access%20to%20the%20source%20code%2C%20the%20Package%20Support%20Framework%20should%20be%20used%20as%20a%20last%20option.%20The%20best%20approach%20is%20always%20to%20change%20the%20code%20to%20accomodate%20the%20requirements%20(in%20this%20case%2C%20adding%20in%20your%20app%20the%20logic%20to%20copy%20the%20files%20you%20need%20in%20the%20appropriate%20folder).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThanks%20for%20the%20feedback!%3C%2FP%3E%3C%2FLINGO-BODY%3E
Microsoft

When you deploy a MSIX package on Windows 10, all the files are copied in a special folder called C:\Program Files\WindowsApps. Each application has its own folder, which name is represented by the Package Full Name, which is composed by:

 

  • The Package Family Name (which is composed by Publisher and Name)
  • The version number
  • The target CPU architecture

For example, if you download the MSIX Packaging Tool from the Microsoft Store, it will be deployed in the folder

 

C:\Program Files\WindowsApps\Microsoft.MsixPackagingTool_1.2019.1220.0_x64__8wekyb3d8bbwe

In order to track all the files which belong to the application more efficiently, Windows doesn't allow to deploy files outside this folder. However, you might have a scenario where you actually need to do this. For example, you must copy a dependency in a system folder; or your application comes with a set of data or configuration files you need to deploy in the local AppData folder of the user.

 

To overcome this requirement, MSIX provides a feature called Virtual File System, which gives you the possibility to map the most common system folders (like C:\Windows or C:\Program Files) inside a special folder inside the package called VFS. When the application looks for a file inside these folders, Windows will redirect the call to the VFS folder and will try to see if the file is included in the Virtual File System. This feature provides two main benefits:

 

  • You get the opportunity to create truly standalone MSIX packages. Even if your application has one or more dependencies, you can bundle everything together, without asking to the user to manually install a framework or a library your application depends on.
  • It helps to minimize the problem known as DLL Hell, which happens when you have multiple applications depending on different version of the same framework. Typically this framework can be installed only system-wide, so you can't keep multiple versions of the same one on the machine. This means that, if the most recent version contains some breaking changes, your applications which depends on older versions might brake. With the Virtual File System you can include, inside the package, the specific version of the dependency you need and it won't interfere with the already installed ones.

The Virtual File System is a great way to overcome this MSIX limitation when it comes to deploy a dependency. But what about when you need to copy data or configuration files in the local AppData folder or a library like Documents? In this case, the Virtual File System can't really help since, as per the documentation, it supports mostly system folders, not user's folder (except the generic C:\ProgramData one).

 

Let's see which options we have.

 

The sample app

As a starting point, we're going to use a simple Windows Forms application, which retrieves a list of employees from a local SQLite database. The whole code is available here. The connection with the database is handled using the System.Data.SQLite library, which is an ADO.NET provider for SQLite, the popular self-contained database. When the application starts, it uses a class called SQLiteConnection to establish a connection with a local SQLIte file. Then, using a SQLiteCommand object, it performs a SELECT query on the database to retrieve the list of employees. In the end, using a SQLDataReader object, it iterates through all the resulting rows and it adds them to a BindingSource object, which is connected to a DataGrid control in the UI.

 

This is the complete code:

 

private void LoadData()
{
    string dbPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)}\\MyEmployees\\Employees.db";
    if (File.Exists(dbPath))
    {

        SQLiteConnection connection = new SQLiteConnection($"Data Source= {dbPath}");
        using (SQLiteCommand command = new SQLiteCommand(connection))
        {
            connection.Open();
            command.CommandText = "SELECT * FROM Employees";
            using (SQLiteDataReader reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    Employee employee = new Employee
                    {
                        EmployeeId = int.Parse(reader[0].ToString()),
                        FirstName = reader[1].ToString(),
                        LastName = reader[2].ToString(),
                        Email = reader[3].ToString()
                    };

                    employeeBindingSource.Add(employee);
                }
            }
        }

        dataGridView1.DataSource = employeeBindingSource;
    }
}

As you can see from the first line of the method, the application is expecting to find the SQLite database in the C:\ProgramData folder. The Environment.SpecialFolder.CommonApplicationData folder is translated with the %PROGRAMDATA% environment variable. This means that the application looks for the database in the path C:\ProgramData\MyEmployees\Employees.db. The package of the application includes a file called Employees.db, which we want to copy in this folder. Without doing this, the app would display an empty DataGrid when it starts. However, this is a task that we can't achieve directly with MSIX, since the content of the package (including our Employees.db file) will be copied only in the special folder under C:\Program Files\WindowsApps. We could use the Virtual File System, since C:\ProgramData is one of the mapped folders, but we want our database to be modifiable. If we leave it in the package folder, it would be read-only instead.

 

Option 1: copy the files when the application starts

This might seem obvious, but it's the best option if we're talking about an application which is still actively developed. When the application starts for the first time, we can just copy the file into the local C:\ProgramData folder. We can use multiple ways to detect if the it's the first launch: we can add a key in the registry; we can store the information in a configuration file; or we can simply look if the database already exists in the C:\ProgramData folder.

Here is an example of a method that we can add to our application:

 

private void CopyDatabase()
{
    string result = Assembly.GetExecutingAssembly().Location;
    int index = result.LastIndexOf("\\");
    string dbPath = $"{result.Substring(0, index)}\\Employees.db";

    string destinationPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)}\\MyEmployees\\Employees.db";
    string destinationFolder = $"{Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)}\\MyEmployees\\";

    if (!File.Exists(destinationPath))
    {
        Directory.CreateDirectory(destinationFolder);
        File.Copy(dbPath, destinationPath, true);
    }
}

First we get a reference to the Employees.db file which is included in the package folder. We use reflection since, when an application runs as packaged, the Current Working Directory is mapped with the C:\Windows\System32 or C:\Windows\SysWOW64 folder. As such, we can't simply use the Directory.GetCurrentDirectory() API to achieve this task. Once we have the path of the database file, we use the Environment.SpecialFolder.CommonApplicationData property to compose the full path of the destination folder. In this case, we want to copy the database inside the C:\ProgramData\MyEmployees folder.

 

In the end, if the Employees.db file doesn't exist in the C:\ProgramData folder, it means that it's the first execution of the app. As such, we go on and we copy the database from the package inside the destination folder.

 

That's it. Now we just need to make sure that the CopyDatabase() method we have just defined is invoked before the LoadData() one we have previously seen. This is how the event handler of the Load event of the form will look like:

 

private void Form1_Load(object sender, EventArgs e)
{
    CopyDatabase();
    LoadData();        
}

Now we can package our application with MSIX by adding a Windows Application Packaging Project to our solution. If we did everything properly, when we launch the application we will see the list of the employees in the DataGrid. And if we use File Explorer to open the C:\ProgramData\MyEmployees path, we will see the Employees.db file we have copied.

 

DatabaseFile.png

 

Option 2: copy the files with a PowerShell script

In some cases, we might not be able to change the code of our application. It might be because you aren't a developer, but you manage the deployment of applications in your enterprise and, as such, you don't have the source code; or it's a legacy app built with a very old technology and it would be risky to make any change. In this scenario, we can leverage a feature that has been recently added to the Package Support Framework: scripting support. We have already talked about this framework on this blog: it's an open source framework which provides support to fixups, which are DLLs that are able to change the behavior of your application at runtime. This way, you can solve common MSIX blockers (like apps which write to the installation folder or need to access to the current working directory) without changing the code.

 

Since a few months, the Package Support Framework has added supports to script. You can include inside your package one or more PowerShell scripts and execute them on various conditions: when the application starts or closes, only the first time after the MSIX package has been deployed or every time, etc.

 

This feature is a great fit for our scenario: we can include inside the package a script that takes care of copying the database file to the C:\ProgramData folder, without having to change the code. Let's see how to do it. We're going to use Visual Studio and the Windows Application Packaging Project since I'm a developer, but you can perform also the following steps manually, by unpacking the MSIX package, injecting the Package Support Framework and then repackaging it again. This way, you can leverage the same approach even if you aren't a developer or you don't use Visual Studio. This approach is described in the official documentation.

 

Step 1: create the PowerShell script

As first step, let's create the PowerShell script which is going to copy the database from the package to the C:\ProgramData folder. You can use any text editor, from Notepad to Visual Studio code. This is the script to copy and paste:

 

New-Item -Path $env:ProgramData -Name "MyEmployees" -ItemType "directory"
Copy-Item -Path "Employees.db" -Destination "$env:ProgramData\MyEmployees" -Recurse

First we use the New-Item command to create a new folder called MyEmployees in the C:\ProgramData path. Then we use the Copy-Item command to copy the file Employees.db to the folder we have just created.

 

Step 2: add the Package Support Framework

First we need to download the Package Support Framework, which is distributed through NuGet. However, it isn't a traditional library, so we won't have to add it to a project in Visual Studio, but we're going to download it and copy some files inside our Visual Studio solution. The easiest way to achieve this task is by using the NuGet CLI, which can be downloaded from the official website. Download the most recent Windows x86 command line version:

 

NuGet.png

 

Once you have downloaded and copied it somewhere on your computer, open a command prompt on that location and run the following command:

 

nuget install Microsoft.PackageSupportFramework

At the end of the process, you will find in the same location a folder called Microsoft.PackageSupportFramework followed by the version number of the most recent version. For example, at the moment of writing this post, the folder is called Microsoft.PackageSupportFramework.1.0.200102.1. Go inside it and move to the bin folder. We're going to copy a few files inside the Windows Application Packaging Project, by dragging them from File Explorer to the WAP project in Visual Studio. If your application is compiled for x86, copy the PsfLauncher32.exe, PsfRunDll32.exe and PsfRuntime32.dll files. If instead, it's compiled for x64, copy the PsfLauncher64.exe, PsfRunDll64.exe and PsfRuntime64.dll files. My sample on GitHub is compiled for 64 bits, so I've added the files with 64 suffix.

The next step is to include inside the package a PowerShell script, which is used by the Package Support Framework to invoke the other custom scripts you include. This file is called StartingScriptWrapper.ps1 and it's included in the bin folder as well. However, unlike for the previous files, it doesn't have to be included in the root of the package, but in the same folder which contains the main executable of the application. In some cases the two things might coincide, but you can't take it for granted. For example, in case you're using the Windows Application Packaging Project, Visual Studio will put the main application's executable and the DLLs inside a sub-folder of the package, with the same name of the application. For instance, my sample app is called MyEmployees, so the main executable and files of the application will be stored in a folder called MyEmployees inside the package. This is where we need to copy the StartingScriptWrapper.ps1 file. To achieve this goal, it's enough to manually add a folder called MyEmployees inside the Windows Application Packaging Project. It will be merged with the one generated by Visual Studio.

 

Inside this folder we have to include also the PowerShell script that we have created at Step 1. This is how the final project should look like:

 

ProjectFile.png

 

Step 3: configure the Package Support Framework

The last step is to configure the Package Support Framework. So far we have just injected the required files, but we didn't set it up. If we would create a MSIX package now out from the Windows Application Packaging Project, we won't notice any difference. The main application would simply be launched, as before.

 

To configure the framework we need to include a file inside the Windows Application Packaging Project called config.json. Then copy and paste the following content:

 

{
  "applications": [
    {
      "id": "App",
      "executable": "MyEmployees/MyEmployees.exe",
      "workingDirectory": "MyEmployees",
      "stopOnScriptError": true,
      "startScript": {
        "scriptPath": "CopyDatabase.ps1",
        "showWindow": false,
        "waitForScriptToFinish": true,
        "runOnce": true
      }
    }
  ]
}

Let's take a look at the most important settings:

 

  • id is the identifier of the application. We can find it by right clicking on the Package.appxmanifest file and choosing View code. Look for the Application entry, which will look like this:

     

    <Application Id="App"
      Executable="$targetnametoken$.exe"
      EntryPoint="$targetentrypoint$">
    

    The identifier of the application is the value of the Id attribute. If you're using a standard Windows Application Packaging Project, its default value is always App.

     

  • executable is the main executable of the application. You need to specify the full path starting from the root of the package, in my case it's MyEmployees\MyEmployees.exe.

  • In order to redirect all the file system calls to the Current Working Directory, you need to specify it through the workingDirectory property. It must be the path of the folder which contains the main executable, in my case MyEmployees.

The other settings are dedicated to configure the scripting support. These are just some settings, but in the documentation you'll find all of them.

 

  • We include the configuration of the script inside the startScript section, since we want to run it when the application starts.
  • scriptPath is the name of the PowerShell script we have created in Step 1.
  • showWindow is set to false, since we want the script to be completely transparent to the user. We want him to just see the main application starting up. However, for testing purposes, it might be helpful to keep it to true.
  • waitForScriptToFinish is set to true, since we don't want to start the MyEmployees application until the script has finished to copy the database, otherwise the data won't be loaded properly.
  • runOnce is set to true because we don't want to repeat the script every time the application starts. We want to copy the database only the first time after the deployment.

 

Step 4: configure the manifest

The last step is to change the entry point of the application. When it starts, it doesn't have to launch anymore the MyEmployees.exe executable, but the Package Support Framework. It will be up to it to load the required DLLs and then execute the main application. This is why, in the config.json, we have specified the main executable in the executable property. However, if we're using Visual Studio and the Windows Application Packaging Project, we can't do it directly in the Package.appxmanifest file. Even if we manually change it in the manifest, in fact, Visual Studio will always replace it with the entry point set in the WAP project during the MSIX generation. As such, we have first to generate the package and then make the changes.

 

To generate the package, you just need to follow the normal procedure. Right click on the WAP project, choose Publish → Create app package and follow the wizard. Some important notes:

 

  • You can skip the package signing at this point, because we'll need to sign it again after having changed the manifest.

  • In the Select and configure packages section make sure to:

    • Set Generate bundle to Never, since we want a plain MSIX package
    • In the configuration mappings, include only the CPU architecture which matches the same one you've used for the Package Support Framework.

      PublishPackage.png

 

Once you complete the wizard and you have a MSIX package, you need to edit it. The easiest way to do it is to have the MSIX Packaging Tool installed from the Microsoft Store. Once you have installed it, you can just right click on the MSIX package and choose Edit with MSIX Packaging Tool. As first thing we need to change the entry point, so click on the Open file button under the Manifest file section.

 

MSIXPackagingTool.png

 

The manifest will be opened in your favorite text editor and any change you're going to make will be automatically included back in the main package. Look again for the Application entry, which will look like this:

 

<Application Id="App" Executable="MyEmployees\MyEmployees.exe" EntryPoint="Windows.FullTrustApplication">

You must replace the Executable attribute with the path of the PsfLauncher64.exe file (or PsfLauncher32.exe if your application is 32-bit). This is how the manifest should look like after the change:

 

<Application Id="App" Executable="PsfLauncher64.exe" EntryPoint="Windows.FullTrustApplication">

Save and close the text editor. Now we need to sign the package, otherwise we won't be able to install it. From the Signing preference dropdown choose the option which works best for you. For example, if you're used to sign your MSIX package with a certificate, choose the Sign with a certificate (.pfx) option and select if from your hard drive. Then provide the password in the new field that will appear. Regardless of the option you choose, once you have configured the signing you can generate an updated package by pressing the Save button. The tool will propose you to upgrade the version number. It isn't really required in our case since we aren't creating an update, so feel free to choose No.

 

Test the package

That's it! Now double click on the MSIX package you have just created with the MSIX Packaging Tool and install it. At the end, Windows will launch automatically the application. If everything went well, you should see the list of employees displayed in the main window. And, as a confirm, you should find also the Employees.db file inside the C:\ProgramData\MyEmployees folder. All of this without changing the code of the main application.

 

What about the AppData folder?

In some scenarios the data might be stored in the local AppData folder. Can we use the same approach also in this scenario? The answer is yes! You just need to take in consideration that the AppData folder is virtualized by Windows when an application is packaged as MSIX. This means that every time the application tries to read or write a file from the AppData folder, the operation is redirected to the local storage of the application. This approach helps Windows to maintain a clean installation. When the application is uninstalled, Windows will simply delete the local storage, without leaving leftovers behind.

This means that if your application copies some files from the package to the AppData folder, the operation will work just fine but you won't actually find the files in the real AppData folder of the user, but you will have to look in the local folder of the application, which is stored in the %LOCALAPPDATA%\Packages folder. For example, in case of the MyEmployees applications, files would be copied in the %LOCALAPPDATA%\Local\Packages\MyEmployees_mfkd8f81tn1vy\LocalCache\Local folder.

 

Wrapping up

Having an application which comes with a default set of data that must be deployed to a folder like ProgramData or AppData is a common scenario. MSIX, out of the box, isn't able to directly support it, since all the files included in the package can be deployed only to a special folder where Windows keeps all the packaged apps. In this post we have seen a couple of options to overcome this limitation:

 

  • If we're talking about an application which is actively developed, we can just add some code to copy the files the first time the application launches.
  • If you don't have the opportunity to make code changes, either because you don't own it or you're unable to them, you can leverage the Package Support Framework and the recently added scripting support. Thanks to a PowerShell script, you can copy the files you need in the destination folder only the first time the application starts after it has been deployed.

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

Happy coding!

3 Comments
Senior Member

Thanks for the post.  How can one edit an .appxbundle?  The MSIX Packaging Tool only works with msix, appx, and .msixbundle, correct?  Is the only option to repackage via CLI?

 

Thanks

Ernie

Contributor

This post is great but you should really consider updating its content to better integrate with VS as explained in the linked (probably newer) docs here: https://docs.microsoft.com/en-us/windows/msix/psf/package-support-framework-vs

Microsoft

Hello @LuKePicci thanks for the tip! I can definitely include a reference on the Visual Studio approach in the post. The reason I have focused on the manual approach (the one explained here: Fix issues that prevent your desktop application from running in an MSIX container - MSIX | Microsof...) is that, typically, the Package Support Framework is geared more towards IT Pro who needs to repackage apps and they don't have access to the source code.

If you're a developer and you have access to the source code, the Package Support Framework should be used as a last option. The best approach is always to change the code to accomodate the requirements (in this case, adding in your app the logic to copy the files you need in the appropriate folder).

 

Thanks for the feedback!