diff --git a/MSBuild.Caching/CacheGet.cs b/MSBuild.Caching/CacheGet.cs new file mode 100644 index 00000000..36f281ed --- /dev/null +++ b/MSBuild.Caching/CacheGet.cs @@ -0,0 +1,18 @@ +using Microsoft.Build.Framework; +using Task = Microsoft.Build.Utilities.Task; + +namespace MSBuild.Caching; + +public class CacheGet : Task +{ + public string? Key { get; set; } + + [Output] + public string? Value { get; set; } + + public override bool Execute() + { + this.Value = (string?)this.BuildEngine4.GetRegisteredTaskObject(this.Key, RegisteredTaskObjectLifetime.Build) ?? ""; + return true; + } +} diff --git a/MSBuild.Caching/CacheSet.cs b/MSBuild.Caching/CacheSet.cs new file mode 100644 index 00000000..ca623e24 --- /dev/null +++ b/MSBuild.Caching/CacheSet.cs @@ -0,0 +1,19 @@ +using Microsoft.Build.Framework; +using Task = Microsoft.Build.Utilities.Task; + +namespace MSBuild.Caching; + +public class CacheSet : Task +{ + public string? Key { get; set; } + + public string? Value { get; set; } + + public override bool Execute() + { + this.BuildEngine4.RegisterTaskObject( + this.Key, this.Value, RegisteredTaskObjectLifetime.Build, allowEarlyCollection: false); + + return true; + } +} diff --git a/MSBuild.Caching/MSBuild.Caching.csproj b/MSBuild.Caching/MSBuild.Caching.csproj new file mode 100644 index 00000000..5b2e954a --- /dev/null +++ b/MSBuild.Caching/MSBuild.Caching.csproj @@ -0,0 +1,13 @@ + + + + false + net472;net6.0 + 12.0 + + + + + + + diff --git a/MinVer.sln b/MinVer.sln index bf1988b1..84b2bd6c 100644 --- a/MinVer.sln +++ b/MinVer.sln @@ -17,6 +17,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MinVerTests.Infra", "MinVer EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MinVerTests.Packages", "MinVerTests.Packages\MinVerTests.Packages.csproj", "{694ECAC7-FD05-4550-A4FB-8F497D29ECB0}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MSBuild.Caching", "MSBuild.Caching\MSBuild.Caching.csproj", "{3A9A6053-076E-47D4-9912-E04BD11C666F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -51,6 +53,10 @@ Global {694ECAC7-FD05-4550-A4FB-8F497D29ECB0}.Debug|Any CPU.Build.0 = Debug|Any CPU {694ECAC7-FD05-4550-A4FB-8F497D29ECB0}.Release|Any CPU.ActiveCfg = Release|Any CPU {694ECAC7-FD05-4550-A4FB-8F497D29ECB0}.Release|Any CPU.Build.0 = Release|Any CPU + {3A9A6053-076E-47D4-9912-E04BD11C666F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3A9A6053-076E-47D4-9912-E04BD11C666F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3A9A6053-076E-47D4-9912-E04BD11C666F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3A9A6053-076E-47D4-9912-E04BD11C666F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/MinVer/MinVer.csproj b/MinVer/MinVer.csproj index 86214515..c89a2925 100644 --- a/MinVer/MinVer.csproj +++ b/MinVer/MinVer.csproj @@ -33,6 +33,7 @@ + @@ -42,6 +43,8 @@ + + diff --git a/MinVer/build/MinVer.targets b/MinVer/build/MinVer.targets index 3a00bd2f..679a7d16 100644 --- a/MinVer/build/MinVer.targets +++ b/MinVer/build/MinVer.targets @@ -4,8 +4,13 @@ $(MSBuildAllProjects);$(MSBuildThisFileFullPath) $(GenerateNuspecDependsOn);MinVer $(GetPackageVersionDependsOn);MinVer + $(MSBuildThisFileDirectory)bin\net6.0\MSBuild.Caching.dll + $(MSBuildThisFileDirectory)bin\net472\MSBuild.Caching.dll + + + low high @@ -35,7 +40,6 @@ - @@ -46,14 +50,19 @@ - + + + - + - + @(MinVerOutputVersion) + + + $(MinVerVersion.Split(`.`)[0]) $(MinVerVersion.Split(`.`)[1]) $(MinVerVersion.Split(`.`)[2].Split(`-`)[0].Split(`+`)[0]) diff --git a/MinVerTests.Packages/MultipleProjects.cs b/MinVerTests.Packages/MultipleProjects.cs index 593c2065..9fa81fae 100644 --- a/MinVerTests.Packages/MultipleProjects.cs +++ b/MinVerTests.Packages/MultipleProjects.cs @@ -52,8 +52,6 @@ public async Task MultipleTagPrefixes() Assert.Collection( versionCalculations, message => Assert.Equal("MinVer: Calculated version 2.3.4.", message), - message => Assert.Equal("MinVer: Calculated version 5.6.7.", message), - message => Assert.Equal("MinVer: Calculated version 2.3.4.", message), message => Assert.Equal("MinVer: Calculated version 5.6.7.", message)); Assert.Collection( diff --git a/targets/Program.cs b/targets/Program.cs index d2a83675..c81b220e 100644 --- a/targets/Program.cs +++ b/targets/Program.cs @@ -34,7 +34,7 @@ { var path = TestDirectory.Get("MinVer.Targets", "eyeball-minver-logs"); - await Sdk.CreateProject(path, "Release"); + await Sdk.CreateSolution(path, ["project0", "project1",], "Release"); await Git.Init(path); await Git.Commit(path); @@ -43,7 +43,7 @@ await RunAsync( "dotnet", - "build --no-restore --nologo", + "build --no-restore --nologo -maxCpuCount:1", path, configureEnvironment: env => {