diff --git a/src/utils.js b/src/utils.js
index 73dd223e..89943fec 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -36,9 +36,8 @@ function getCurrentVersionCsproj(csprojDocument) {
const propertyGroupNodes = Object.values(rootNode.childNodes).filter((node) => {
return node.nodeName === 'PropertyGroup';
});
- if (propertyGroupNodes.length === 1) {
- const propertyGroupNode = propertyGroupNodes[0];
-
+ //find version property within one of the property groups
+ for (const propertyGroupNode of propertyGroupNodes) {
const versionNodes = Object.values(propertyGroupNode.childNodes).filter((node) => {
return node.nodeName === 'Version';
});
@@ -63,22 +62,17 @@ function getNewProjectContentCsproj(newVersion, csprojDocument) {
const propertyGroupNodes = Object.values(rootNode.childNodes).filter((node) => {
return node.nodeName === 'PropertyGroup';
});
- if (propertyGroupNodes.length === 1) {
- const propertyGroupNode = propertyGroupNodes[0];
-
+ let coreVersionSat = false;
+ //find version property within one of the property groups
+ for (const propertyGroupNode of propertyGroupNodes) {
const versionNodes = Object.values(propertyGroupNode.childNodes).filter((node) => {
return node.nodeName === 'Version';
});
if (versionNodes.length === 1) {
const versionNode = versionNodes[0];
versionNode.childNodes.item(0).data = newVersion;
- } else {
- const versionNode = new DOMParser().parseFromString(
- `${newVersion}`,
- 'text/xml'
- );
- propertyGroupNode.appendChild(versionNode);
- }
+ coreVersionSat = true;
+ }
const packageVersionNodes = Object.values(propertyGroupNode.childNodes).filter((node) => {
return node.nodeName === 'PackageVersion';
@@ -104,6 +98,15 @@ function getNewProjectContentCsproj(newVersion, csprojDocument) {
versionNode.childNodes.item(0).data = `${newVersion}.0`;
}
}
+ if (coreVersionSat === false && propertyGroupNodes.length > 0) {
+ //Greedy, set the version in the first encountered property group
+ const propertyGroupNode = propertyGroupNodes[0];
+ const versionNode = new DOMParser().parseFromString(
+ `${newVersion}`,
+ 'text/xml'
+ );
+ propertyGroupNode.appendChild(versionNode);
+ }
}
return new XMLSerializer().serializeToString(rootNode);
}
diff --git a/test/utils.spec.js b/test/utils.spec.js
index a3c9bd1e..2b4048d6 100644
--- a/test/utils.spec.js
+++ b/test/utils.spec.js
@@ -131,6 +131,56 @@ describe('Utils', () => {
expect(version).toEqual('1.0.0');
});
+ test('should return version 3', () => {
+ const csproj = `
+
+
+
+
+ Debug
+ AnyCPU
+ {E7ECDD31-5969-43AF-A7E1-31E04631124C}
+ Library
+ Properties
+ Oxide.Ext.GamingApi
+ Oxide.Ext.GamingApi
+ v4.6.1
+ 512
+
+ 0.0.0
+ 0.0.0
+ 0.0.0.0
+ 0.0.0.0
+ https://github.com/GamingAPI/umod-rust-server-extension.git
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+ false
+ 6
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+ false
+
+
+
+
+
+`;
+ const version = getCurrentVersionCsproj(csproj);
+ expect(version).toEqual('0.0.0');
+ });
test('should return version 2', () => {
const csproj = `