Setting the version number for .NET Core projects -
what options setting project version .net core / asp.net core projects?
found far:
set
version
property inproject.json
. source: dnx overview, working dnx projects. seems setassemblyversion
,assemblyfileversion
,assemblyinformationalversion
unless overridden attribute (see next point).setting
assemblyversion
,assemblyfileversion
,assemblyinformationalversion
attributes seems work , overrideversion
property specified inproject.json
.for example, including
'version':'4.1.1-*'
inproject.json
, setting[assembly:assemblyfileversion("4.3.5.0")]
in.cs
file result inassemblyversion=4.1.1.0
,assemblyinformationalversion=4.1.1.0
,assemblyfileversion=4.3.5.0
is setting version number via attributes, e.g. assemblyfileversion
, still supported?
have missed - there other ways?
context
the scenario i'm looking @ sharing single version number between multiple related projects. of projects using .net core (project.json), others using full .net framework (.csproj). logically part of single system , versioned together.
the strategy used until having sharedassemblyinfo.cs
file @ root of our solution assemblyversion
, assemblyfileversion
attributes. projects include link file.
i'm looking ways achieve same result .net core projects, i.e. have single file modify.
why not change value in project.json file. using cakebuild (optimizations possible)
task("bump").does(() => { var files = getfiles(config.srcdir + "**/project.json"); foreach(var file in files) { information("processing: {0}", file); var path = file.tostring(); var trg = new stringbuilder(); var regexversion = new system.text.regularexpressions.regex("\"version\":(\\s)?\"0.0.0-\\*\","); using (var src = system.io.file.openread(path)) { using (var reader = new streamreader(src)) { while (!reader.endofstream) { var line = reader.readline(); if(line == null) continue; line = regexversion.replace(line, string.format("\"version\": \"{0}\",", config.semver)); trg.appendline(line); } } } system.io.file.writealltext(path, trg.tostring()); } });
then if have e.g. unittest project takes dependency on project, use "*" dependency resolution.
also, bump before doing dotnet restore
. order follows:
task("default") .isdependenton("initoutdir") .isdependenton("bump") .isdependenton("restore") .isdependenton("build") .isdependenton("unittest"); task("ci") .isdependenton("default") .isdependenton("pack");
link full build script: https://github.com/danielwertheim/ensure.that/blob/3a278f05d940d9994f0fde9266c6f2c41900a884/build.cake
the actual values, e.g. version
coming importing separate build.config
file, in build script:
#load "./buildconfig.cake" var config = buildconfig.create(context, buildsystem);
the config file looks (taken https://github.com/danielwertheim/ensure.that/blob/3a278f05d940d9994f0fde9266c6f2c41900a884/buildconfig.cake):
public class buildconfig { private const string version = "5.0.0"; public readonly string srcdir = "./src/"; public readonly string outdir = "./build/"; public string target { get; private set; } public string branch { get; private set; } public string semver { get; private set; } public string buildprofile { get; private set; } public bool isteamcitybuild { get; private set; } public static buildconfig create( icakecontext context, buildsystem buildsystem) { if (context == null) throw new argumentnullexception("context"); var target = context.argument("target", "default"); var branch = context.argument("branch", string.empty); var branchisrelease = branch.tolower() == "release"; var buildrevision = context.argument("buildrevision", "0"); return new buildconfig { target = target, branch = branch, semver = version + (branchisrelease ? string.empty : "-b" + buildrevision), buildprofile = context.argument("configuration", "release"), isteamcitybuild = buildsystem.teamcity.isrunningonteamcity }; } }
Comments
Post a Comment