Cake Build installs the full version with the alias DotNetCoreBuild

I use an alias ParseReleaseNotesin Cake to control my versioning, it worked fine with a project where I correct assembly information with an alias CreateAssemblyInfo.

Now that the project does not use csproj, but project.json, I want to achieve the same, and build information is not a real option with project.json.

By checking DotNetCoreBuild(string, ​DotNetCoreBuildSettings)​and DotNetCoreBuildSettings, there is only one way to set parts of a version through a property VersionSuffix.

Is there a Cake alias / parameter to achieve this, or is it possible to fix a .json project from Cake?

+4
source share
2 answers

project.json dotnet build , .

, project.json - "JSON", project.json JSON, .. JSON.Net.

, JSON.Net addin, UpdateProjectJsonVersion, project.json, ReleaseNotes ( ).

#addin "Newtonsoft.Json"

// fake a release note
ReleaseNotes releaseNotes = new ReleaseNotes(
    new Version("3.0.0"),
    new [] {"3rd release"},
    "3.0.-beta"
    );

// project.json to patch
FilePath filePaths = File("./project.json");

// patch project.json
UpdateProjectJsonVersion(releaseNotes.RawVersionLine, filePaths);

// utility function that patches project.json using json.net
public static void UpdateProjectJsonVersion(string version, FilePath projectPath)
{
    var project = Newtonsoft.Json.Linq.JObject.Parse(
        System.IO.File.ReadAllText(projectPath.FullPath, Encoding.UTF8));

    project["version"].Replace(version);

    System.IO.File.WriteAllText(projectPath.FullPath, project.ToString(), Encoding.UTF8);
}

, UpdateProjectJsonVersion, DotNetCoreBuild, , .

+2

Cake Alias ​​ , Addin MagicChunks. script, :

#addin "MagicChunks"

- :

var projectToPackagePackageJson = $"{projectToPackage}/project.json";
Information("Updating {0} version -> {1}", projectToPackagePackageJson, nugetVersion);

TransformConfig(projectToPackagePackageJson, projectToPackagePackageJson, new TransformationCollection {
    { "version", nugetVersion }
});

TransformConfig - , MagicChunks.

. .

+5

Source: https://habr.com/ru/post/1650086/


All Articles