Skip to content

Commit de812d8

Browse files
authored
Merge pull request #2361 from akordowski/feature/add-version-element-to-project_file_updater
Add Version element to project file updater
2 parents e8102ab + 9894216 commit de812d8

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/GitVersionCore.Tests/VersionConverters/ProjectFileUpdaterTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
using System;
2-
using System.IO;
3-
using System.Xml.Linq;
41
using GitVersion;
52
using GitVersion.Extensions;
63
using GitVersion.Logging;
@@ -12,6 +9,9 @@
129
using NSubstitute;
1310
using NUnit.Framework;
1411
using Shouldly;
12+
using System;
13+
using System.IO;
14+
using System.Xml.Linq;
1515

1616
namespace GitVersionCore.Tests
1717
{
@@ -298,6 +298,7 @@ public void UpdateProjectFileAddsVersionToFile(string xml)
298298
<AssemblyVersion>2.3.1.0</AssemblyVersion>
299299
<FileVersion>2.3.1.0</FileVersion>
300300
<InformationalVersion>2.3.1+3.Branch.foo.Sha.hash</InformationalVersion>
301+
<Version>2.3.1</Version>
301302
</PropertyGroup>
302303
</Project>";
303304
var transformedXml = fs.ReadAllText(fileName);

src/GitVersionCore/VersionConverters/AssemblyInfo/ProjectFileUpdater.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
using GitVersion.Logging;
2+
using GitVersion.OutputVariables;
13
using System;
24
using System.Collections.Generic;
35
using System.IO;
46
using System.Linq;
57
using System.Xml.Linq;
6-
using GitVersion.Logging;
7-
using GitVersion.OutputVariables;
88

99
namespace GitVersion.VersionConverters.AssemblyInfo
1010
{
@@ -17,6 +17,7 @@ public class ProjectFileUpdater : IProjectFileUpdater
1717
internal const string AssemblyVersionElement = "AssemblyVersion";
1818
internal const string FileVersionElement = "FileVersion";
1919
internal const string InformationalVersionElement = "InformationalVersion";
20+
internal const string VersionElement = "Version";
2021

2122
private readonly List<Action> restoreBackupTasks = new List<Action>();
2223
private readonly List<Action> cleanupBackupTasks = new List<Action>();
@@ -40,6 +41,7 @@ public void Execute(VersionVariables variables, AssemblyInfoContext context)
4041
var assemblyVersion = variables.AssemblySemVer;
4142
var assemblyInfoVersion = variables.InformationalVersion;
4243
var assemblyFileVersion = variables.AssemblySemFileVer;
44+
var packageVersion = variables.NuGetVersionV2;
4345

4446
foreach (var projectFile in projectFilesToUpdate)
4547
{
@@ -54,6 +56,8 @@ public void Execute(VersionVariables variables, AssemblyInfoContext context)
5456
continue;
5557
}
5658

59+
log.Debug($"Update file: {localProjectFile}");
60+
5761
var backupProjectFile = localProjectFile + ".bak";
5862
fileSystem.Copy(localProjectFile, backupProjectFile, true);
5963

@@ -84,6 +88,11 @@ public void Execute(VersionVariables variables, AssemblyInfoContext context)
8488
UpdateProjectVersionElement(fileXml, InformationalVersionElement, assemblyInfoVersion);
8589
}
8690

91+
if (!string.IsNullOrWhiteSpace(packageVersion))
92+
{
93+
UpdateProjectVersionElement(fileXml, VersionElement, packageVersion);
94+
}
95+
8796
var outputXmlString = fileXml.ToString();
8897
if (originalFileContents != outputXmlString)
8998
{

0 commit comments

Comments
 (0)