Node-based parser of Visual Studio projects/solutions.
All functions come in synchronous and asynchronous versions. Synchronous versions are suffixed with "Sync". Asynchronous versions return a promise which resolves to the same value as the synchronous version of a function.
Solution file parser
constparseSolution=(file,options={})=>Promise.resolve({})constparseSolutionSync=(file,options={})=>{}From a path
constparser=require('vs-parse');constsolutionData=awaitparser.parseSolution('HelloWorld.sln');From a string
constparser=require('vs-parse');constfs=require('fs');constcontents=fs.readFileSync('HelloWorld.sln',{encoding: 'utf-8'});constsolutionData=awaitparser.parseSolution(contents);From a buffer
constparser=require('vs-parse');constfs=require('fs');constbuffer=fs.readFileSync('HelloWorld.sln');constsolutionData=awaitparser.parseSolution(buffer);constparser=require('vs-parse');constsolutionData=awaitparser.parseSolution('HelloWorld.sln');console.log(solutionData);/* Outputs: { fileFormatVersion: '12.00', visualStudioVersion: '15.0.27004.2009', minimumVisualStudioVersion: '10.0.40219.1', projects: [ { id: '1580E0CD-6DAA-4328-92F6-2E0B0F0AB7AF', name: 'TestNUnit3', relativePath: 'TestNUnit3\\TestNUnit3.csproj', projectTypeId: 'FAE04EC0-301F-11D3-BF4B-00C04F79EFBC' } ] }*/A full parse of a solution and all its dependencies can be done by passing the deepParse option. This will force the parser to enumerate and parse all dependent projects (as well as their dependencies). See parseProject() for details.
Example:
constparser=require('vs-parse');constsolutionData=awaitparser.parseSolution('HelloWorld.sln'{deepParse: true});console.log(solutionData);/* Outputs: { fileFormatVersion: '12.00', visualStudioVersion: '15.0.27004.2009', minimumVisualStudioVersion: '10.0.40219.1', projects: [ { id: '1580E0CD-6DAA-4328-92F6-2E0B0F0AB7AF', name: 'TestNUnit3', relativePath: 'TestNUnit3\\TestNUnit3.csproj', projectTypeId: 'FAE04EC0-301F-11D3-BF4B-00C04F79EFBC', codeFiles: [ { fileName: 'MyFile.cs' } ], packages: [ { name: 'NUnit', version: '3.7.1', targetFramework: 'net452' } ], references: [ { assemblyName: 'nunit.framework', culture: 'neutral', hintPath: '..\packages\NUnit.3.7.1\lib\net45\nunit.framework.dll', processorArchitecture: 'MSIL', publicKeyToken: 'b035f5f7f11d50a3a', version: '3.7.1.0' } ] } ] }*/Parses a project file.
constparseProject=(file,options={})=>Promise.resolve({})constparseProjectSync=(file,options={})=>{}From a path
constparser=require('vs-parse');constprojectData=awaitparser.parseProject('./TestNUnit3/TestNUnit3.csproj');From a string
constparser=require('vs-parse');constfs=require('fs');constcontents=fs.readFileSync('./TestNUnit3/TestNUnit3.csproj',{encoding: 'utf-8'});constprojectData=awaitparser.parseProject(contents);From a buffer
constparser=require('vs-parse');constfs=require('fs');constbuffer=fs.readFileSync('./TestNUnit3/TestNUnit3.csproj');constprojectData=awaitparser.parseProject(buffer);Example:
constparser=require('vs-parse');constprojectData=awaitparser.parseProject('./TestNUnit3/TestNUnit3.csproj');console.log(projectData);/* Outputs: { codeFiles: [ { fileName: 'Class1.cs' } ], references: [ { assemblyName: 'nunit.framework', culture: 'neutral', hintPath: '..\packages\NUnit.3.7.1\lib\net45\nunit.framework.dll', processorArchitecture: 'MSIL', publicKeyToken: 'b035f5f7f11d50a3a', version: '3.7.1.0' } ] }*/A full parse of a project and all its dependencies can be done by passing the deepParse option. This will force the parser to enumerate and parse all packages. Project files using the <PackageReference> format do not require this option to return dependent packages. Dependency parsing will defer to the dependencies listed in packages.config over <PackageReference> if a packages.config file is present.
Example:
constparser=require('vs-parse');constprojectData=awaitparser.parseProject('./TestNUnit3/TestNUnit3.csproj',{deepParse: true});console.log(projectData);/* Outputs: { codeFiles: [ { fileName: 'Class1.cs' } ], packages: [ { name: 'NUnit', version: '3.7.1', targetFramework: 'net452' } ], references: [ { assemblyName: 'nunit.framework', culture: 'neutral', hintPath: '..\packages\NUnit.3.7.1\lib\net45\nunit.framework.dll', processorArchitecture: 'MSIL', publicKeyToken: 'b035f5f7f11d50a3a', version: '3.7.1.0' } ] }*/Parses a nuget 'packages.config' file.
constparsePackages=(file,options={})=>Promise.resolve({})constparsePackagesSync=(file,options={})=>{}constparser=require('vs-parse');constpackages=awaitparser.parsePackages('./packages.config');console.log(packages);/* Outputs: [ { name: 'NUnit', version: '3.7.1', targetFramework: 'net452' } ]*/A very simple semver parser. Mostly a wrapper over standardized tools, with support for .NET-specific assembly versioning.
constparser=require('vs-parse');constversionString='1.2.3.4';constversionInfo=parser.parseSemverSync(versionString);console.log(versionInfo);/* Outputs: { major: '1', minor: '2', patch: '3', version: '1.2.3', originalString: '1.2.3.4' }*/An options object can be passed to a parsing function to customize its behaviour.
deepParse - Specifying true will also read and parse all dependencies. Defaults to false.
Example: A solution is dependent on its projects, while a project is dependent on its packages.
dirRoot - The root directory under which the solution or project lives. Defaults to undefined.
Required when doing a deep parse of a solution or project from file contents or a buffer.