5
4

2 回答 2

5

There is no built in Cake Alias to provide this functionality, but you can make use of a 3rd Party Addin for the MagicChunks project. You can add this into your Cake script by simply doing:

#addin "MagicChunks"

And from there, you can do something like:

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

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

Where TransformConfig is the Method Alias that is added by the MagicChunks addin.

NOTE: This sample was taken from the following project.

于 2016-08-04T07:17:14.087 回答
2

There's no built in alias to patch project.json version or parameter for dotnet build to set full version that I know of.

That said as project.json is just "JSON" it's fully possible to patch project.json using a JSON serializer i.e. JSON.Net.

Below I've created an example that references JSON.Net as an addin and then created an UpdateProjectJsonVersion utility function that I can use to patch my project.json using parsed the ReleaseNotes (in this case I've hard coded it for simplicity).

#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);
}

So basically just call UpdateProjectJsonVersion before you call the DotNetCoreBuild alias and it'll result in same version as your release notes.

于 2016-08-03T21:29:36.017 回答