Skip to content

Visual Studio "No Compile" option #2294

Closed

Description

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#215

Grunt-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!

Activity

  1. rotemdan commented on Mar 11, 2015

    @rotemdan

    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?

  2. danquirk commented on Mar 11, 2015

    @danquirk
    Member

    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 Action: None in its properties that would probably do what you want but it's pretty onerous to do manually even in medium sized projects.

  3. mhegazy commented on Mar 11, 2015

    @mhegazy
    Contributor

    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 <TypeScriptEnabled>true</TypeScriptEnabled> in your project file.

  4. nycdotnet commented on Mar 11, 2015

    @nycdotnet
    Author

    Mohamed Hegazy (@mhegazy) did you mean <TypeScriptEnabled>false</TypeScriptEnabled> ?

  5. mhegazy commented on Mar 11, 2015

    @mhegazy
    Contributor

    well depending on what you want :)

    if you want to turn off the language service project content loading, make it false,
    if you want to enable it, make it true. it is already enabled by including the default targets (Microsoft.TypeScript.targets)

  6. nycdotnet commented on Mar 11, 2015

    @nycdotnet
    Author

    OK I'll mess around with it. Thanks!

  7. rotemdan commented on Mar 11, 2015

    @rotemdan

    Thanks Mohamed Hegazy (@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 <TypeScriptCompile Include=".."/> entries for newly added/created .ts files in the project configuration.

    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 Build(F6) and Rebuild commands, as VS automatically saves before the build starts, leading to two different Grunt instances needlessly running in parallel.

  8. nycdotnet commented on Mar 19, 2015

    @nycdotnet
    Author

    I was not able to get <TypeScriptEnabled>false</TypeScriptEnabled> to work (VS 2013 Update 4 with TypeScript 1.4), but removing the TypeScript targets file from the project did disable the compilation on project Build.

    Here's the complete steps required to disable TypeScript compilation in VS (though still have the language services work, keep refactoring happy, etc.):

    • Remove the reference to the TypeScript ".targets" file from the project file.
    • Disable "Automatically compile TypeScript files which are not part of a project" in the Visual Studio TypeScript options.

    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 <TypeScriptEnabled/> to do anything.

    Thanks Mohamed Hegazy (@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.

  9. mhegazy commented on Mar 19, 2015

    @mhegazy
    Contributor

    one tricky thing, is <TypeScriptEnabled>false</TypeScriptEnabled> needs to be at the end of your file specifically after the import to the targets. as the targets define it anyways, and you want to override it.

  10. nycdotnet commented on Mar 24, 2015

    @nycdotnet
    Author

    one tricky thing, is false needs to be at the end of your file specifically after the import to the targets. as the targets define it anyways, and you want to override it.

    You're exactly right! This was the trick.

  11. nycdotnet commented on Mar 24, 2015

    @nycdotnet
    Author

    I think this solves the problem. Thanks, Mohamed Hegazy (@mhegazy) .

  12. nycdotnet commented on Mar 24, 2015

    @nycdotnet
    Author

    Hi Mohamed Hegazy (@mhegazy) - sorry to trouble you. Are you certain that <TypeScriptEnabled>false</TypeScriptEnabled> works in VS 2013 with TypeScript 1.4 installed? I just upgraded my current PC from VS 2013 with TS 1.3 (straight VS 2013 Update 4) to VS 2013 with TS 1.4, and now Visual Studio is trying to build the TypeScript again "on build" (meaning the errors that appear have "Build:" in front of them), even though the last five lines of my projects are as below:

      <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 <TypeScriptEnabled>false</TypeScriptEnabled> to work at all there - I'm wondering if there was a regression on this build option?

  13. 4 remaining items

  14. mhegazy commented on Mar 25, 2015

    @mhegazy
    Contributor

    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 <TypeScriptEnabled>true</TypeScriptEnabled> tag and will look to VS as if it is the default one, but it will handle build differently.

  15. nycdotnet commented on Mar 25, 2015

    @nycdotnet
    Author

    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.

  16. mhegazy commented on Mar 25, 2015

    @mhegazy
    Contributor

    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.

  17. nycdotnet commented on Mar 25, 2015

    @nycdotnet
    Author

    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 <TypeScriptEnabled /> tag in the targets file, but it wasn't working (VS was treating the .ts files as loose). Any idea why that is? (I'm sure for someone that knows MSBuild this is obvious - maybe some sort of scope problem?).

    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 <Import Project="$(ProjectDir)\node_modules\grunt-ts\custom.TypeScript.targets" /> and set <TypeScriptEnabled>.

    Thanks again!!

  18. mhegazy commented on Mar 25, 2015

    @mhegazy
    Contributor

    I tried putting the tag in the targets file, but it wasn't working (VS was treating the .ts files as loose). Any idea why that is? (I'm sure for someone that knows MSBuild this is obvious - maybe some sort of scope problem?).

    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.

    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 and set .

    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.

  19. nycdotnet commented on Mar 26, 2015

    @nycdotnet
    Author

    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.

  20. mhegazy commented on Mar 26, 2015

    @mhegazy
    Contributor

    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.

  21. nycdotnet commented on Mar 26, 2015

    @nycdotnet
    Author

    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.

  22. nycdotnet commented on Mar 27, 2015

    @nycdotnet
    Author

    Mohamed Hegazy (@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

  23. RyanCavanaugh commented on Mar 27, 2015

    @RyanCavanaugh
    Member

    Very cool! I love the scenarios this enables.

  24. nycdotnet commented on Mar 27, 2015

    @nycdotnet
    Author

    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.

  25. geirsagberg commented on Aug 10, 2015

    @geirsagberg

    Just FYI, in VS2015 RTM there is an easier way to disable TypeScriptCompile:
    Just add <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked> to the .csproj, e.g. in the first <PropertyGroup>.

  26. nycdotnet commented on Aug 10, 2015

    @nycdotnet
    Author

    Thanks.

  27. locked and limited conversation to collaborators on Jun 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions