-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Visual Studio "No Compile" option #2294
Comments
Hi, just a few days ago I submitted issue #2252 that's somewhat related to this. I need some way to trigger pre- and post-build events when using compile-on-save for a TS project having a single file output (while still maintaining the usual VS "Build" and "Rebuild" commands, language service, debugging etc.). As a workaround I'm currently using Task Runner Explorer with grunt-contrib-watch (launched using a binding of "Solution Open") to watch the compiled file for changes and perform additional actions every time it's modified. However I don't find that really satisfying (I also need to perform some pre-compilation actions and generally prefer having build steps done either all using Grunt or all with VS) and consider doing exactly what is described: Turn off the VS compilation completely and implement a custom compile-on-save, full builds (that include running unit tests etc.), pre- and post- build events with a combination of grunt-contrib-watch, grunt-ts, additional grunt plugins and Task Runner Explorer. (update: already implemented that and it works fine - it runs a custom grunt build script every time a .ts file is modified, though currently it doesn't support TRE "Before Build" and "After Build" bindings - for the above mentioned reasons). It seems that the easiest (and least involved for TS plugin developers) way to efficiently allow these kinds of build scenarios would be to provide an option to turn off any form of compilation initiated by Visual Studio. I would, too, appreciate any ideas on how to do that? |
I don't know if there's a great option for you right now. If you set every .ts file in the project to have |
Build is derived by targets in MSBuild projects. If you want to disable the default typescript build, remove the reference to the typescript targets from your file. This is going to make your language service not collect all files in the project in one context. I would say that is fine, and by next release we should have tsconfig support and then that becomes your new project. If you still want to make it work without using tsconfig, and/or waiting for the next release, define a property |
@mhegazy did you mean |
well depending on what you want :) if you want to turn off the language service project content loading, make it false, |
OK I'll mess around with it. Thanks! |
Thanks @mhegazy, the configuration option seems to work so far! (while still showing syntax/complie errors and allowing debugging in IE) and can even be set for a specific solution configuration (I tried and it seemed to work), like this: <PropertyGroup Condition="'$(Configuration)' == 'Debug'">
...
<TypeScriptEnabled>false</TypeScriptEnabled>
...
</PropertyGroup> I'm not exactly sure though what "disabling the language service project content loading" means? (I'm not very familiar with VS concepts like targets, contexts etc). As far as I've tested, everything seems to work normally with this option (apart from the expected behavior of not compiling on build)? And it looks like it will still add On a side note, now with everything done through Grunt, I somehow have to find a way to deal with collisions between grunt-watch triggered builds and "Before Build"/"After Build" bound events when invoking the VS |
I was not able to get Here's the complete steps required to disable TypeScript compilation in VS (though still have the language services work, keep refactoring happy, etc.):
The second step is sort of a bug (or at least the dialog is not labeled in a strictly accurate manner); Even though your TypeScript files are "part" of a project, if you disable the targets file, Visual Studio 2013 will treat them as if they are not part of a project and do compile on save (if the global option is not set). I couldn't get Thanks @mhegazy - it would be awesome if this could be part of the TypeScript options dialog, but at least it's fairly easy to support via project edit. |
one tricky thing, is |
You're exactly right! This was the trick. |
I think this solves the problem. Thanks, @mhegazy . |
Hi @mhegazy - sorry to trouble you. Are you certain that <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets')" />
<PropertyGroup>
<TypeScriptEnabled>false</TypeScriptEnabled>
</PropertyGroup>
</Project> It was working correctly on this machine earlier today (when I closed this ticket), but now that I put 1.4 on here, the Build from VS is giving me errors. Commenting out the reference to the targets file (and turning off "compile on save" for TypeScript not in a project) does still disable it. I have 1.4 at home and I couldn't get |
if you do not want to get build on F5, remove the reference to the targets. That was the short answer, here is the long version: The project file is used for two things:
If you do not want build in VS to work, just remove the targets. this will disable build, but will also tell the LS that this project is not a TypeScript project. and it will then treat all files as "loose files". if this is ok with you, then no more work is needed. if you want to change that and make it still use the properties from your project file, and not include other files open in your project, etc.. then add If you want the build to work in VS, but the LS not to treat it as a project, then set the flag to false. |
Thanks. This is great information and everything seems to work consistently with what you've described. If I've removed the .targets file, but set <!--
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets')" />
-->
<PropertyGroup>
<TypeScriptEnabled>true</TypeScriptEnabled>
</PropertyGroup>
</Project> If so, this seems odd because it means there would be no way to control the settings that were accessible in the UI without re-enabling the target and then using the UI (or more realistically just editing the TS project setting directly at that point since you're in there anyway). The reason I'm asking all this is that I wrote an npm library a few weeks ago to read the TypeScript build properties out of a .csproj and .vbproj (https://www.npmjs.com/package/csproj2ts) which I'm currently integrating into grunt-ts. When it's ready, there will be an easy way to effectively "run tsc against a .csproj file" (as requested here: #1702). I want to be able to tell people the best way to set up their project to use the VS TypeScript language service for their coding experience, but entirely use grunt-ts for building. I was hoping that it would be possible to let people use the UI to configure TypeScript properties in this scenario, but perhaps it won't be. Are you aware of a way to have the TypeScript Build tab show up with the TypeScript .targets file disabled? Also, it seems even if I do something like this: Sorry, @mhegazy - I promise I'm not trolling you!! |
yes, the property pages are wired in the targets, so removing them removes the UI, you will have to manually edit the file
The scenario you are trying to achieve is doable, but will have some rough edges, and you will need to hack a few places to make it work. @paulvanbrenk is currently adding support for tsconfig in VS, this allows the project property pages to use the tsconfig file if it was there. We are also working on integrating better in ASP.net 5 projects, which i believe will do all what you want, namely 1. grubt/bower support, 2. a file system based view, 3. use tsconfig to manage project properties, and 4. simple interaction with other editors/IDEs. I believe this will work nicely with the scenario you are describing and you will not have to hack your way around it. this will come in the next release though, so some waiting is involved :)
Imports are loaded when the project is loaded. so in this import you are saying loaded only in 'Configuration' 'Debug', changing the configuration does not force a reload.
|
OK. Truly, thank you for such excellent information and thorough discussion. Just to throw it out there to @paulvanbrenk - it would be awesome to have some sort of way even in the future state with the The
Allowing Visual Studio users to choose a community-developed TypeScript compiler system while still keeping the nice UI inside Visual Studio would be awesome (especially with the nice Task Runner Explorer add-on). I hope you'll weigh the significant benefits to the community this would enable against the time it would take you to code a checkbox that says "Disable TypeScript Build". |
This is the part where i get confused. to me this is removing the typescript targets reference, then replacing it with your grunt targets that will build things differently. it feels strange to me to include a .targets file with a condition that tells it to do nothing; why include it in the first place? I would be happy to help compose a .targets file that replaces the standard typescript targets, this one will include the |
Huh. I should have thought of that - I think I've been treating the .targets file as this unchangeable thing, but of course this makes perfect sense. I'll look into the targets file format and get back to you. |
an easy way to start is to copy the targets file Microsoft.TypeScript.Target, remove things that you do not care about, e.g. calling tsc, and add tasks to call grunt, and wire in the configuration, etc.. then include it in your project. |
Awesome! I've gotten everything working from a minimalist perspective by setting my .csproj file with the following 4 lines. <Import Project="$(ProjectDir)\custom.TypeScript.targets" />
<PropertyGroup>
<TypeScriptEnabled>true</TypeScriptEnabled>
</PropertyGroup> And the minimalist custom.TypeScript.targets file is this: <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VsToolsPath Condition="'$(VsToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VsToolsPath>
</PropertyGroup>
<UsingTask TaskName="TypeScript.Tasks.VsTsc" AssemblyFile="$(VSToolsPath)\TypeScript\TypeScript.tasks.dll" />
<PropertyGroup>
<CfgPropertyPagesGuidsAddCSharp>{d4683cae-88c4-4b85-863d-ac8014f3ba36}</CfgPropertyPagesGuidsAddCSharp>
<CfgPropertyPagesGuidsAddVB>{d4683cae-88c4-4b85-863d-ac8014f3ba36}</CfgPropertyPagesGuidsAddVB>
<CfgPropertyPagesGuidsAddTypeScript>{d4683cae-88c4-4b85-863d-ac8014f3ba36}</CfgPropertyPagesGuidsAddTypeScript>
</PropertyGroup>
<ItemGroup>
<ProjectCapability Include="TypeScript" />
</ItemGroup>
</Project> I tried putting the I think that this solves my problem at this point. I can run my Grunt task using the Task Runner Explorer extension which can kick off Grunt or Gulp tasks when a VS Build is triggered. The build now always shows as having succeeded regardless of the TypeScript compile result, but this is fine since the user can see the output from grunt-ts in the TRX window. The "TypeScript Build" panel appears in the project properties window. Compile on save works if that option is selected. The build still shows as failed if the C# or VB code doesn't compile successfully (a good thing). The setup to get here from a default Visual Studio "HTML Application with TypeScript" or ASP.NET web project is fairly straight-forward. Can you see any problem with us distributing the above minimalist .targets file with grunt-ts? That would mean that we'd only have to tell people to update their project's .targets line to Thanks again!! |
this is strange. this is how we have it in our targets, and it works fine. are you including other targets that has the property? any conditions? i tried it in a new ts project, removed the Microsoft.TypeScript.targets, and put yours, and added true and that worked.
I think this is the correct way to go. i would just try to get the TypeScriptEnabled in there as well. let me know how i can help diagnosing the issue a few notes, you do not need the tasks.dll reference nor the VsToolsPath definition, unless you need it for something else. |
I'm seeing the behavior you predicted on my home computer. It also worked without the reference to the DLL. I must have made some sort of mistake before, so I'll try it out again tomorrow. I think this is really great! Thanks, Mohamed. This should be released as part of grunt-ts in the next few days. |
one thing that might be causing this is target files are only loaded once in VS, so if you edit the targets the changes will not be reflected in your project until you restart VS. |
That could have been it; I was just unloading/reloading the project. It's possible I restarted VS at home. I'll make a note of that in the docs. |
@mhegazy Thanks for all your help. We've released grunt-ts 4.0.0 which contains the "compile from Visual Studio Project" feature: https://github.com/TypeStrong/grunt-ts#vs Instructions to disable VS build: https://github.com/TypeStrong/grunt-ts/blob/master/docs/DisableVisualStudioBuild.md |
Very cool! I love the scenarios this enables. |
Thanks, Ryan. I'm fairly pleased with how it turned out. When tsconfig comes about, it might be less necessary, but this will bridge the gap until then and of course it's compatible with TypeScript compiler versions prior to 1.5. PS: There have been two bug reports today, so we should be pushing a 4.0.1 tonight assuming I can get them corrected. |
Just FYI, in VS2015 RTM there is an easier way to disable TypeScriptCompile: |
Thanks. |
Hi,
We've recently developed an enhancement for the grunt-ts plugin that allows targeting a Visual Studio project file for input TS file paths and TS config info rather than having to use
src:
and the other options. TypeStrong/grunt-ts#215Grunt-ts along with Task Runner Explorer enables developers to use features not yet supported by the Visual Studio TypeScript project build config UI (such as preserveConstEnums).
One thing about using Task Runner Explorer is that it can only hook into certain Visual Studio events. Among them is "after build" and "before build". After build works great, but it has the odd issue of VS doing its own compilation step of the TypeScript followed by grunt-ts calling tsc. This doesn't seem to be an issue except for performance (the work VS is doing to compile and emit is wasted effort and the developer has to wait longer for the desired result).
I'm wondering what the best way would be for us to turn off only the compile/emit in Visual Studio for TypeScript, but keep everything else the same (language service/syntax highlighting, errors list, C# or VB building, etc). Is this even currently possible? If not, could it be?
Thanks!
The text was updated successfully, but these errors were encountered: