Skip to content

Commit 7351a3b

Browse files
authored
Support project references by forcing target dependency to ensure it is updated/set BEFORE the target to retrieve it is run. (#81)
This Fixes #79 Though a new test bug should be filed to account for the shortcomings of the tests (See #80)
1 parent 390d793 commit 7351a3b

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/Ubiquity.NET.Versioning.Build.Tasks.UT/BuildTaskTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,36 @@ static FileVersionQuad ExpectedFileVersion( bool isPreRelease, bool isCiBuild )
544544
}
545545
}
546546

547+
[TestMethod]
548+
[DataRow("netstandard2.0")]
549+
[DataRow("net48")]
550+
[DataRow("net8.0")]
551+
public void Projects_with_project_references_create_proper_dependencies_in_nuspec( string targetFramework )
552+
{
553+
// This tests for a fix to https://github.com/UbiquityDotNET/CSemVer.GitBuild/issues/79
554+
// Currently this is a bit of a hack to move things along elsewhere.
555+
// for now, hack this and specifically look for the solution that is at least known to work at this point.
556+
var globalProperties = new Dictionary<string, string>
557+
{
558+
[PropertyNames.BuildMajor] = "1",
559+
[PropertyNames.BuildMinor] = "2",
560+
[PropertyNames.BuildPatch] = "3",
561+
[PropertyNames.PreReleaseName] = "delta",
562+
};
563+
564+
using var collection = new ProjectCollection(globalProperties);
565+
using var fullResults = Context.CreateTestProjectAndInvokeTestedPackage(targetFramework, collection);
566+
var prop = fullResults.BuildResults.Creator.Project.GetProperty("GetPackageVersionDependsOn");
567+
Assert.IsTrue(prop.EvaluatedValue.Contains("PrepareVersioningForBuild", StringComparison.Ordinal));
568+
569+
// A full solution would:
570+
// Create a project (dependentProj)
571+
// - Should generate a NuGetPackage
572+
// Create a project (testProj) that has a project reference for 'dependentProj'
573+
// pack testProj
574+
// look into generated nupkg to ensure dependency for dependentProj has correct version (and NOT the default 1.0.0)
575+
}
576+
547577
private static IEnumerable<PrereleaseTestData> GetPrereleaseTestData()
548578
{
549579
return from tfm in TargetFrameworks

src/Ubiquity.NET.Versioning.Build.Tasks/build/Ubiquity.NET.Versioning.Build.Tasks.targets

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
<_TaskFolder Condition=" '$(MSBuildRuntimeType)' == 'Core' ">tasks\netstandard2.0\</_TaskFolder>
44
<_TaskFolder Condition=" '$(MSBuildRuntimeType)' != 'Core' ">tasks\net48\</_TaskFolder>
55
<_Ubiquity_NET_Versioning_Build_Tasks>$([MSBuild]::NormalizePath($(MSBuildThisFileDirectory)..\$(_TaskFolder)Ubiquity.NET.Versioning.Build.Tasks.dll))</_Ubiquity_NET_Versioning_Build_Tasks>
6+
<!--
7+
Force target dependency for tasks that use this package. If a project contains references to another project then
8+
the NuGet tasks will call a task that uses this in the referenced project. The actual task is currently
9+
`_GetProjectVersion` but that is not formally documented and subject to change. (This property isn't formally
10+
documented either but at least it doesn't have the leading underscore to indicate it is intended as private/internal
11+
and does have some hits on a search) see: https://github.com/UbiquityDotNET/CSemVer.GitBuild/issues/79
12+
-->
13+
<GetPackageVersionDependsOn>$(GetPackageVersionDependsOn);PrepareVersioningForBuild</GetPackageVersionDependsOn>
614
</PropertyGroup>
715

816
<!--
@@ -21,7 +29,7 @@
2129
<UsingTask TaskName="ParseBuildVersionXml" AssemblyFile="$(_Ubiquity_NET_Versioning_Build_Tasks)"/>
2230

2331
<Target Name="PrepareVersioningForBuild"
24-
BeforeTargets="PrepareForBuild;_IntermediatePack"
32+
BeforeTargets="PrepareForBuild"
2533
DependsOnTargets="GetRepositoryInfo;VerifyProvidedBuildVersion;SetVersionDependentProperties;"
2634
/>
2735

0 commit comments

Comments
 (0)