-
install the CSUnits package, which provides project template for C# unit of measurement library:
dotnet new install Mangh.Metrology.CSUnits
-
Create a project
<PROJECT_NAME>
in<PROJECT_FOLDER>
for units of measurement in namespace<PROJECT_NAMESPACE>
:dotnet new csunits -n <PROJECT_NAME> -o <PROJECT_FOLDER> -ns <PROJECT_NAMESPACE>
For more information on the folders and files created with this command, see the "C# project" page.
-
(optional) To continue under Visual Studio IDE, attach the project to a Visual Studio solution:
- open Visual Studio IDE,
- create a new or select an existing solution,
- right click the solution root folder (or a solution subfolder),
- perform:
Add
->Existing Project...
, - select the project created above.
-
Go to the
./Templates
folder:- edit
Definitions.txt
to specify units of measurement for your solution(s), - (optional) customize XSLT templates:
Unit.xslt
: template for a single unit (struct),Scale.xslt
: template for a single scale (struct),Catalog.xslt
: template for the Catalog class (catalog of all defined units and scales),Aliases.xslt
: template forAliases.inc
file that might be used to import unit and scale types in dependent projects,Report.xslt
: template forgenerator_report.txt
file (a summary of generated units and scales).
- edit
-
(optional) Modify the
Directory.Build.targets
file so that the generatedAliases.inc
file is (automatically) exported to all dependent projects (those that require units of measurement). See: Demo/UnitsOfMeasurement or CALINE3/Metrology projects for an example. You can safely delete the file if you are not going to use it. -
(optional) Modify the
Math.cs
source file to provide the additional math required to handle the units. See: Demo/UnitsOfMeasurement or CALINE3/Metrology projects for an example. You can safely delete the file if you are not going to use it. -
Compile the project to create the library:
dotnet build