1

I have a solution in VS2017 which DOES compile the TS files in the web project (.net core 2.0) but not in the test project (.net core 2.0).

Is that by design?

I can't find any setting that says in the webproject 'autocompile the TS files' (does VS2017 compile TS files out-of-the-box?), so I can't check whether that setting is on or off on the testproject.

EDIT I did find that the web project has a tab 'typescript build' in the properties of the project, and the test project has not. So I guess this means that the testproject is not intended for typescript building; however, can it made to be like it?

I don't want to change my testproject to webproject I guess, just to make it compile TypeScript files.

2
  • See typescriptlang.org/docs/handbook/… Commented Mar 4, 2018 at 9:53
  • I'm honestly unsure about your particular question... Thought I would comment saying that I have been using Task Runner Explorer to trigger webpack compiling of my typescript files and that works a treat. Commented Mar 4, 2018 at 9:54

1 Answer 1

2
+200

Compilation is directed by what target files are imported into your project. If you open your web project file (open the .csproj as xml) you will see the sdk used is Microsoft.NET.Sdk.Web, while for a unit test project the sdk is Microsoft.NET.Sdk. These SDKs point to folders in c:\Program Files\dotnet\sdk\2.1.4\Sdks\ (or equivalent depending on your setup) that will be used for default imports into your project.

If we dig around a bit into what is included for Microsoft.NET.Sdk.Web that is related to Typescript, we find the following:

<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" Condition="Exists('$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets') AND '$(EnableTypeScriptNuGetTarget)' != 'true'" />

<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.DotNetCore.targets" Condition="Exists('$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.DotNetCore.targets') AND '$(EnableTypeScriptNuGetTarget)' != 'true'" />

<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props" Condition="Exists('$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props')" />

If we add these lines inside the Project tag in our unit test project file (.csproj) we will include the necessary build steps for Typescript. You will also get the Typescript property page in your project.

Note I have not tested this extensively but it appears to work, if you have any problems, let me know.

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

Comments

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.