Reputation: 241
I've a few existing Asp.Net Core 2 class library projects. Now I want to enable TypeScript compilation in them so I can add the generated js files as resources to the library. (The js is for Cosmos db server side scripts, not for web app).
I've added the package.json and tsconfig.json files but VS 2017 is ignoring them as regards the right click and "Package Install" option does not appear.
I can create a separate empty Asp.Net Core web app to get the typescript compiling working but then I have the problem of sharing the js files with my class library.
Any ideas?
Upvotes: 0
Views: 1179
Reputation: 241
I made some progress on this (I think).
I changed the project element from
<Project Sdk="Microsoft.NET.Sdk">
to
<Project Sdk="Microsoft.NET.Sdk.Web">
I then had to change the output type back to class library. And then had to set make sure there was TypeScriptCompile elements for each of the typescript files in the project.
<ItemGroup>
<None Remove="Scripts\spSampleForTest001.ts" />
</ItemGroup>
<ItemGroup>
<TypeScriptCompile Include="Scripts\spSampleForTest001.ts" />
</ItemGroup>
Its working but I'm not 100% confident in it.
Setting Sdk="Microsoft.NET.Sdk.Web" seems to be key.
Upvotes: 0
Reputation: 535
I believe its not possible out of the box. You may find some workarounds at: https://github.com/Microsoft/TypeScript/issues/11
You could also use some compilers like babel with js-runners or build tools like webpack.
Similar question: How to get Visual Studio 2017 to compile TypeScript on build in class library project (new .net core style .csproj)
Upvotes: 1