Visual Studio 2012 and integrating node.



  • I have a SPA application using Angular 2 and typescript. I have configured this as a project in Visual Studio 2012.

    The newer versions of visual studio have this baked in. VS 2012 doesn't.

    For now I have a:

    • Pre-build" event that runs npm install.
    • Post-build" event that run npm start.

    It works okay for me. However there are two problems.

    • If they don't have node installed I won't get a failure on build before it launches.
    • I would prefer if they press "Debug" it would fire npm start.

    Is there any easy way of either integrating via customizing the project file to run custom actions on debug. Without having to deal with Web Essentials or an external plugin.

    I've done some googling and I can't find anything helpful.



  • Why are you still on 2012? :)



  • Because the other team members are using it. I am using VS2015, but I can't leave them shit up a creek without a paddle because I wanted use latest and greatest.

    What I got is workable, but not ideal. If I can get it nearer to ideal without writing a plugin ... then I am sorted.



  • This post is deleted!


  • @blakeyrat said:

    Assuming "they" is other developers you share the project with, I'm not sure there's a way to fix this.

    Who else would "they" be? FFS.

    @blakeyrat said:

    You could look into possibly configuring Nuget to install NPM and its dependencies?

    No I can't use NuGet, I can't use plugins otherwise I would have solved the problem already.

    The fix would be having a build failure telling them to install node. I need via the pre / post built event to send VS an event so it stops and flags it as a built failure.

    @blakeyrat said:

    I'm confused. The Debug configuration should still run Pre-Build and Post-Build events...?

    I use the post build event as a hack. It works, but it isn't perfect. I want something more integrated. I want it to start and kill the process.

    Stuff exists in the proj file, but if I remove or edit it regenerates so I must be doing something wrong. Thus why I am asking for help.

    I honestly couldn't give a shit if I was using something hacked together in VS, but I know other people do.


  • I survived the hour long Uno hand

    This is weird, because typically in this kind of shell scripting, npm failing to run (because it's not installed) would automatically fail the event. I'm seeing people upset because "net start soandso" fails their build if it's already running. Do you have other stuff in there you're not mentioning?



  • It's not the answer you want to hear, but have you tried educating your co-workers about the virtues of moving to Visual Studio 2015? There's some nifty stuff in VS2015 that they might enjoy.


  • Discourse touched me in a no-no place

    does npm install return some kind of indication if node's not installed, or just "bad command or file name" by the shell? If the latter, you can probably use a batch file. See http://superuser.com/questions/175466/determine-if-command-is-recognized-in-a-batch-file

    I don't know enough about node to round out a solution for you, but this should give you some more ideas: http://geekswithblogs.net/dchestnutt/archive/2006/05/30/80113.aspx


  • I survived the hour long Uno hand

    @FrostCat said:

    does npm install return some kind of indication if node's not installed, or just "bad command or file name" by the shell?

    I can't imagine it'd be the former; with nothing installed to respond to the command npm it'd have to be the shell barfing.


  • Discourse touched me in a no-no place

    @Yamikuronue said:

    nothing installed to respond to the command npm it'd have to be the shell barfing.

    My first link shows how to catch exactly that; the second talks about what to do with a batch file that has more than one command, although I didn't read the whole thing--the nuance there is that VS will only look at the error code of the last thing that happened; presumably you have to cache it after each command.


  • Garbage Person

    In other words, kill the luddites. There is literally no reason whatsoever not to upgrade.

    Also, whytf can't you use nuget? It's core functionality in 2012.

    Our approach to team members with missing bits of the dev environment is to shame then mercilessly until it's properly installed. If the CI system understands it, you'd better have your IDE set up to understand it.



  • @Weng said:

    Also, whytf can't you use nuget? It's core functionality in 2012.

    The dlls are statically linked and shared between solutions.



  • That's a weird thing about batch versus bash. Batch gives back the result of the last command, whereas bash only gives back an exit status if the script explicitly exits or if set -e, which causes any failed command to immediately terminate the script.



  • @lucas said:

    The dlls are statically linked

    I am unclear on what words mean anymore.



  • @lucas said:

    @Weng said:
    Also, whytf can't you use nuget? It's core functionality in 2012.

    The dlls are statically linked and shared between solutions.

    And this stops you from using NuGet packages for external-dependencies, how?



  • The external dependencies are statically linked. In any case using nuget won't solve my problem.



  • I still fail to see the problem.

    Also, why not turn those dependencies into NuGet packages of your own? You don't have to publish them on NuGet.org, you can even host them on Sharepoint if you wish.



  • @lucas said:

    Also, whytf can't you use nuget? It's core functionality in 2012.

    @lucas said:

    The dlls are statically linked and shared between solutions.

    You're going to have to elaborate on that.

    99.9% of the libraries available on Nuget are statically-linked and shared between solutions.



  • @AlexMedia said:

    I still fail to see the problem.

    Also, why not turn those dependencies into NuGet packages of your own? You don't have to publish them on NuGet.org, you can even host them on Sharepoint if you wish.

    The reason why I can't use Nuget is that the dlls are saved in a folder about 5 levels below in TFS and everything is referenced relative to C:\ drive instead of the solution directory.I can't remap my project folder and if I moved anything I would break every other project outside of mine if I moved anything. Mixing NuGet into the mix will break the pattern for other developers and everything will become more WTF as a result.

    In anycase it doesn't help me at all, because I am not concerned with using nuget. I am concerned with getting NPM slightly better integrated with VS 2012.



  • This looks sufficient for now.



  • @lucas said:

    dlls are saved in a folder about 5 levels below in TFS and everything is referenced relative to C:\ drive instead of the solution directory.I can't remap my project folder and if I moved anything I would break every other project outside of mine if I moved anything.

    Then fix that!



  • Unfortunately I think my boss would take a dim view if I spent the next 3 month fixing every reference, getting it tested so I haven't broken anything and then getting those changes deployed.

    Also it doesn't have anything to do with what I asked. I dunno why you are fixated on it.



  • @lucas said:

    I dunno why you are fixated on it.

    Because it's horribly broken, and obviously stopping you from Doing it RightTM



  • Well, whoever set it up created a huge mess by not using relative paths. (Which, BTW, are both supported and recommended by literally everything in Visual Studio, including NuGet.)



  • I'm responding like that because there are a few things which can easily be fixed. Still using VS 2012 and being unable to upgrade because someone set up your solutions in a shitty way is just blocking you, much more than a lack of npm will be.

    A while ago, I used a NuGet package to help with app.config transforms. When I upgraded to VS2015, it broke because some DLL was no longer present. Instead of sticking with VS2013, I fixed the problem (by switching to a different way of doing app.config transforms).


Log in to reply