Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
scan csproj files for usage of ProjectReference
const glob = require('glob')
const fs = require('fs');
const xml2js = require('xml2js');
const path = require('path');
function parseFile (filePath, parser) {
fs.readFile(filePath, (err, data) => {
parser.parseString(data, (err, result) => {
const itemgroups = result.Project.ItemGroup;
if (itemgroups && itemgroups.length) {
itemgroups.forEach(grp => {
if (grp.ProjectReference) {
const cleanFilePath = filePath.replace(/\.\.\/\.\./, ''); // replace(/\.\.\\\.\.\.\\/, '')
console.log(grp.ProjectReference.length + ' ProjectReferences in ' + cleanFilePath);
grp.ProjectReference.forEach(ref => {
let include = ref.$.Include;
include = include.replace(/\\/g, path.sep)
.replace(/\.\./g, '')
//.replace(/\.\.\//, '');
console.log('--> Project Ref: ', include);
});
}
});
}
});
});
}
let scanPath = '../../**/*.csproj';
const projectFolder = '';
if (projectFolder) {
scanPath = `../../${projectFolder}/**/*.csproj`
}
console.log('Scanning', scanPath);
glob(scanPath, {}, function (err, files) {
if (err) {
console.log('ERR', err);
}
var parser = new xml2js.Parser();
files.forEach(file => {
// console.log(file);
parseFile(file, parser);
});
console.log(files.length + ' .csproj files scanned');
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.