Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Handle verbose Version in Directory.Build.props #972

Merged
merged 2 commits into from
May 15, 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
Expand Up @@ -54,6 +54,19 @@ public void SinglePackageShouldBePopulated()
PackageAssert.IsPopulated(package);
}

[Test]
public void SinglePackageFromVerboseFormatShouldBePopulated()
{
const string verboseFormatVersion =
@"<Project><ItemGroup><PackageReference Include=""foo""><PrivateAssets>all</PrivateAssets><Version>1.2.3.4</Version></PackageReference></ItemGroup></Project>";

var reader = MakeReader();
var packages = reader.Read(StreamFromString(verboseFormatVersion), TempPath());

var package = packages.FirstOrDefault();
PackageAssert.IsPopulated(package);
}

[Test]
public void SinglePackageShouldBeCorrect()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private PackageInProject XmlToPackage(XElement el, PackagePath path)
{
id = el.Attribute("Update")?.Value;
}
var version = el.Attribute("Version")?.Value;
var version = el.Attribute("Version")?.Value ?? el.Element("Version")?.Value;

return _packageInProjectReader.Read(id, version, path, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ public async Task ShouldUpdateValidFileWithIncludeAttribute()
await ExecuteValidUpdateTest(_testFileWithInclude, "<PackageReference Include=\"foo\" Version=\"{packageVersion}\" />");
}

[Test]
public async Task ShouldUpdateValidFileWithIncludeAndVerboseVersion()
{
await ExecuteValidUpdateTest(
@"<Project><ItemGroup><PackageReference Include=""foo""><Version>{packageVersion}</Version></PackageReference></ItemGroup></Project>",
@"<Version>{packageVersion}</Version>");
}

private async Task ExecuteValidUpdateTest(string testProjectContents, string expectedPackageString, [CallerMemberName] string memberName = "")
{
const string oldPackageVersion = "5.2.31";
Expand Down
10 changes: 9 additions & 1 deletion NuKeeper.Update/Process/UpdateDirectoryBuildTargetsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,15 @@ private void UpdateFile(Stream fileContents, NuGetVersion newVersion,
{
_logger.Detailed(
$"Updating directory-level dependencies: {currentPackage.Id} in path {currentPackage.Path.FullName}");
dependencyToUpdate.Attribute("Version").Value = newVersion.ToString();
var attribute = dependencyToUpdate.Attribute("Version");
if (attribute != null)
{
attribute.Value = newVersion.ToString();
}
else
{
dependencyToUpdate.Element("Version").Value = newVersion.ToString();
}
}

xml.Save(fileContents);
Expand Down
5 changes: 3 additions & 2 deletions NuKeeper/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;

[assembly: InternalsVisibleTo("NuKeeper.Tests")]

Expand All @@ -22,7 +23,7 @@ namespace NuKeeper
[Subcommand(typeof(GlobalCommand))]
public class Program
{
public static int Main(string[] args)
public static async Task<int> Main(string[] args)
{
var container = ContainerRegistration.Init();

Expand All @@ -31,7 +32,7 @@ public static int Main(string[] args)

try
{
return app.Execute(args);
return await app.ExecuteAsync(args);
}
catch (CommandParsingException cpe)
{
Expand Down