Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VS2019 Customise/override Typescript .exe location (using msbuild?). #41355

Closed
Griffork opened this issue Nov 1, 2020 · 9 comments
Closed

VS2019 Customise/override Typescript .exe location (using msbuild?). #41355

Griffork opened this issue Nov 1, 2020 · 9 comments
Assignees
Labels
Visual Studio Integration with Visual Studio

Comments

@Griffork
Copy link

Griffork commented Nov 1, 2020

Microsoft.NodejsTools.targets, Microsoft.NodejsToolsV2.targets, msbuild, VS2019, Ttypescript, Typescript, node_modules.

Suggestion

So I just switched over to using Visual Studio 2019 (from 2017) and found that creating a new Typescript web project uses Microsoft.NodejsToolsV2.targets instead of Microsoft.NodejsTools.targets which requires using a Typescript install in node_modules instead of the built-in SDK. This got me excited because I thought I'd be able to overwrite a variable to point to the custom wrapper for tsc that I'm using (ttypescript), but unfortunately not the case.

Currently it is possible to switch the build & clean version of tsc over to a custom location by creating your own .targets file and c# script to run tsc with the provided configuration and providing all the settings as appropriate (as I have done), however the tsc used by CompileOnSave is hardcoded into the SDK, and cannot be changed using msbuild. So I've lost all compile on save support (if I turn CompileOnSave on my output is overwritten by javascript that doesn't run).

So I'm requesting the ability to specify explicitly where tsc is located, so that I can use a custom wrapper instead of the default tsc in VS2019. I'm perfectly fine for this to be only available within msbuild or the project properties.

Use Cases

This will allow me to use the experimental typescript transforms prior to the official implementation within vs 2019 across my projects while still being able to use compile-on-save.

Examples

I don't know what to put here aside from what I've already said.

Checklist

My suggestion meets these guidelines:

  • [y] This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • [y] This wouldn't change the runtime behavior of existing JavaScript code
  • [y] This could be implemented without emitting different JS based on the types of the expressions
  • [y] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • [?] This feature would agree with the rest of TypeScript's Design Goals.

Final note:

Whenever I raise these issues people tell me to switch to VS code. Please don't. I'm too dependant on the VS->Azure workflow to make the switch.

@DanielRosenwasser
Copy link
Member

@minestarks
Copy link
Member

I think there are a couple of points of confusion to clear up here.

  • Compile On Save in Visual Studio actually uses tsserver.js, not tsc.js - so unless you have a custom wrapper for tsserver too, it's not going to be possible to wire up your custom bits to Compile On Save
  • Sounds like you've succesfully hacked/modified the MSBuild files to pick up a custom compiler. But (except in a few supported scenarios) the contents of MSBuild project don't matter to how VS locates tsserver. If you do have a custom tsserver.js, you can use this unsupported registry key to point VS to it.

From the VS developer command prompt:

CD "%VSINSTALLDIR%"
vsregedit set . HKLM TypeScriptLanguageService CustomTSServerLocation string "full_path_to_my_custom_tsserver.js"

I'm going to re-emphasize that this setting is unsupported and its behavior may change in future versions of VS - but then so is using a custom tsc wrapper 🙂

@Griffork
Copy link
Author

Griffork commented Nov 11, 2020

Thanks for the quick reply, that was a lot faster than I was expecting. I do in fact have a custom tsserver..js! (I'm using ttypescript which generates both)

It's not clear from the key itself, but I'm guessing that changing that value changes the tsserver used for all projects?
I have two solutions on the same PC which I'm actively working on and only one of them uses the changed tsc. Is there a way for me to change the tsserver for only that solution?

Edit: To clarify I work on the two solutions separately. I'd want the custom tsserver to be used for all projects in a single visual studio instance, and a normal tsserver for another instance. I do not want them running side-by-side I just don't want to have to continually edit the registry to switch between them.

If the registry edit just adds another entry to the project's TypeScript version drop-down (in project settings) that would be the most perfect.

@Griffork
Copy link
Author

@minestarks any chance on getting some clarification on this?

@DanielRosenwasser
Copy link
Member

I would just try it, but I'm pretty sure you should be able to lock yourself to a specific TS version at a project-level granularity. https://github.com/Microsoft/TypeScript/wiki/Updating-TypeScript-in-Visual-Studio-2017

@Griffork
Copy link
Author

Griffork commented Nov 17, 2020

@DanielRosenwasser the question was does using the custom registry key override all typescript versions, just one of them or create a new entry?

Your link seems to be about changing typescript versions in general (with different SDKs) which is exactly what I was talking about in the last sentance of my last post. I'm already aware that drop-down exists I just wanted to confirm that the registry key would work with that drop-down rather than clobber it.

I don't like editing my registry on a whim, so I'd prefer to know in advance whether or not I can use it, particularly since I use this machine for work on a project that doesn't have an altered compiler, so it's pretty important that I know that that's not going to break.

@DanielRosenwasser
Copy link
Member

The reg key should be removable if it doesn't work but I won't pressure you into changing it if you're not comfortable with that.

I'm not sure, @PranavSenthilnathan or @minestarks may be able to answer this.

@jessetrinity
Copy link
Contributor

jessetrinity commented Nov 17, 2020

Setting the key clobbers. I think you can also set the CustomTSServerLocation in the command line before launching VS a la https://github.com/microsoft/JSTSdocs/blob/master/articles/troubleshooting/index.md.

Since you have your own custom tsserver though, you should be able to create your own "SDK version". Below is what I just tried and I would normally not recommend doing this, but since you have a custom tsserver I don't think I can stop you:

  1. Back up your existing TypeScript SDK folders in C:\Program Files (x86)\Microsoft SDKs\TypeScript.
  2. copy your latest SDK folder, probably 4.1.
  3. Rename the copy to something ludicrous that is not likely to collide with an actual TS version anytime soon, say 6.6.
  4. Copy your tsserver files into the 6.6 folder. I don't know what ttypescript does, but if you're working with the TypeScript repo you can just copy the contents of typescript\built\local.
  5. Open a project in VS and you should see a 6.6 version when you select the version for your project. You're likely to see something break like localization, but I do see the right node process starting on my machine.

I would really like to add a menu to VS that just lets you restart the server, select version, etc...

@Griffork
Copy link
Author

Griffork commented Nov 20, 2020

Ooooh! Thank you @jessetrinity for the answer and the workarounds. I'd love to see a menu like that too, but making a custom SDK works too.

Could I name it 0.1 since 0.8 was the first public build, so it shouldn't be able to ever conflict?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Visual Studio Integration with Visual Studio
Projects
None yet
Development

No branches or pull requests

5 participants