Visual Studio Online - Continuous build with npm install and typescript

Oct 23, 2014 at 1:14 AM
Does anyone know how to create a Visual Studio Online build definition that uses the njsproj project type which installs all npm packages, compiles all the .ts files, removes all unwanted .ts files and deploys to Azure via continuous deployment integration?

Thanks

Francesco
Oct 29, 2014 at 4:28 PM
Edited Oct 30, 2014 at 3:17 PM
Hi francesco,

We build nodejs solutions with tfs online and deploys to Azure.We are using webstorm to develop but we used njsproj to build. You can check this presentation for a live example from build 2014 http://channel9.msdn.com/Events/Build/2014/3-584

We have a generic build.msproj based on njsproj.
build.msproj
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
        <SchemaVersion>2.0</SchemaVersion>
        <ProjectGuid>{6da09510-917a-4d15-bdf5-951132808dfe}</ProjectGuid>
        <ProjectView>ShowAllFiles</ProjectView>
        <StartupFile>server.js</StartupFile>
        <WorkingDirectory>.</WorkingDirectory>
        <OutputPath>.</OutputPath>
        <ProjectTypeGuids>{3AF33F2E-1136-4D97-BBB7-1795711AC8B8};{349c5851-65df-11da-9384-00065b846f21};{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}</ProjectTypeGuids>
        <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">11.0</VisualStudioVersion>
        <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
    </PropertyGroup>
    <PropertyGroup Condition="'$(Configuration)' == 'Debug'" />
    <PropertyGroup Condition="'$(Configuration)' == 'Release'" />
    <ItemGroup>
        <Content Include="package.json" />
        <Compile Include="server.js" />
        <Content Include="Web.config" />

        <!--  Include app folders and subfolders-->
        <Content Include="app\**\*.*" />
        <Content Include="config\**\*.*" />
        <Content Include="public\**\*.*" />
        <Content Include="utils\**\*.*" />
    </ItemGroup>
    <Import Project="$(MSBuildToolsPath)\Microsoft.Common.targets" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
    <Import Project="$(VSToolsPath)\Node.js Tools\Microsoft.NodejsTools.targets" />
    <ProjectExtensions>
        <VisualStudio>
          <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
            <WebProjectProperties>
              <UseIIS>False</UseIIS>
              <AutoAssignPort>True</AutoAssignPort>
              <DevelopmentServerPort>0</DevelopmentServerPort>
              <DevelopmentServerVPath>/</DevelopmentServerVPath>
              <IISUrl>http://localhost:48022/</IISUrl>
              <NTLMAuthentication>False</NTLMAuthentication>
              <UseCustomServer>True</UseCustomServer>
              <CustomServerUrl>http://localhost:1337</CustomServerUrl>
              <SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
            </WebProjectProperties>
          </FlavorProperties>
          <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}" User="">
            <WebProjectProperties>
              <StartPageUrl>
              </StartPageUrl>
              <StartAction>CurrentPage</StartAction>
              <AspNetDebugging>True</AspNetDebugging>
              <SilverlightDebugging>False</SilverlightDebugging>
              <NativeDebugging>False</NativeDebugging>
              <SQLDebugging>False</SQLDebugging>
              <ExternalProgram>
              </ExternalProgram>
              <StartExternalURL>
              </StartExternalURL>
              <StartCmdLineArguments>
              </StartCmdLineArguments>
              <StartWorkingDirectory>
              </StartWorkingDirectory>
              <EnableENC>False</EnableENC>
              <AlwaysStartWebServerOnDebug>False</AlwaysStartWebServerOnDebug>
            </WebProjectProperties>
          </FlavorProperties>
        </VisualStudio>
    </ProjectExtensions>
</Project>
for npm package we have an installModules.bat file
cd %APPVEYOR_BUILD_FOLDER%
cmd /c ""C:\Program Files\nodejs\npm.cmd" install 2>null"

exit 0
or it's also possible
cd %TF_BUILD_SOURCESDIRECTORY%
cmd /c ""C:\Program Files\nodejs\npm.cmd" install 2>null"

exit 0
and we have a build definition with this parameters

2.1 =>\build.msproj
2.5 => MSBuild Arguments : /t:package | Prebuild script path: \installModules.bat


Good luck.