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.