Comments (22)
Hi guys, I took a stab at writing a small Cake plugin to run MinVer and parse the version:
https://github.com/augustoproiete/Cake.MinVer
#addin "nuget:?package=Cake.MinVer&version=0.1.0"
var version = MinVer();
Task("Example")
.Does(context =>
{
context.Information($"Version: {version.Version}");
context.Information($"Major: {version.Major}");
context.Information($"Minor: {version.Minor}");
context.Information($"Patch: {version.Patch}");
context.Information($"PreRelease: {version.PreRelease}");
context.Information($"BuildMetadata: {version.BuildMetadata}");
});
RunTarget("Example");
from minver.
I think the real solution is for Cake to have something akin to SimpleExec built into it.
Why not just use SimpleExec?
from minver.
I ended up with this code in my Cake script:
var directoryBuildPropsFilePath = GetFiles("Directory.Build.props").Single().ToString();
var directoryBuildPropsDocument = System.Xml.Linq.XDocument.Load(directoryBuildPropsFilePath);
var preReleasePhase = directoryBuildPropsDocument.Descendants("MinVerDefaultPreReleasePhase").Single().Value;
string version = null;
StartProcess(
"dotnet",
new ProcessSettings()
.WithArguments(x => x
.Append("minver")
.AppendSwitch("--default-pre-release-phase", preReleasePhase))
.SetRedirectStandardOutput(true)
.SetRedirectedStandardOutputHandler( // Beware, this gets called twice, hence the null check.
output =>
{
if (output != null)
{
version = output;
}
return output;
}));
I'm reading the pre-release phase from a Directory.Build.props
file and plugging that into the dotnet minver
CLI tool. Then you can use the version
any way you like. In my case I'm using the version to tag a Docker image.
from minver.
That looks awesome.
Would be nice if MinVer listed Cake.MinVer on it's ReadMe, for visibility.
from minver.
@damianh Thanks for your support 🤷♂️
Thank me later ;)
from minver.
Thanks for chiming in @RehanSaeed.
BTW, this is quite a bit simpler with SimpleExec:
var version = Read("minver", $"--default-pre-release-phase {preReleasePhase}");
from minver.
I'm not sure I understand the motivation. It seems to be, essentially, a .NET API for using MinVer. Why does it have a dependency on Cake?
BTW, I am considering releasing the underlying MinVer library as a package, so that would also provide a .NET API.
from minver.
BTW this can be acheived today with a single line of code, using the SimpleExec
and semver
packages:
var version = Semver.SemVersion.Parse(SimpleExec.Command.Read("minver").Trim());
from minver.
A problem now is that Cake.Minver is a layer that needs maintenance both against Cake APIs and MinVer, will lag behind MinVer changes (which may be breaking) and may be abandoned (which has happened to other Cake plugins).
@adamralph has no obligations to that plugin so my advice is caveat emptor ("buyer beware")
from minver.
@adamralph Yes, I think so...
var version = MinVer();
Reads much better IMO, and has the added benefit of not having to take a dependency on Semver
and on SimpleExec
.
Also, version
comes with a couple of handy properties such as AssemblyVersion
and FileVersion
ready to use.
Property | Type | Description |
---|---|---|
Version | string |
The original, non-normalized version string |
Major | int |
The major version number |
Minor | int |
The minor version number |
Patch | int |
The patch version number |
PreRelease | string |
The pre-release extension |
BuildMetadata | string |
The build metadata extension |
AssemblyVersion | string |
{Major}.0.0.0 |
FileVersion | string |
{Major}.{Minor}.{Patch}.0 |
InformationalVersion | string |
same as Version above |
PackageVersion | string |
same as Version above |
from minver.
I've been bitten by both cake and NuGet dependencies before. I think the real solution is for Cake to have something akin to SimpleExec built into it. It has some methods which are very close. Until then, the solutions above are good enough. Pick your poison.
from minver.
@ben-foster-cko the version is the only line. Bear in mind that there are two output streams: stdout and stderr. You should only read stdout:
(stderr) MinVer: No commit found with a valid SemVer 2.0 version. Using default version 0.0.0-alpha.0.
(stderr) MinVer: Using { Commit: 798fedc, Tag: null, Version: 0.0.0-alpha.0, Height: 21 }.
(stderr) MinVer: Calculated version 0.0.0-alpha.0.21.
(stdout) 0.0.0-alpha.0.21
from minver.
@RehanSaeed as mentioned above, the full version, and only the full version, is written to stdout. You can read that, and then it is trivial to split it into its constituent parts, should you need to.
from minver.
@augustoproiete how much value does it add over this single line?
var version = Semver.SemVersion.Parse(SimpleExec.Command.Read("minver").Trim());
Is the effort worth it?
from minver.
@ben-foster-cko do you just need the version string? Only the version is printed to stdout, as a plain string. All other messages go to stderr. If you just read stdout then the entire string is the version.
from minver.
@adamralph so just to confirm, the last line will always be the version?
MinVer: No commit found with a valid SemVer 2.0 version. Using default version 0.0.0-alpha.0.
MinVer: Using { Commit: 798fedc, Tag: null, Version: 0.0.0-alpha.0, Height: 21 }.
MinVer: Calculated version 0.0.0-alpha.0.21.
0.0.0-alpha.0.21
from minver.
Also came here looking to use the CLI tool in Cake build.
JSON output would be useful. An option to just output the ful version would be great too.
from minver.
Any link to an example how to use the cli within a cake script? Somehow I don't get this to work :-/
from minver.
@StefanOssendorf I'm not aware of any such example. The CLI is a regular .NET SDK tool. It is invoked with minver
and it prints the version to stdout. You should be able to use any mechanism which is capable of executing a .NET SDK tool and reading its output.
from minver.
That's exactly what I'm was looking for. Thank you very much :-)
from minver.
@adamralph It's the other way around. It's a Cake plugin, specifically built for Cake users who are familiar with how it works and its DSL, that has a dependency on MinVer to calculate the version.
from minver.
@damianh Thanks for your support 🤷♂️
from minver.
Related Issues (20)
- CS7035 - The specified version string does not conform to the recommended format - major.minor.build.revision HOT 7
- Again a case for "autoincrement=none" HOT 2
- Tags are ignore when using tag prefixes in repository with mupltiple projects HOT 3
- Fails on `osx-arm64` HOT 9
- .NET 6 binaries HOT 2
- 4.1.0 release
- Error when git not installed HOT 5
- Produce an MSBuild error when Git is not present in PATH HOT 2
- Remove redundant MSB3073 error when a MinVer MSBuild error is produced HOT 1
- MinVer in WPF projects HOT 6
- 4.2.0 release
- Allow tags with the format v1.0 or v1.1 HOT 4
- 4.3.0 release
- Tags ignored with actions/checkout@v3 HOT 2
- Do not include MinVerBuildMetadata in PackageVersion HOT 5
- Allow for disabling the pre-release additions by a property value HOT 4
- disable MinVerAutoIncrement HOT 5
- 5.0.0 release
- MinVerBuildMetadata included in .Net 8 SDK build but not .Net 6 SDK HOT 5
- Is it time to revisit the MSBuild task idea? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from minver.