6

I'm new to gulp. I set it up to preprocess some javascript in a folder within my project. When the task completes, new minified files are created, but they are not automatically included in my Visual Studio Project.

How can I automatically add these to my project? Do I have to manually add files created by gulp or other preprocessors manually?

bingo
  • 2,298
  • 1
  • 15
  • 21

2 Answers2

1

If the filenames aren't going to change the easiest thing is to add the files into the project.

If they are going to change you can edit the .csproj file and change Context Include= to a wildcard (*).

Right click on the project and choose Unload Project. Then right-click on the project again and Edit name.csproj. Find a file in the same location you want to include and change it to *.

e.g.

<Content Include="Dist\js\*.js" />

Then Visual Studio will pick up whatever is in the folder.

danny-sg
  • 91
  • 1
  • 4
  • ...just one more thing. This appeared to be working but my included files went missing again. [This](http://stackoverflow.com/a/9438419/2456553) answer seems to have the solution, adding the Include in as a Pre/Post build. – danny-sg Nov 17 '15 at 07:56
  • Could you not get gulp to rewrite some of your project.csproj file to add the files? – Worthy7 Dec 15 '17 at 07:14
0

Please reference following code, it works for me.

'use strict';
var gulp = require('gulp'),
    addContentFileToVSProject = require('add-content-file-to-project');

gulp.task('addNewFiles', () => {
    return new Promise((resolve, reject) => {

        // step 1: get new files
        var allNewFiles = geNewFiles(sourcePath, destnationPath);

        // step 2: add new files to .csproj
        for (var f in allNewFiles) {
            var newfile = destnationPath + '/' + allNewFiles[f];

            // to .csproj
            addContentFileToVSProject.execute(newfile);

         }
        resolve();
     });
});

By the way, I'm using Gulp 4.0 and Visual Studio 2017 latest version. The geNewFiles(s, t) is a function which return all new files by comparing files between source and destination folder. I put all new generated files to destination folder.

Ortsbo
  • 175
  • 1
  • 7