


The advantage of this solution is that it works not only from builds on build server, but also in manual builds from dotnet build or Visual Studio. Our BeforeBuildActionsProject1 Target that calls task must have unique name per project in case we have more projects in the solution which calls GetCurrentBuildVersion task.It assumes that this dll file is located on parent directory from your. Mentioned UsingTask imports GetCurrentBuildVersion task from DC.Now we setup MSBuild to use this task and set FileVersion and AssemblyVersion properties. This task project is also available in my GitHub holajan/DC.Build.Tasks NET Standard 1.3 class library project type with this class. NET automatic versioning (Build number is days count since and Revision is half seconds since midnight). The logic to get version numbers is same as. It takes BaseVersion property (optional) on input and returns generated version in Version output property. Task class inherit from class from NuGet package. ((int)new TimeSpan(d.Hour, d.Minute, d.Second).TotalSeconds) / 2).ToString() Return new Version(baseVersion.Major, baseVersion.Minor, Private static string GetCurrentBuildVersionString(Version baseVersion) This.Version = GetCurrentBuildVersionString(originalVersion) Var originalVersion = (this.BaseVersion ? "1.0.0") So first, we create our custom MSBuild task GetCurrentBuildVersion: public class GetCurrentBuildVersion : Task In MSBuild process we use our custom MSBuild task to generate version numbers and then we override values of these FileVersion and AssemblyVersion properties with new values from task.

csproj file (not in AssemblyInfo.cs) as property FileVersion (generates AssemblyFileVersionAttribute) and AssemblyVersion (generates AssemblyVersionAttribute). Values for AssemblyVersion and AssemblyFileVersion is in MSBuild project. I came up with a solution that worked almost the same as old AssemblyVersion attribute with star (*) - AssemblyVersion("1.0.*") Package number for NuGet packages msbuild /t:pack /p:Version=YourVersionNumber msbuild /t:build /p:Version=YourVersionNumber /p:AssemblyVersion=YourVersionNumber However if you are using TeamCity, TFS or other CI/CD tool, it's probably better to keep the version number controlled and incremented by them and pass to build as a parameter (as it was suggested in other answers), e.g. Net Core Developers consider Deterministic Builds beneficial described in Īnd Compilers should be deterministic: same inputs generate same outputs #372 Wildcards are only allowed if the build is not deterministic, which The workaround to make AssemblyVersion * working is described in “Confusing error message for wildcard in on.
