XmlNotepad Development#
You can build and test XML Notepad using Visual Studio 2022. It uses .NET frameworks, so be sure to install the ".NET desktop development" feature when using the Visual Studio Installer. XML Notepad targets .NET Framework version 4.8.
Coding Guidelines#
XmlNotepad follows the standard C# Coding Guidelines with the default C# formatting settings that ship with VS 2022.
The following additional conventions are also followed:
- All if/else statements use curly brackets.
- Add private/internal/public access explicitly on all members.
- Do not use "s_" prefix on statics, instead use Class name qualification.
- All private fields prefixed with
_
except for WinForms generated code. - Accessing fields with
this.
is ok, do not stripthis.
prefix if used. - Constants are PascalCased even if they are private to a class.
- Try and collect all private fields at the top of the class.
- Public fields are PascalCased like public properties and methods.
- Generally one class per file, unless there is a super natural family of classes, like Commands.cs, that would cause an unnecessary explosion in number of files.
- Nice to have blank line between methods.
- Use "Remove and Sort Usings" command in VS.
Build the code#
First clone the repo:
git clone https://github.com/microsoft/XmlNotepad.git
From the command line initialize your ApiKey.cs file:
echo namespace XmlNotepad { public partial class AppAnalytics { private const string ApiKey="%XMLNOTEPAD_ANALYTICSKEY%"; } } > src\model\ApiKey.cs
Then restore all the nuget packages
nuget restore xmlnotepad.sln
Then you can build it:
msbuild xmlnotepad.sln
Using Visual Studio:
- Load
src/XmlNotepad.sln
into Visual Studio. - Select Debug or Release and target "Any CPU".
- Run Rebuild Solution (rebuild also installs any missing nuget packages)
Debug the app#
- Right click the
Application
project and selectSet as Startup Project
. - Select Debug configuration.
- Press F5 to start debugging.
Test the app#
After building the app:
- Right click the
UnitTests
project and selectRun tests
.
This is a GUI test, so do not move your mouse or type on your keyboard or let your screen lock until this test is completed. Total test run time is about 12 minutes.
The tests all pass on Windows 10, but currently some tests fail on Windows 11, there seems to be some breaking changes in the Windows Automation layer that XML Notepad tests are using. This is being investigated.
Note: bug 10244 is still open in in .net 4.8
System.Windows.Automation of menu items that blocks the tests, so checkout the branch clovett/net472
to run the unit
tests.
UpdateVersions#
The UpdateVersions
project synchronizes the Version.props
information across multiple places so you can edit the
version number in Version.props
and this tool will replicate that across the following:
- The
Version.cs
file which sets the assembly version for all projects in the solution. - The WIX based setup file
Product.wxs
. - The windows package manifest file
Package.appxmanifest
. - The updates.xml file.
- The readme.htm file.
You will also have to restart Visual Studio so that the new versions are picked up by the ClickOnce deployment
information in Application.csproj
.
Publish the app and all setups#
The publish.cmd
script runs UpdateVersions, builds Release bits, builds the ClickOnce installer and the winget.msix
installer from XmlNotepadPackage
, and the standalone .msi installer from XmlNotepadSetup
, it zips these files so
they can be available on the Github Release page then it creates the new github release for the current version. It also
signs the assemblies and installers using the signing certificate specified by the environment variable MYKEYFILE
.
The ClickOnce installed is uploaded to lovettsoftware using the environment variable LOVETTSOFTWARE_STORAGE_CONNECTION_STRING. Click once is convenient because it provides auto-updating whenever a new version is published.
Build the setup .msi installer#
After building the Release
configuration of XmlNotepad.sln
load the XmlNotepadSetup.sln
. This solution uses the
WIX Toolset to build a standalone windows .msi installer. To build that setup you will need
to install the WIX toolset then the Wix Toolset Visual Studio 2022
Extension.
Then right click the XmlNotepadSetup
project and select "build". This will produce an .msi installer in the
XmlNotepadSetup\bin\release folder. There is also a sign.cmd
script invoked by this build that will try and sign the
resulting .msi using the certificate installed by the author. This step will only work for the author who owns the
certificate.
This msi
installer gives folks the option to install XML Notepad on machines that are isolated from the internet and
there are quite a few customers who have requested this, which is why it exists.
Build the winget setup package#
The winget
setup package is built by the XmlNotepadPackage
project in the XmlNotepadSetup.sln
solution. Right
click this project in the Solution Explorer and select Publish
and Create App Packages
. Choose Sideloading, and the
package files will be written to the XmlNotepadPackage\AppPackages folder. These can then be uploaded to the server
hosting these packages and you can then update the manifest in
winget-pkgs.
This package provides the winget install xmlnotepad
setup option.
Publishing the bits to Azure Blob Store#
The publish.cmd
script uses the
AzurePublishClickOnce tool which uses the
environment variable named LOVETTSOFTWARE_STORAGE_CONNECTION_STRING
to access the Azure storage account where it
uploads the new clickonce installer, and removes the older versions so that the storage account does not keep growing
and growing.
Design#
See XML Notepad Design for more detailed information about how this application is designed.
Issues#
Feedback and suggestions are welcome, just use the GitHub issues list. Pull requests are also welcome, in fact, a number of good pull requests have already been merged. Thanks to all who are helping to make XML Notepad a great tool!