Skip to content

Latest commit

 

History

History
56 lines (42 loc) · 2.61 KB

UsingCS.md

File metadata and controls

56 lines (42 loc) · 2.61 KB

Using C# projects

Installing the required tools

  • install the CSUnits package, which provides project template for C# unit of measurement library:

    dotnet new install Mangh.Metrology.CSUnits

Creating a project

  1. 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.

  2. (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.
  3. 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 for Aliases.inc file that might be used to import unit and scale types in dependent projects,
      • Report.xslt: template for generator_report.txt file (a summary of generated units and scales).
  4. (optional) Modify the Directory.Build.targets file so that the generated Aliases.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.

  5. (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.

  6. Compile the project to create the library:

    dotnet build