-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Visual Studio 2017 Compile on Save only compiles the current file #18222
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
Comments
looks like another report of #18130 |
There's currently a more detailed discussion about this issue here: https://developercommunity.visualstudio.com/content/problem/97205/broken-typescript-compileonsave-build-tooling-for.html Essentially, VS 2017 should probably do a full build of the project when save is invoked for the first time, and incremental builds on saves thereafter. I'm not 100% sure of the ramifications of doing so, we might have rejected it for perf reasons in the past. The fix could be in tsserver or VS depending on how you look at it. |
Here is a summary of the answers to questions that @minestarks asked: Our solution has several individual applications that transpile many TypeScript files into single JavaScript files, and the ES5 JavaScript output files are stored in TFS (multiple tsconfig.json files). However, we also have 2 large applications (with their own tsconfig.json files) that consist of over 30 TypeScript files each. They need to be transpiled into transient output files, fed into WebPack, and the ES5 JavaScript output from WebPack is stored in TFS. The transient output files are not stored in TFS. Also, unlike VS2015, VS2017 is failing to check-out the output file prior to attempting to write to it, causing the output to silently fail. We have disabled the TypeScript compile-on-build ability via .csproj entries, as we never want any TypeScript code to build during a solution/project build. Only developers who are actually making changes to the TypeScript code will update the JavaScript output files. The developers that don't change the TypeScript files, use the previously transpiled JavaScript files that are in TFS, which later get deployed and published to production. |
I'm not sure if this is related to my problem or not. If not, I will raise a separate issue. We have a number of TypeScript files inside C# projects, and use the "Compile Files Not Part of a Project" setting to compile them into AMD modules (ECMAScript 5 level). In the latest Visual Studio 2017 some files are not being compiled on save (can't see any pattern in this). The files that are being compiled are generating wildly different code from VS2015 which is not valid JavaScript (or at least, cannot be loaded by
becomes
which fails to load at runtime (via requirejs 2.1.8) since |
@john-cullen this sounds like an unrelated issue.
So if I understand you correctly, the TypeScript files are part of the project? In that case, the "compile files not part of a project" setting may not apply. You may want to go into project properties -> TypeScript Build and select AMD as the module kind. Alternatively, if you're using a tsconfig.json, make sure the module kind is specified there, or if you're using MSBuild, you can use the TypeScriptModuleKind property. The generated code in your example is valid JavaScript, it's just generating CommonJS modules, not AMD.
If this persists, please file a feedback item through Visual Studio -> Help -> Report a Problem. Thanks for reporting! |
@minestarks hi, sorry I was unclear. The typescript files we have are not part of a typescript project, they are in class library projects so there is no TypeScript Build settings in the Project itself. We aren't using a tsconfig either. The project works as expected without modification in VS 2015. |
@minestarks Is there any update on the status of this? I see that 15.4 was released today, and that it is not in the release. Thanks |
I am having the same issue in 15.4.5 :( Only way to compile ts files is to build the whole project. Have tried with and without a tsconfig.json file and the '"compileOnSave" : true' option set. Restarting the IDE doesn't help either. |
Changing from Bug to Suggestion, per the conversation at https://developercommunity.visualstudio.com/content/problem/97205/broken-typescript-compileonsave-build-tooling-for.html. |
@Kaelum It sounds like you could get what you want by just building the project once when you open it. That build should be incremental (if not now, then in an upcoming release, because we've made improvements here) and, thereafter, compile-on-safe should re-emit all files depending on the saved one. Conceivably, we could have compile-on-save re-emit all files the first time it is invoked, but that would add to the startup cost and probably do redundant work in cases where the files happened to already have been emitted (e.g. during a previous VS session). |
@Kaelum I think you mentioned that you might also be having source control issues. If that's the case, can you please file a separate issue for them? |
@SimonSDA I'm not sure I understand what problem you're seeing. What gets emitted when you save? Nothing? Just the file you saved? |
@amcasey Building is not an option. As was previously discussed with @minestarks, we don't allow the build process to compile TypeScript, and it is disabled via the .csproj setting. CompileOnSave MUST work exactly as it does in Visual Studio 2015. This is why we agreed that Visual Studio 2017 MUST work exactly like TSC.exe -w does. |
@Kaelum I'm not sure I understand why the TS files are in the same project as the other files if their builds are mutually exclusive. Would it make sense to separate them into their own project? |
@amcasey no it does not. The TS files are compiled down to JavaScript, which are marked as Content, stored in source control, and published as a part of the web application. The TS files are basically stored in 2 different locations, and none of them are marked as Content:
This is not going to change, as it works extremely well for us. Only those who are allowed to write TS, are also allowed to compile it and update the JavaScript files. They check-out the JavaScript files that will be updated (this used to be automatic under previous VS versions), make their changes to the TS files, CompileOnSave, and when done, they check in both the TS and JavaScript files. Everyone who is just consuming the JavaScript output from TS does not need to have TS installed on their systems, nor do our build servers. It just works for them, and that is exactly what we want. Putting the TS files in a separate project would make this extremely difficult to use, and won't be considered. I don't understand why anyone would remove this functionality from Visual Studio, when it has been there for years. That is beyond boggling to me. Can you explain that? |
@Kaelum I'm glad you've found a setup that works for you. I think another way to set it up might have been to separate the files that you don't want non-TS devs to touch into their own project, configured to output to the same place they're outputting now. However, I understand that changing your project layout is not an option. Between VS 2015 and VS 2017, the JS/TS language service (i.e. editor integration) was re-architected. The new design improved consistency between VS and other editors (especially VS Code) and lit up new features (as well as improving our ability to add still more features). However, not everything operates exactly as it used to. Compile-on-Save is one thing that changed. It's a feature that has to achieve a delicate balance between performance and convenience. Some users, for example, find that it triggers too much work, affecting responsiveness. https://developercommunity.visualstudio.com/content/problem/10762/typescript-background-compilation-too-often-causes.html At the moment, I don't think we have enough evidence to swing the pendulum back towards doing a larger build at the expense of degraded performance. We would, however, be happy to work with you (offline, if you prefer) to find a tailored mitigation for your scenario. |
@amcasey neither of those issues apply. There are basically only 2 people writing TS code at this time, myself, and one other person. The code that I've been writing is used throughout the entire site, uses the The other developer has written 2 ReactJS applications that are only used by 2 views, and share about 80% of their code between the applications. These ReactJS TS code applications use |
@Kaelum, sorry, I didn't mean to suggest that those DeveloperCommunity users were on the opposite side of the same issue - merely that compiling more files on save would have negative consequences for some users. Do I understand correctly that your own code is arranged in such a way that compile-on-save works for you in both VS 2015 and VS 2017 and that only this other developer is still having problems with VS 2017? Or are you both having problems? If only 1-2 developers are affected, could you use a .csproj.user (or other project flavor) file on your individual boxes to specify that you do want to build TS files? These files would not be checked in to source control and the other developers would continue to skip the TS build. |
@amcasey anyone who attempts to work on the 2 ReactJS TS applications, has the problem, which is why @minestarks and I agreed that the only fix is to use TSC.exe -w, or replicate the exact same functionality within Visual Studio. To be honest, I don't know why you don't just allow the developer to chose either the Visual Studio way, or the TSC.exe -w way. Since the TS compiling options are now defined in the project file itself, why not add a switch and let the programmers decide? Is there a reason why Visual Studio 2017 can't kick off TSC.exe -w in a background process? I thought that that was whole reason Visual Studio 2017 took a complete left turn. EDIT: Perhaps even add it to the Task Runner? |
To clarify, while I think the specific request "do a full build on first save" is worth considering, I don't necessarily think we should implement it. The main drawback is negative perf consequences for large projects, which is something that impacts a lot of other users. |
@minestarks is there a reason that there isn't a Microsoft managed extension for TSC.exe to run in the Task Runner Explorer? If there was, this would be a non-issue, as long as we can completely turn off the built-in functionality of Visual Studio 2017. We already use the Task Runner Explorer for WebPack and other Mads Kristensen extensions. |
A couple of points after reading through this.
Effectively, sounds like you want incremental build (which ensures the project is up to date), not compile-on-save (which ensures code is generated for the file just saved). We have just completed adding incremental build (shipping shortly), but as the name would imply, this depends on a build, which you have disabled, so that won't help here. Two thoughts that come to mind for your specific scenario:
Bottom line is compile-on-save is not intended to ensure your entire project emit is up to date, we have incremental build for that now, but that depends on having a build. You can mimic this outside of a VS build by using "tsc -w" or WebPack at the command-line, both of which can be launched by Task Runner Explorer as outlined above. |
@billti sorry for the late reply, but it's been a little busy with our current release, and I wasn't sure how your response would go with the VP of my department, the other TypeScript coder. I informed everyone of your stance today, and left it to them whether or not they want to escalate this. For now, we'll just deal with the issues forced upon us. Here are the answers to your questions: Check-in/out: I was only referring to files managed by Visual Studio (my code), not the files managed by WebPack (the other code), as my code outputs directly to files that are a part of the project and checked into source control.
I both agree and disagree with some of your points, where I disagree is in the implementation, as there needs to be something to satisfy the issue presented. I do agree that for the code in question, that we could have possibly done things better, which may have completely eliminated the issue for us, but I have no options when the VP of my department says that this is how we are doing it. |
We suggest looking into incremental build (TS 3.4) as an alternative here - closing as Working as Intended. |
Windows 10 Version 1607
Microsoft Visual Studio Enterprise 2017
Version 15.3.3
TypeScript Version: 2.4.1 Release
Using the exact same solution (see example below) under VS2015 and VS2017, which uses "compileOnSave", VS2017 is not building any of the files listed under the "include" folders, when saving the single file listed in the "files" section. The only output is for that one file, when the file is saved. It is now also only outputting the single file being saved that is a part of the "include" section, Previously, it was building all of the files in that folder.
Can we get back the normal functionality of TSC.exe (watch), which was available in VS2015? This currently functionality is basically useless. Also, if the output files are checked-in to source control, VS2017 is not automatically checking them out like VS2015 does, which is another piece that has been broken.
Sample Project: https://developercommunity.visualstudio.com/storage/attachments/10591-typescriptbug.zip
Steps to reproduce the issue:
VS2017 is not using TypeScript correctly.
The text was updated successfully, but these errors were encountered: