none
Can you integrate an NPM script when you Build or Publish in VS 2017?

    Question

  • In other words integrate the npm script that into build/publish pipeline so the files are build and ready for when I click Publish?  or integrate into the Publish process?

    For instance in my package.json I have the following that will build my Angular CLI application into an optimized production version into the "\dist" folder I have specified in my angular-cli.json file.

     "scripts": {
        "build": "ng build --prod"

    Right now I have to run this manually before Publish so the files are there to be deployed to my IIS.

    1.) I suppose I can run "cmd.exe /c npm run build" but not sure if you can do this in the VS Build/Publish

    2.) Something else I just noticed is "Publish" says it's copying my "dist" folder but the contents never make it to the publish destination but the "dist/out-tsc" does...Why is Publish ignoring certain files?

    Thanks


    Thursday, February 01, 2018 4:06 PM

Answers

  • AFAIK, you can also use the extension NPM Task Runnerto integrate the npm script that into build pipeline. This extension brought the experience of managing these task runners a little closer to home for VS users, but it also let you integrate the tasks into the build pipeline of VS itself. For some more details, you can refer to following blog for details:

    https://blog.sstorie.com/0-60-with-angular-2-and-visual-studio-part-2/

    For the second issue, have you try to include your scripts to your .csproj file:

    <Content Include="Client\dist\**\*.*" />

    Besides, since the second issue is more related to angular, you can open a new thread on the GitHub:

    https://github.com/angular/angular/issues

    Hope this helps.

     

    MSDN Community Support Please remember to click Mark as Answer. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    • Edited by Leo Liu-MSFTMicrosoft contingent staff Friday, February 02, 2018 8:35 AM
    • Marked as answer by dat1 Saturday, February 03, 2018 2:59 AM
    • Unmarked as answer by dat1 Tuesday, February 06, 2018 4:00 PM
    • Marked as answer by dat1 Tuesday, February 06, 2018 10:29 PM
    Friday, February 02, 2018 8:35 AM

All replies

  • Yes you can do that using  an MsBuild Task in the csproj file and you tell that msbuild task to run npm.

    You can follow the following repository for a sample

    MsBuild


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (kokkisajee) or Facebook (sajeetharan) profile for Sajeetharan at Stack Overflow, Q&A for professional and enthusiast programmers

    Thursday, February 01, 2018 4:12 PM
  • Thank you! I will look into that as well.  I also just found under "Project" >  "ProjectName Properties" > "Build Events" you can add Pre-Build/Post-build command lines.

    I'm still not sure that why what gets built into my "\dist" folder doesn't get Published to my destination folder.  


    Thursday, February 01, 2018 4:18 PM
  • AFAIK, you can also use the extension NPM Task Runnerto integrate the npm script that into build pipeline. This extension brought the experience of managing these task runners a little closer to home for VS users, but it also let you integrate the tasks into the build pipeline of VS itself. For some more details, you can refer to following blog for details:

    https://blog.sstorie.com/0-60-with-angular-2-and-visual-studio-part-2/

    For the second issue, have you try to include your scripts to your .csproj file:

    <Content Include="Client\dist\**\*.*" />

    Besides, since the second issue is more related to angular, you can open a new thread on the GitHub:

    https://github.com/angular/angular/issues

    Hope this helps.

     

    MSDN Community Support Please remember to click Mark as Answer. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    • Edited by Leo Liu-MSFTMicrosoft contingent staff Friday, February 02, 2018 8:35 AM
    • Marked as answer by dat1 Saturday, February 03, 2018 2:59 AM
    • Unmarked as answer by dat1 Tuesday, February 06, 2018 4:00 PM
    • Marked as answer by dat1 Tuesday, February 06, 2018 10:29 PM
    Friday, February 02, 2018 8:35 AM
  • Thanks again! I did what you said and added this to my .csproj's ItemGroup as follows and it worked when I ran Build

    <ItemGroup>
    .....
    <Content Include="dist\**\*.*" />
    </ItemGroup>



    • Edited by dat1 Tuesday, February 06, 2018 10:29 PM
    Saturday, February 03, 2018 2:59 AM