Files could not be found in your workspace, or you do not have permission to access it

老子叫甜甜 提交于 2019-12-24 10:38:02

问题


I realize this question has been asked before, but I haven't found an answer that specifically addresses this issue.

I'm using Visual Studio 2015 Update 3 on a project with Core 1 (MVC 6), Angular2 and the project is in TFS. I'm using Gulp-watch to copy html/css/js files over as I work on them and this works most of the time. I have most of wwwroot in my .tfignore file including my "app" folder where all those files are being copied/cleaned by gulp and gulp-watch. I know tfignore settings are working because TFS is not trying to commit those files. However when Gulp does a clean on that folder I get a "could not be found in your workspace, or you do not have permission to access it.". This TFS check slows down the process when I build and that's enough to want to fix it, but at times the Gulp-Watch process fails because it doesn't have permissions to copy a specific html file. The gulp-watch copy error is EPERM: operation not permitted, open 'dashboard.component.html' at Error (native) Process terminated with code 1. If I clean and then re-run the Gulp copy there are no permission issues. I'm thinking that possibly TFS is playing a part in this problem even though those files are tfignored.

PS. I've read that you can use gulp-plumber to avoid the stops on errors, but I'm trying to figure out what is causing the TFS errors in wwwroot and hopefully as a result fix the frequent file copy errors first.

Gulp code in question:

var appDestPath = './wwwroot/app/';

gulp.task('clearAppDestinationFolderHtml',
    function () {
        return gulp.src(appDestPath + '**/*.html')
            .pipe(clean());
    });

gulp.task('clearAppDestinationFolderCss',
    function () {
        return gulp.src(appDestPath + '**/*.css')
            .pipe(clean());
    });

gulp.task('moveHtml', function () {
    gulp.start('clearAppDestinationFolderHtml');
    gulp.src(['app/**/*.html']).pipe(gulp.dest('./wwwroot/app/'));
});

gulp.task('moveCss', function () {
    gulp.start('clearAppDestinationFolderCss');
    gulp.src(['app/**/*.css']).pipe(gulp.dest('./wwwroot/app/'));
});

gulp.task('watch', function () {
    gulp.watch('app/**/*.html', ['moveHtml']);
    gulp.watch('app/**/*.css', ['moveCss']);
});

The cleaning of the destination folder was only added while trying to fix this problem. I'm realizing that the clean is running at the same time as the copy and could cause it's own issues. I just recently tried this code as well to copy only the specific file changed and ended up with the same error as before (operation not permitted, open 'wwwroot\app\User\Components\app.component.ts'):

gulp.task('watch2', function () {
    return gulp.watch('./app/**/*', function(obj){
        if( obj.type === 'changed') {
            gulp.src( obj.path, { "base": "./app/"})
            .pipe(gulp.dest(appDestPath));
        }
    })
});

Also here is my .tfignore file:

wwwroot/app
wwwroot/scripts
wwwroot/libs
wwwroot/_references.js
app/*.js
app/*.js.map
typings

回答1:


If you're only moving files to the /app directory, they're probably still read-only. Files under TFS source control are read-only. If that's the case, the gulp-chmod plugin can remove that read-only flag.

Also, gulp-clean is deprecated in favor of del.

As for the dependency, that's not hard to do with gulp 3. You can either use a plugin called run-sequence (which is a temporary fix until gulp 4 is released) or you can just set a dependency on the task

var gulp = require('gulp'),
    $ = require('gulp-load-plugins')(),
    del = require('del'),
    appDestPath = './app/';


gulp.task('clean:html', () => {
    return del([
        appDestPath + '**/*.html'
    ]);
});

gulp.task('clean:css', () => {
    return del([
        appDestPath + '**/*.css'
    ]);
});

gulp.task('moveHtml', ['clean:html'], function () {
    gulp.src(['src/**/*.html'])
        .pipe($.chmod(666))
        .pipe(gulp.dest('./app/'));
});

gulp.task('moveCss', ['clean:css'], function () {
    gulp.src(['src/**/*.css'])
        .pipe($.chmod(666))
        .pipe(gulp.dest('./app/'));
});

gulp.task('watch', () => {
    gulp.watch('src/**/*.html', ['moveHtml']);
    gulp.watch('src/**/*.css', ['moveCss']);
});


来源:https://stackoverflow.com/questions/39273591/files-could-not-be-found-in-your-workspace-or-you-do-not-have-permission-to-acc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!