Skip to content

Add Version element to project file updater #2361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System;
using System.IO;
using System.Xml.Linq;
using GitVersion;
using GitVersion.Extensions;
using GitVersion.Logging;
Expand All @@ -12,6 +9,9 @@
using NSubstitute;
using NUnit.Framework;
using Shouldly;
using System;
using System.IO;
using System.Xml.Linq;

namespace GitVersionCore.Tests
{
Expand Down Expand Up @@ -298,6 +298,7 @@ public void UpdateProjectFileAddsVersionToFile(string xml)
<AssemblyVersion>2.3.1.0</AssemblyVersion>
<FileVersion>2.3.1.0</FileVersion>
<InformationalVersion>2.3.1+3.Branch.foo.Sha.hash</InformationalVersion>
<Version>2.3.1</Version>
</PropertyGroup>
</Project>";
var transformedXml = fs.ReadAllText(fileName);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using GitVersion.Logging;
using GitVersion.OutputVariables;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using GitVersion.Logging;
using GitVersion.OutputVariables;

namespace GitVersion.VersionConverters.AssemblyInfo
{
Expand All @@ -17,6 +17,7 @@ public class ProjectFileUpdater : IProjectFileUpdater
internal const string AssemblyVersionElement = "AssemblyVersion";
internal const string FileVersionElement = "FileVersion";
internal const string InformationalVersionElement = "InformationalVersion";
internal const string VersionElement = "Version";

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

foreach (var projectFile in projectFilesToUpdate)
{
Expand All @@ -54,6 +56,8 @@ public void Execute(VersionVariables variables, AssemblyInfoContext context)
continue;
}

log.Debug($"Update file: {localProjectFile}");

var backupProjectFile = localProjectFile + ".bak";
fileSystem.Copy(localProjectFile, backupProjectFile, true);

Expand Down Expand Up @@ -84,6 +88,11 @@ public void Execute(VersionVariables variables, AssemblyInfoContext context)
UpdateProjectVersionElement(fileXml, InformationalVersionElement, assemblyInfoVersion);
}

if (!string.IsNullOrWhiteSpace(packageVersion))
{
UpdateProjectVersionElement(fileXml, VersionElement, packageVersion);
}

var outputXmlString = fileXml.ToString();
if (originalFileContents != outputXmlString)
{
Expand Down