Skip to content

Instantly share code, notes, and snippets.

@elizabeth-young
Last active January 5, 2016 15:59
Show Gist options
  • Save elizabeth-young/87e4accef7a9db1c3283 to your computer and use it in GitHub Desktop.
Save elizabeth-young/87e4accef7a9db1c3283 to your computer and use it in GitHub Desktop.
Add gulp to MS Build

To run gulp on build

Add the following nuget packages

https://github.com/kmees/MSBuild.NodeTools

Install-Package MSBuild.Npm
Install-Package MSBuild.Gulp

Add tasks for each project configuration to gulpfile.js

gulp.task('build-Debug', function () {
  return processScripts(false, false);
});
gulp.task('build-Release', function () {
  return processScripts(false, true);
});

To exclude gulpfile.js and package.json from deployed version

Add the following line to the PropertyGroup element in the publish profile

<ExcludeFilesFromDeployment>gulpfile.js;package.json;packages.config;</ExcludeFilesFromDeployment>

To deploy build files not included in project

Add the following to the bottom of the profile above the closing Project tag

<Target Name="CustomCollectFiles">
    <ItemGroup>
      <_CustomFiles Include="Scripts\build\**\*" />
      <FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
        <DestinationRelativePath>Scripts\build\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
      </FilesForPackagingFromProject>
    </ItemGroup>
  </Target>
  <PropertyGroup>
    <CopyAllFilesToSingleFolderForPackageDependsOn>
      CustomCollectFiles;
      $(CopyAllFilesToSingleFolderForPackageDependsOn);
    </CopyAllFilesToSingleFolderForPackageDependsOn>

    <CopyAllFilesToSingleFolderForMsdeployDependsOn>
      CustomCollectFiles;
      $(CopyAllFilesToSingleFolderForMsdeployDependsOn);
    </CopyAllFilesToSingleFolderForMsdeployDependsOn>
  </PropertyGroup>

Example publish profile

<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit http://go.microsoft.com/fwlink/?LinkID=208121. 
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <ExcludeFilesFromDeployment>gulpfile.js;package.json;packages.config;scripts\_references.js;ignoreme.txt</ExcludeFilesFromDeployment>
    <publishUrl>C:\Path\To\Folder</publishUrl>
    <DeleteExistingFiles>True</DeleteExistingFiles>
  </PropertyGroup>
  <Target Name="CustomCollectFiles">
    <ItemGroup>
      <_CustomFiles Include="Scripts\build\**\*" />
      <FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
        <DestinationRelativePath>Scripts\build\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
      </FilesForPackagingFromProject>
    </ItemGroup>
  </Target>
  <PropertyGroup>
    <CopyAllFilesToSingleFolderForPackageDependsOn>
      CustomCollectFiles;
      $(CopyAllFilesToSingleFolderForPackageDependsOn);
    </CopyAllFilesToSingleFolderForPackageDependsOn>

    <CopyAllFilesToSingleFolderForMsdeployDependsOn>
      CustomCollectFiles;
      $(CopyAllFilesToSingleFolderForMsdeployDependsOn);
    </CopyAllFilesToSingleFolderForMsdeployDependsOn>
  </PropertyGroup>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment