-
Notifications
You must be signed in to change notification settings - Fork 2
Home
nTsMapper is a command line application that processes a .NET assembly for classes used in ApiController methods as either parameters or were included in ResponseType attributes and generates corresponding TypeScript code. nTsMapper will produce both interfaces and concrete implementations for all the source classes found in the provided .NET assembly.
A nuget package is available at https://www.nuget.org/packages/nTsMapper. Currently, adding a reference to the nuget package will download the nTsMapper executable and make it available for use. Unfortunately, this means integrating it with your application is still a manual process.
The simplest way to get nTsMapper integrated with your application is to create a before build step in the project where you intend to consume the generated TypeScript. For example:
<Target Name="BeforeBuild" Inputs="$(ProjectDir)..\WebAPI\bin\WebApi.dll" Outputs="$(ProjectDir)Api\WebApi.Server.ts">
<Message Text="Running nTsMapper to create WebApi.Server.ts file." />
<Exec Command="$(ProjectDir)..\Packages\nTsMapper.1.0.5969.26876\lib\net45\nTsMapper.exe -assemblyPath "$(ProjectDir)..\WebApi\bin\WebApi.dll" -outputfilename "$(ProjectDir)Api\WebApi.Server.ts"" />
</Target>In this example the WebUI project will need to have a dependency on the WebAPI project so that WebAPI will be built first. Additionally, the WebUI project shoudl be configured to compile TypeScript files to JavaScript files and the \Api\WebApi.Server.js file will need to be included client side in accordance with your established patterns.
In the example above the path in the before build target is hard coded to the path of nTsMapper package, which includes a version number. Upgrading to newer versions of nTsMapper will require you to make some manual adjustments to the before build target.