0

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?

2 Answers 2

1

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)

Sign up to request clarification or add additional context in comments.

Comments

0

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.

1 Comment

I encountered VS/MSBuild problems with this that require some changes to the csproj file - see github.com/Microsoft/msbuild/issues/3271#issuecomment-386662451

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.