Commandline app to convert CSharp data models into Typescript. It loads and converts the models in runtime, which allows for multi-platform integration and usage on CI/CD pipelines.
This package is still on experimental phase. It is being used in some internal projects in production but has it has some limitations (this is not an exhaustive list):
- Can not load WEB.SDK assemblies (you should have a plain CLR assembly to use it).
- Some complex types like Lists of Generic Lists will not work.
- Go to https://github.com/engthiago/Onbox.TypeSharp/releases and downlaod the latest version
- Unzip the contents
- cd into the folder
- Execute commands against .\TypeSharp.exe as shown on example sections below
-s or --source
Required
The full path name of the folder to be converted and/or to be watched. Sub diretories will also be considered. This path is not case sensitive. Relative paths work.
-f or --file-filter
Required
Filters the assemblies (just pure assembly names not full name) to be converted. This filter is not case sensitive.
-t or --type-filter
Optional
Filters the types (fully qualified names) to be converted. This filter is not case sensitive. Notice that if another model depends on ignored ones, they will still be converted.
-d or --destination
Required
The full path name of the folder where the Typescript files will be saved. Relative paths work.
-w or --watch
Optional
Tells the app to watch the destination folder and re-run everytime something changes.
-m or --export-module
Optional
Creates an exports module file containing all converted models.
Converts all the types from one assembly and dumps them into a models folder on the desktop:
.\TypeSharp.exe --source "C:\repos\Onbox.TypeSharp\samples\SampleModels\bin\Debug\netstandard2.0" --file-filter "SampleModels.dll" --destination "C:\Users\MyUser\Desktop\Models"
Converts all the types from all assemblies in a folder and dump them into a models folder on the desktop:
.\TypeSharp.exe --source "C:\repos\Onbox.TypeSharp\samples\SampleModels\bin\Debug\netstandard2.0" --file-filter "*.dll" --destination "C:\Users\MyUser\Desktop\Models"
Converts only types that contains Web.Models on their fully qualified names from one assembly and dumps them into a models folder on the desktop:
.\TypeSharp.exe --source "C:\repos\Onbox.TypeSharp\samples\SampleModels\bin\Debug\netstandard2.0" --file-filter "*.dll" --type-filter "Web.Models" --destination "C:\Users\MyUser\Desktop\Models"
Watches a assembly so everytime it changes, converts all the types and dumps them into a models folder on the desktop:
.\TypeSharp.exe --source "C:\repos\Onbox.TypeSharp\samples\SampleModels\bin\Debug\netstandard2.0" --file-filter "*.dll" --type-filter "Web.Models" --destination "C:\Users\MyUser\Desktop\Models" --watch
Msbuild Target for running TypeSharp after build. You could add multiple runs of TypeSharp by adding more tags:
<Project>
<Target Name="TypeSharp" AfterTargets="CoreBuild">
<Exec Command="..\..\typesharp\TypeSharp.exe --source bin\$(Configuration) --file-filter Web.Models.dll --destination ..\angular-app\src\dtos" />
</Target>
</Project>
- Doesn't depend o Visual Studio
- .Net5 based, so it runs wherever dotnet runs
- Can be incorporated into MSBuild
- Can be incorporated into CI pipelines
- Lightweight
- Can watch assemblies for changes
- Can not load runtime dependencies like Microsoft.AspNetCore.Mvc, so it can not run against ASP.NetCore assemblies
All runtime dependencies are already packaged when installed. Not even .Net5 is needed, since everything is bundled in the exe.